added .cinfo, .sinfo, .uinfo, fixed ;sbl to take server names

This commit is contained in:
Master Kwoth 2016-04-14 06:00:40 +02:00
parent bb8fa329d4
commit a7eb06233d
4 changed files with 361 additions and 124 deletions

View File

@ -27,6 +27,7 @@ namespace NadekoBot.Modules.Administration
commands.Add(new CrossServerTextChannel(this)); commands.Add(new CrossServerTextChannel(this));
commands.Add(new SelfAssignedRolesCommand(this)); commands.Add(new SelfAssignedRolesCommand(this));
commands.Add(new Remind(this)); commands.Add(new Remind(this));
commands.Add(new InfoCommands(this));
} }
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Administration;

View File

@ -0,0 +1,95 @@
using Discord;
using Discord.Commands;
using NadekoBot.Commands;
using NadekoBot.Extensions;
using System;
using System.Linq;
using System.Text;
namespace NadekoBot.Modules.Administration.Commands
{
class InfoCommands : DiscordCommand
{
public InfoCommands(DiscordModule module) : base(module)
{
}
internal override void Init(CommandGroupBuilder cgb)
{
cgb.CreateCommand(Module.Prefix + "sinfo")
.Alias(Module.Prefix + "serverinfo")
.Description($"Shows info about the server the bot is on. If no channel is supplied, it defaults to current one.\n**Usage**:{Module.Prefix}sinfo Some Server")
.Parameter("server", ParameterType.Optional)
.Do(async e =>
{
var servText = e.GetArg("server")?.Trim();
var server = string.IsNullOrWhiteSpace(servText)
? e.Server
: NadekoBot.Client.FindServers(servText).FirstOrDefault();
if (server == null)
return;
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(server.Id >> 22);
var sb = new StringBuilder();
sb.AppendLine($"`Name:` **#{server.Name}**");
sb.AppendLine($"`Owner:` **{server.Owner}**");
sb.AppendLine($"`Id:` **{server.Id}**");
sb.AppendLine($"`Icon Url:` **{await server.IconUrl.ShortenUrl()}**");
sb.AppendLine($"`TextChannels:` **{server.TextChannels.Count()}** `VoiceChannels:` **{server.VoiceChannels.Count()}**");
sb.AppendLine($"`Members:` **{server.UserCount}** `Online:` **{server.Users.Count(u => u.Status == UserStatus.Online)}** (may be incorrect)");
sb.AppendLine($"`Roles:` **{server.Roles.Count()}**");
sb.AppendLine($"`Created At:` **{createdAt}**");
if (server.CustomEmojis.Count() > 0)
sb.AppendLine($"`Custom Emojis:` **{string.Join(", ", server.CustomEmojis)}**");
if (server.Features.Count() > 0)
sb.AppendLine($"`Features:` **{string.Join(", ", server.Features)}**");
if (!string.IsNullOrWhiteSpace(server.SplashId))
sb.AppendLine($"`Region:` **{server.Region.Name}**");
await e.Channel.SendMessage(sb.ToString());
});
cgb.CreateCommand(Module.Prefix + "cinfo")
.Alias(Module.Prefix + "channelinfo")
.Description($"Shows info about the channel. If no channel is supplied, it defaults to current one.\n**Usage**:{Module.Prefix}cinfo #some-channel")
.Parameter("channel", ParameterType.Optional)
.Do(async e =>
{
var chText = e.GetArg("channel")?.Trim();
var ch = string.IsNullOrWhiteSpace(chText)
? e.Channel
: e.Server.FindChannels(chText, Discord.ChannelType.Text).FirstOrDefault();
if (ch == null)
return;
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
var sb = new StringBuilder();
sb.AppendLine($"`Name:` **#{ch.Name}**");
sb.AppendLine($"`Id:` **{ch.Id}**");
sb.AppendLine($"`Created At:` **{createdAt}**");
sb.AppendLine($"`Topic:` **{ch.Topic}**");
sb.AppendLine($"`Users:` **{ch.Users.Count()}**");
await e.Channel.SendMessage(sb.ToString());
});
cgb.CreateCommand(Module.Prefix + "uinfo")
.Alias(Module.Prefix + "userinfo")
.Description($"Shows info about the user. If no user is supplied, it defaults a user running the command.\n**Usage**:{Module.Prefix}uinfo @SomeUser")
.Parameter("user", ParameterType.Optional)
.Do(async e =>
{
var userText = e.GetArg("user")?.Trim();
var user = string.IsNullOrWhiteSpace(userText)
? e.User
: e.Server.FindUsers(userText).FirstOrDefault();
if (user == null)
return;
var sb = new StringBuilder();
sb.AppendLine($"`Name#Discrim:` **#{user.Name}#{user.Discriminator}**");
sb.AppendLine($"`Id:` **{user.Id}**");
sb.AppendLine($"`Current Game:` **{(string.IsNullOrWhiteSpace(user.CurrentGame) ? "-" : user.CurrentGame)}**");
sb.AppendLine($"`Joined At:` **{user.JoinedAt}**");
sb.AppendLine($"`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name))}**");
sb.AppendLine($"`AvatarUrl:` **{await user.AvatarUrl.ShortenUrl()}**");
await e.Channel.SendMessage(sb.ToString());
});
}
}
}

View File

@ -1,25 +1,30 @@
using System; using Discord.Commands;
using Discord.Modules; using Discord.Modules;
using Discord.Commands;
using PermsHandler = NadekoBot.Classes.Permissions.PermissionsHandler;
using System.Linq;
using System.Threading.Tasks;
using NadekoBot.Classes.JSONModels; using NadekoBot.Classes.JSONModels;
using NadekoBot.Classes.Permissions; using NadekoBot.Classes.Permissions;
using NadekoBot.Commands; using NadekoBot.Commands;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using System;
using System.Linq;
using System.Threading.Tasks;
using PermsHandler = NadekoBot.Classes.Permissions.PermissionsHandler;
namespace NadekoBot.Modules { namespace NadekoBot.Modules
internal class PermissionModule : DiscordModule { {
internal class PermissionModule : DiscordModule
{
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Permissions; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Permissions;
public PermissionModule() { public PermissionModule()
{
commands.Add(new FilterInvitesCommand(this)); commands.Add(new FilterInvitesCommand(this));
commands.Add(new FilterWords(this)); commands.Add(new FilterWords(this));
} }
public override void Install(ModuleManager manager) { public override void Install(ModuleManager manager)
manager.CreateCommands("", cgb => { {
manager.CreateCommands("", cgb =>
{
cgb.AddCheck(PermissionChecker.Instance); cgb.AddCheck(PermissionChecker.Instance);
@ -29,17 +34,22 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "pr") .Alias(Prefix + "pr")
.Description("Sets a role which can change permissions. Or supply no parameters to find out the current one. Default one is 'Nadeko'.") .Description("Sets a role which can change permissions. Or supply no parameters to find out the current one. Default one is 'Nadeko'.")
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
if (string.IsNullOrWhiteSpace(e.GetArg("role"))) { {
if (string.IsNullOrWhiteSpace(e.GetArg("role")))
{
await e.Channel.SendMessage($"Current permissions role is `{PermsHandler.GetServerPermissionsRoleName(e.Server)}`"); await e.Channel.SendMessage($"Current permissions role is `{PermsHandler.GetServerPermissionsRoleName(e.Server)}`");
return; return;
} }
var arg = e.GetArg("role"); var arg = e.GetArg("role");
Discord.Role role = null; Discord.Role role = null;
try { try
{
role = PermissionHelper.ValidateRole(e.Server, arg); role = PermissionHelper.ValidateRole(e.Server, arg);
} catch (Exception ex) { }
catch (Exception ex)
{
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first."); await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.");
return; return;
@ -52,7 +62,8 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "v") .Alias(Prefix + "v")
.Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true") .Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true")
.Parameter("arg", ParameterType.Required) .Parameter("arg", ParameterType.Required)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("arg"); var arg = e.GetArg("arg");
var val = PermissionHelper.ValidateBool(arg); var val = PermissionHelper.ValidateBool(arg);
PermsHandler.SetVerbosity(e.Server, val); PermsHandler.SetVerbosity(e.Server, val);
@ -62,7 +73,8 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "serverperms") cgb.CreateCommand(Prefix + "serverperms")
.Alias(Prefix + "sp") .Alias(Prefix + "sp")
.Description("Shows banned permissions for this server.") .Description("Shows banned permissions for this server.")
.Do(async e => { .Do(async e =>
{
var perms = PermsHandler.GetServerPermissions(e.Server); var perms = PermsHandler.GetServerPermissions(e.Server);
if (string.IsNullOrWhiteSpace(perms?.ToString())) if (string.IsNullOrWhiteSpace(perms?.ToString()))
await e.Channel.SendMessage("No permissions set for this server."); await e.Channel.SendMessage("No permissions set for this server.");
@ -73,13 +85,17 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "rp") .Alias(Prefix + "rp")
.Description("Shows banned permissions for a certain role. No argument means for everyone.\n**Usage**: ;rp AwesomeRole") .Description("Shows banned permissions for a certain role. No argument means for everyone.\n**Usage**: ;rp AwesomeRole")
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("role"); var arg = e.GetArg("role");
var role = e.Server.EveryoneRole; var role = e.Server.EveryoneRole;
if (!string.IsNullOrWhiteSpace(arg)) if (!string.IsNullOrWhiteSpace(arg))
try { try
{
role = PermissionHelper.ValidateRole(e.Server, arg); role = PermissionHelper.ValidateRole(e.Server, arg);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("💢 Error: " + ex.Message); await e.Channel.SendMessage("💢 Error: " + ex.Message);
return; return;
} }
@ -95,13 +111,17 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "cp") .Alias(Prefix + "cp")
.Description("Shows banned permissions for a certain channel. No argument means for this channel.\n**Usage**: ;cp #dev") .Description("Shows banned permissions for a certain channel. No argument means for this channel.\n**Usage**: ;cp #dev")
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var arg = e.GetArg("channel"); var arg = e.GetArg("channel");
var channel = e.Channel; var channel = e.Channel;
if (!string.IsNullOrWhiteSpace(arg)) if (!string.IsNullOrWhiteSpace(arg))
try { try
{
channel = PermissionHelper.ValidateChannel(e.Server, arg); channel = PermissionHelper.ValidateChannel(e.Server, arg);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("💢 Error: " + ex.Message); await e.Channel.SendMessage("💢 Error: " + ex.Message);
return; return;
} }
@ -116,12 +136,16 @@ namespace NadekoBot.Modules {
.Alias(Prefix + "up") .Alias(Prefix + "up")
.Description("Shows banned permissions for a certain user. No argument means for yourself.\n**Usage**: ;up Kwoth") .Description("Shows banned permissions for a certain user. No argument means for yourself.\n**Usage**: ;up Kwoth")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
{
var user = e.User; var user = e.User;
if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) if (!string.IsNullOrWhiteSpace(e.GetArg("user")))
try { try
{
user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("💢 Error: " + ex.Message); await e.Channel.SendMessage("💢 Error: " + ex.Message);
return; return;
} }
@ -136,16 +160,22 @@ namespace NadekoBot.Modules {
.Parameter("module", ParameterType.Required) .Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Description("Sets a module's permission at the server level.\n**Usage**: ;sm [module_name] enable") .Description("Sets a module's permission at the server level.\n**Usage**: ;sm [module_name] enable")
.Do(async e => { .Do(async e =>
try { {
try
{
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
PermsHandler.SetServerModulePermission(e.Server, module, state); PermsHandler.SetServerModulePermission(e.Server, module, state);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -154,16 +184,22 @@ namespace NadekoBot.Modules {
.Parameter("command", ParameterType.Required) .Parameter("command", ParameterType.Required)
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Description("Sets a command's permission at the server level.\n**Usage**: ;sc [command_name] disable") .Description("Sets a command's permission at the server level.\n**Usage**: ;sc [command_name] disable")
.Do(async e => { .Do(async e =>
try { {
try
{
var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
PermsHandler.SetServerCommandPermission(e.Server, command, state); PermsHandler.SetServerCommandPermission(e.Server, command, state);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -173,25 +209,35 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.Description("Sets a module's permission at the role level.\n**Usage**: ;rm [module_name] enable [role_name]") .Description("Sets a module's permission at the role level.\n**Usage**: ;rm [module_name] enable [role_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
if (e.GetArg("role")?.ToLower() == "all") { if (e.GetArg("role")?.ToLower() == "all")
foreach (var role in e.Server.Roles) { {
foreach (var role in e.Server.Roles)
{
PermsHandler.SetRoleModulePermission(role, module, state); PermsHandler.SetRoleModulePermission(role, module, state);
} }
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
} else { }
else
{
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
PermsHandler.SetRoleModulePermission(role, module, state); PermsHandler.SetRoleModulePermission(role, module, state);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
} }
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -201,25 +247,35 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.Description("Sets a command's permission at the role level.\n**Usage**: ;rc [command_name] disable [role_name]") .Description("Sets a command's permission at the role level.\n**Usage**: ;rc [command_name] disable [role_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
if (e.GetArg("role")?.ToLower() == "all") { if (e.GetArg("role")?.ToLower() == "all")
foreach (var role in e.Server.Roles) { {
foreach (var role in e.Server.Roles)
{
PermsHandler.SetRoleCommandPermission(role, command, state); PermsHandler.SetRoleCommandPermission(role, command, state);
} }
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.");
} else { }
else
{
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
PermsHandler.SetRoleCommandPermission(role, command, state); PermsHandler.SetRoleCommandPermission(role, command, state);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
} }
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -229,25 +285,35 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Description("Sets a module's permission at the channel level.\n**Usage**: ;cm [module_name] enable [channel_name]") .Description("Sets a module's permission at the channel level.\n**Usage**: ;cm [module_name] enable [channel_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
if (e.GetArg("channel")?.ToLower() == "all") { if (e.GetArg("channel")?.ToLower() == "all")
foreach (var channel in e.Server.TextChannels) { {
foreach (var channel in e.Server.TextChannels)
{
PermsHandler.SetChannelModulePermission(channel, module, state); PermsHandler.SetChannelModulePermission(channel, module, state);
} }
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
} else { }
else
{
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
PermsHandler.SetChannelModulePermission(channel, module, state); PermsHandler.SetChannelModulePermission(channel, module, state);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
} }
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -257,25 +323,35 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Description("Sets a command's permission at the channel level.\n**Usage**: ;cc [command_name] enable [channel_name]") .Description("Sets a command's permission at the channel level.\n**Usage**: ;cc [command_name] enable [channel_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
if (e.GetArg("channel")?.ToLower() == "all") { if (e.GetArg("channel")?.ToLower() == "all")
foreach (var channel in e.Server.TextChannels) { {
foreach (var channel in e.Server.TextChannels)
{
PermsHandler.SetChannelCommandPermission(channel, command, state); PermsHandler.SetChannelCommandPermission(channel, command, state);
} }
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.");
} else { }
else
{
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
PermsHandler.SetChannelCommandPermission(channel, command, state); PermsHandler.SetChannelCommandPermission(channel, command, state);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
} }
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -285,17 +361,23 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Description("Sets a module's permission at the user level.\n**Usage**: ;um [module_name] enable [user_name]") .Description("Sets a module's permission at the user level.\n**Usage**: ;um [module_name] enable [user_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
PermsHandler.SetUserModulePermission(user, module, state); PermsHandler.SetUserModulePermission(user, module, state);
await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**."); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -305,17 +387,23 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.Description("Sets a command's permission at the user level.\n**Usage**: ;uc [command_name] enable [user_name]") .Description("Sets a command's permission at the user level.\n**Usage**: ;uc [command_name] enable [user_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var command = PermissionHelper.ValidateCommand(e.GetArg("command"));
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user"));
PermsHandler.SetUserCommandPermission(user, command, state); PermsHandler.SetUserCommandPermission(user, command, state);
await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**."); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -323,17 +411,24 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "asm").Alias(Prefix + "allservermodules") cgb.CreateCommand(Prefix + "asm").Alias(Prefix + "allservermodules")
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Description("Sets permissions for all modules at the server level.\n**Usage**: ;asm [enable/disable]") .Description("Sets permissions for all modules at the server level.\n**Usage**: ;asm [enable/disable]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules) { foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermsHandler.SetServerModulePermission(e.Server, module.Name, state); PermsHandler.SetServerModulePermission(e.Server, module.Name, state);
} }
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server."); await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -342,18 +437,25 @@ namespace NadekoBot.Modules {
.Parameter("module", ParameterType.Required) .Parameter("module", ParameterType.Required)
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Description("Sets permissions for all commands from a certain module at the server level.\n**Usage**: ;asc [module_name] [enable/disable]") .Description("Sets permissions for all commands from a certain module at the server level.\n**Usage**: ;asc [module_name] [enable/disable]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermsHandler.SetServerCommandPermission(e.Server, command.Text, state); PermsHandler.SetServerCommandPermission(e.Server, command.Text, state);
} }
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server."); await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -362,18 +464,25 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Description("Sets permissions for all modules at the channel level.\n**Usage**: ;acm [enable/disable] [channel_name]") .Description("Sets permissions for all modules at the channel level.\n**Usage**: ;acm [enable/disable] [channel_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules) { foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermsHandler.SetChannelModulePermission(channel, module.Name, state); PermsHandler.SetChannelModulePermission(channel, module.Name, state);
} }
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -383,18 +492,25 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Description("Sets permissions for all commands from a certain module at the channel level.\n**Usage**: ;acc [module_name] [enable/disable] [channel_name]") .Description("Sets permissions for all commands from a certain module at the channel level.\n**Usage**: ;acc [module_name] [enable/disable] [channel_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel"));
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermsHandler.SetChannelCommandPermission(channel, command.Text, state); PermsHandler.SetChannelCommandPermission(channel, command.Text, state);
} }
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel."); await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -403,18 +519,25 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("role", ParameterType.Unparsed) .Parameter("role", ParameterType.Unparsed)
.Description("Sets permissions for all modules at the role level.\n**Usage**: ;arm [enable/disable] [role_name]") .Description("Sets permissions for all modules at the role level.\n**Usage**: ;arm [enable/disable] [role_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role"));
foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules) { foreach (var module in NadekoBot.Client.GetService<ModuleService>().Modules)
{
PermsHandler.SetRoleModulePermission(role, module.Name, state); PermsHandler.SetRoleModulePermission(role, module.Name, state);
} }
await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -424,18 +547,25 @@ namespace NadekoBot.Modules {
.Parameter("bool", ParameterType.Required) .Parameter("bool", ParameterType.Required)
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Description("Sets permissions for all commands from a certain module at the role level.\n**Usage**: ;arc [module_name] [enable/disable] [role_name]") .Description("Sets permissions for all commands from a certain module at the role level.\n**Usage**: ;arc [module_name] [enable/disable] [role_name]")
.Do(async e => { .Do(async e =>
try { {
try
{
var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var state = PermissionHelper.ValidateBool(e.GetArg("bool"));
var module = PermissionHelper.ValidateModule(e.GetArg("module")); var module = PermissionHelper.ValidateModule(e.GetArg("module"));
var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel"));
foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module)) { foreach (var command in NadekoBot.Client.GetService<CommandService>().AllCommands.Where(c => c.Category == module))
{
PermsHandler.SetRoleCommandPermission(role, command.Text, state); PermsHandler.SetRoleCommandPermission(role, command.Text, state);
} }
await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role."); await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.");
} catch (ArgumentException exArg) { }
catch (ArgumentException exArg)
{
await e.Channel.SendMessage(exArg.Message); await e.Channel.SendMessage(exArg.Message);
} catch (Exception ex) { }
catch (Exception ex)
{
await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message); await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message);
} }
}); });
@ -444,8 +574,10 @@ namespace NadekoBot.Modules {
.Description("Blacklists a mentioned user.\n**Usage**: ;ubl [user_mention]") .Description("Blacklists a mentioned user.\n**Usage**: ;ubl [user_mention]")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
if (!e.Message.MentionedUsers.Any()) return; if (!e.Message.MentionedUsers.Any()) return;
var usr = e.Message.MentionedUsers.First(); var usr = e.Message.MentionedUsers.First();
NadekoBot.Config.UserBlacklist.Add(usr.Id); NadekoBot.Config.UserBlacklist.Add(usr.Id);
@ -458,15 +590,20 @@ namespace NadekoBot.Modules {
.Description($"Unblacklists a mentioned user.\n**Usage**: {Prefix}uubl [user_mention]") .Description($"Unblacklists a mentioned user.\n**Usage**: {Prefix}uubl [user_mention]")
.Parameter("user", ParameterType.Unparsed) .Parameter("user", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
if (!e.Message.MentionedUsers.Any()) return; if (!e.Message.MentionedUsers.Any()) return;
var usr = e.Message.MentionedUsers.First(); var usr = e.Message.MentionedUsers.First();
if (NadekoBot.Config.UserBlacklist.Contains(usr.Id)) { if (NadekoBot.Config.UserBlacklist.Contains(usr.Id))
{
NadekoBot.Config.UserBlacklist.Remove(usr.Id); NadekoBot.Config.UserBlacklist.Remove(usr.Id);
ConfigHandler.SaveConfig(); ConfigHandler.SaveConfig();
await e.Channel.SendMessage($"`Sucessfully unblacklisted user {usr.Name}`"); await e.Channel.SendMessage($"`Sucessfully unblacklisted user {usr.Name}`");
} else { }
else
{
await e.Channel.SendMessage($"`{usr.Name} was not in blacklist`"); await e.Channel.SendMessage($"`{usr.Name} was not in blacklist`");
} }
}); });
@ -475,8 +612,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "cbl") cgb.CreateCommand(Prefix + "cbl")
.Description("Blacklists a mentioned channel (#general for example).\n**Usage**: ;ubl [channel_mention]") .Description("Blacklists a mentioned channel (#general for example).\n**Usage**: ;ubl [channel_mention]")
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
if (!e.Message.MentionedChannels.Any()) return; if (!e.Message.MentionedChannels.Any()) return;
var ch = e.Message.MentionedChannels.First(); var ch = e.Message.MentionedChannels.First();
NadekoBot.Config.UserBlacklist.Add(ch.Id); NadekoBot.Config.UserBlacklist.Add(ch.Id);
@ -488,8 +627,10 @@ namespace NadekoBot.Modules {
cgb.CreateCommand(Prefix + "cubl") cgb.CreateCommand(Prefix + "cubl")
.Description("Unblacklists a mentioned channel (#general for example).\n**Usage**: ;cubl [channel_mention]") .Description("Unblacklists a mentioned channel (#general for example).\n**Usage**: ;cubl [channel_mention]")
.Parameter("channel", ParameterType.Unparsed) .Parameter("channel", ParameterType.Unparsed)
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
if (!e.Message.MentionedChannels.Any()) return; if (!e.Message.MentionedChannels.Any()) return;
var ch = e.Message.MentionedChannels.First(); var ch = e.Message.MentionedChannels.First();
NadekoBot.Config.UserBlacklist.Remove(ch.Id); NadekoBot.Config.UserBlacklist.Remove(ch.Id);
@ -502,31 +643,30 @@ namespace NadekoBot.Modules {
.Description("Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**\n**Usage**: ;usl [servername/serverid]") .Description("Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**\n**Usage**: ;usl [servername/serverid]")
.Parameter("server", ParameterType.Unparsed) .Parameter("server", ParameterType.Unparsed)
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
.Do(async e => { .Do(async e =>
await Task.Run(async () => { {
await Task.Run(async () =>
{
var arg = e.GetArg("server")?.Trim(); var arg = e.GetArg("server")?.Trim();
if (string.IsNullOrWhiteSpace(arg)) if (string.IsNullOrWhiteSpace(arg))
return; return;
ulong serverId;
if (!ulong.TryParse(arg, out serverId)) {
await e.Channel.SendMessage("Not a valid Id");
return;
}
var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ??
NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault();
if (server == null)
{
await e.Channel.SendMessage("Cannot find that server");
return;
}
var serverId = server.Id;
NadekoBot.Config.ServerBlacklist.Add(serverId); NadekoBot.Config.ServerBlacklist.Add(serverId);
ConfigHandler.SaveConfig(); ConfigHandler.SaveConfig();
//cleanup trivias and typeracing //cleanup trivias and typeracing
Classes.Trivia.TriviaGame trivia; Classes.Trivia.TriviaGame trivia;
Commands.Trivia.RunningTrivias.TryRemove(serverId, out trivia); Trivia.RunningTrivias.TryRemove(serverId, out trivia);
Commands.TypingGame typeracer; TypingGame typeracer;
Commands.SpeedTyping.RunningContests.TryRemove(serverId, out typeracer); SpeedTyping.RunningContests.TryRemove(serverId, out typeracer);
if (server == null) {
await e.Channel.SendMessage("Cannot find that server");
} else {
await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`"); await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`");
}
}); });
}); });
}); });

View File

@ -163,6 +163,7 @@
<Compile Include="Commands\BetrayGame.cs" /> <Compile Include="Commands\BetrayGame.cs" />
<Compile Include="Commands\PlantPick.cs" /> <Compile Include="Commands\PlantPick.cs" />
<Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" /> <Compile Include="Modules\Administration\Commands\CrossServerTextChannel.cs" />
<Compile Include="Modules\Administration\Commands\InfoCommands.cs" />
<Compile Include="Modules\Administration\Commands\Remind.cs" /> <Compile Include="Modules\Administration\Commands\Remind.cs" />
<Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" /> <Compile Include="Modules\Administration\Commands\SelfAssignedRolesCommand.cs" />
<Compile Include="Modules\ClashOfClans.cs" /> <Compile Include="Modules\ClashOfClans.cs" />