public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand(Prefix + "permrole") .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'. | `{Prefix}pr role`") .Parameter("role", ParameterType.Unparsed) .Do(async e => { if (string.IsNullOrWhiteSpace(e.GetArg("role"))) { await e.Channel.SendMessage($"Current permissions role is `{PermissionsHandler.GetServerPermissionsRoleName(e.Server)}`").ConfigureAwait(false); return; } var arg = e.GetArg("role"); Discord.Role role = null; try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { Console.WriteLine(ex.Message); await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.").ConfigureAwait(false); return; } await PermissionsHandler.SetPermissionsRole(e.Server, role.Name).ConfigureAwait(false); await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "rolepermscopy") .Alias(Prefix + "rpc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another. |`{Prefix}rpc Some Role ~ Some other role`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.").ConfigureAwait(false); return; } try { var fromRole = PermissionHelper.ValidateRole(e.Server, args[0]); var toRole = PermissionHelper.ValidateRole(e.Server, args[1]); await PermissionsHandler.CopyRolePermissions(fromRole, toRole).ConfigureAwait(false); await e.Channel.SendMessage($"Copied permission settings from **{fromRole.Name}** to **{toRole.Name}**.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}").ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlpermscopy") .Alias(Prefix + "cpc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one channel to another. |`{Prefix}cpc Some Channel ~ Some other channel`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument."); return; } try { var fromChannel = PermissionHelper.ValidateChannel(e.Server, args[0]); var toChannel = PermissionHelper.ValidateChannel(e.Server, args[1]); await PermissionsHandler.CopyChannelPermissions(fromChannel, toChannel).ConfigureAwait(false); await e.Channel.SendMessage($"Copied permission settings from **{fromChannel.Name}** to **{toChannel.Name}**.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "usrpermscopy") .Alias(Prefix + "upc") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another. |`{Prefix}upc @SomeUser ~ @SomeOtherUser`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument.").ConfigureAwait(false); return; } try { var fromUser = PermissionHelper.ValidateUser(e.Server, args[0]); var toUser = PermissionHelper.ValidateUser(e.Server, args[1]); await PermissionsHandler.CopyUserPermissions(fromUser, toUser).ConfigureAwait(false); await e.Channel.SendMessage($"Copied permission settings from **{fromUser.ToString()}**to * *{toUser.ToString()}**.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "verbose") .Alias(Prefix + "v") .Description($"Sets whether to show when a command/module is blocked. | `{Prefix}verbose true`") .Parameter("arg", ParameterType.Required) .Do(async e => { var arg = e.GetArg("arg"); var val = PermissionHelper.ValidateBool(arg); await PermissionsHandler.SetVerbosity(e.Server, val).ConfigureAwait(false); await e.Channel.SendMessage($"Verbosity set to {val}.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "srvrperms") .Alias(Prefix + "sp") .Description($"Shows banned permissions for this server. | `{Prefix}sp`") .Do(async e => { var perms = PermissionsHandler.GetServerPermissions(e.Server); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage("No permissions set for this server.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "roleperms") .Alias(Prefix + "rp") .Description($"Shows banned permissions for a certain role. No argument means for everyone. | `{Prefix}rp AwesomeRole`") .Parameter("role", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("role"); var role = e.Server.EveryoneRole; if (!string.IsNullOrWhiteSpace(arg)) { try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetRolePermissionsById(e.Server, role.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for **{role.Name}** role.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "chnlperms") .Alias(Prefix + "cp") .Description($"Shows banned permissions for a certain channel. No argument means for this channel. | `{Prefix}cp #dev`") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("channel"); var channel = e.Channel; if (!string.IsNullOrWhiteSpace(arg)) { try { channel = PermissionHelper.ValidateChannel(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetChannelPermissionsById(e.Server, channel.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for **{channel.Name}** channel.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "userperms") .Alias(Prefix + "up") .Description($"Shows banned permissions for a certain user. No argument means for yourself. | `{Prefix}up Kwoth`") .Parameter("user", ParameterType.Unparsed) .Do(async e => { var user = e.User; if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) { try { user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetUserPermissionsById(e.Server, user.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for user **{user.Name}**.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "srvrmdl") .Alias(Prefix + "sm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Sets a module's permission at the server level. | `{Prefix}sm \"module name\" enable`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); await PermissionsHandler.SetServerModulePermission(e.Server, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "srvrcmd").Alias(Prefix + "sc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Sets a command's permission at the server level. | `{Prefix}sc \"command name\" disable`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); await PermissionsHandler.SetServerCommandPermission(e.Server, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rolemdl").Alias(Prefix + "rm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Sets a module's permission at the role level. | `{Prefix}rm \"module name\" enable MyRole`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rolecmd").Alias(Prefix + "rc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Sets a command's permission at the role level. | `{Prefix}rc \"command name\" disable MyRole`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlmdl").Alias(Prefix + "cm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Sets a module's permission at the channel level. | `{Prefix}cm \"module name\" enable SomeChannel`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var channelArg = e.GetArg("channel"); if (channelArg?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false); } else if (string.IsNullOrWhiteSpace(channelArg)) { await PermissionsHandler.SetChannelModulePermission(e.Channel, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{e.Channel.Name}** channel.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, channelArg); await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlcmd").Alias(Prefix + "cc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Sets a command's permission at the channel level. | `{Prefix}cc \"command name\" enable SomeChannel`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("channel")?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "usrmdl").Alias(Prefix + "um") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description($"Sets a module's permission at the user level. | `{Prefix}um \"module name\" enable SomeUsername`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); await PermissionsHandler.SetUserModulePermission(user, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "usrcmd").Alias(Prefix + "uc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description($"Sets a command's permission at the user level. | `{Prefix}uc \"command name\" enable SomeUsername`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); await PermissionsHandler.SetUserCommandPermission(user, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allsrvrmdls").Alias(Prefix + "asm") .Parameter("bool", ParameterType.Required) .Description($"Sets permissions for all modules at the server level. | `{Prefix}asm [enable/disable]`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); foreach (var module in NadekoBot.Client.GetService <ModuleService>().Modules) { await PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allsrvrcmds").Alias(Prefix + "asc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Sets permissions for all commands from a certain module at the server level. | `{Prefix}asc \"module name\" [enable/disable]`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); foreach (var command in NadekoBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allchnlmdls").Alias(Prefix + "acm") .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Sets permissions for all modules at the channel level. | `{Prefix}acm [enable/disable] SomeChannel`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var chArg = e.GetArg("channel"); var channel = string.IsNullOrWhiteSpace(chArg) ? e.Channel : PermissionHelper.ValidateChannel(e.Server, chArg); foreach (var module in NadekoBot.Client.GetService <ModuleService>().Modules) { await PermissionsHandler.SetChannelModulePermission(channel, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allchnlcmds").Alias(Prefix + "acc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Sets permissions for all commands from a certain module at the channel level. | `{Prefix}acc \"module name\" [enable/disable] SomeChannel`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); foreach (var command in NadekoBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allrolemdls").Alias(Prefix + "arm") .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Sets permissions for all modules at the role level. | `{Prefix}arm [enable/disable] MyRole`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); foreach (var module in NadekoBot.Client.GetService <ModuleService>().Modules) { await PermissionsHandler.SetRoleModulePermission(role, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allrolecmds").Alias(Prefix + "arc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Sets permissions for all commands from a certain module at the role level. | `{Prefix}arc \"module name\" [enable/disable] MyRole`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { foreach (var command in NadekoBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false); } } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **all roles** role.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); foreach (var command in NadekoBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "ubl") .Description($"Blacklists a mentioned user. **Bot Owner Only!**| `{Prefix}ubl [user_mention]`") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); NadekoBot.Config.UserBlacklist.Add(usr.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Sucessfully blacklisted user {usr.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "uubl") .Description($"Unblacklists a mentioned user. **Bot Owner Only!** | `{Prefix}uubl [user_mention]`") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); if (NadekoBot.Config.UserBlacklist.Contains(usr.Id)) { NadekoBot.Config.UserBlacklist.Remove(usr.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Sucessfully unblacklisted user {usr.Name}`").ConfigureAwait(false); } else { await e.Channel.SendMessage($"`{usr.Name} was not in blacklist`").ConfigureAwait(false); } }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cbl") .Description($"Blacklists a mentioned channel (#general for example). | `{Prefix}cbl #some_channel`") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); NadekoBot.Config.ChannelBlacklist.Add(ch.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Sucessfully blacklisted channel {ch.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cubl") .Description($"Unblacklists a mentioned channel (#general for example). | `{Prefix}cubl #some_channel`") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); if (NadekoBot.Config.ChannelBlacklist.Contains(ch.Id)) { NadekoBot.Config.ChannelBlacklist.Remove(ch.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Sucessfully unblacklisted channel {ch.Name}`").ConfigureAwait(false); } else { await e.Channel.SendMessage($"`{ch.Name} was not in blacklist`").ConfigureAwait(false); } }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "sbl") .Description($"Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY** | `{Prefix}sbl [servername/serverid]`") .Parameter("server", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { var arg = e.GetArg("server")?.Trim(); if (string.IsNullOrWhiteSpace(arg)) { return; } var server = NadekoBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? NadekoBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (server == null) { await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); return; } var serverId = server.Id; NadekoBot.Config.ServerBlacklist.Add(serverId); await ConfigHandler.SaveConfig().ConfigureAwait(false); //cleanup trivias and typeracing await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cmdcooldown") .Alias(Prefix + "cmdcd") .Description($"Sets a cooldown per user for a command. Set 0 to clear. **Needs Manager Messages Permissions**| `{Prefix}cmdcd \"some cmd\" 5`") .Parameter("command", ParameterType.Required) .Parameter("secs", ParameterType.Required) .AddCheck(SimpleCheckers.ManageMessages()) .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var secsStr = e.GetArg("secs").Trim(); int secs; if (!int.TryParse(secsStr, out secs) || secs < 0 || secs > 3600) { throw new ArgumentOutOfRangeException("secs", "Invalid second parameter. (Must be a number between 0 and 3600)"); } await PermissionsHandler.SetCommandCooldown(e.Server, command, secs).ConfigureAwait(false); if (secs == 0) { await e.Channel.SendMessage($"Command **{command}** has no coooldown now.").ConfigureAwait(false); } else { await e.Channel.SendMessage($"Command **{command}** now has a **{secs} {(secs==1 ? "second" : "seconds")}** cooldown.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allcmdcooldowns") .Alias(Prefix + "acmdcds") .Description($"Shows a list of all commands and their respective cooldowns. | `{Prefix}acmdcds`") .Do(async e => { ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(e.Server.Id, out perms); if (perms == null) { return; } if (!perms.CommandCooldowns.Any()) { await e.Channel.SendMessage("`No command cooldowns set.`").ConfigureAwait(false); return; } await e.Channel.SendMessage(SearchHelper.ShowInPrettyCode(perms.CommandCooldowns.Select(c => c.Key + ": " + c.Value + " secs"), s => $"{s,-30}", 2)).ConfigureAwait(false); }); }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand(Prefix + "permrole") .Alias(Prefix + "pr") .Description("Sets a role which can change permissions. Or supply no parameters to find out the current one. Default one is 'Wiz Bot'.") .Parameter("role", ParameterType.Unparsed) .Do(async e => { if (string.IsNullOrWhiteSpace(e.GetArg("role"))) { await e.Channel.SendMessage($"Current permissions role is `{PermissionsHandler.GetServerPermissionsRoleName(e.Server)}`").ConfigureAwait(false); return; } var arg = e.GetArg("role"); Discord.Role role = null; try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { Console.WriteLine(ex.Message); await e.Channel.SendMessage($"Role `{arg}` probably doesn't exist. Create the role with that name first.").ConfigureAwait(false); return; } PermissionsHandler.SetPermissionsRole(e.Server, role.Name); await e.Channel.SendMessage($"Role `{role.Name}` is now required in order to change permissions.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "rpc") .Alias(Prefix + "rolepermissionscopy") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another.\n**Usage**:`{Prefix}rpc Some Role ~ Some other role`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument."); return; } try { var fromRole = PermissionHelper.ValidateRole(e.Server, args[0]); var toRole = PermissionHelper.ValidateRole(e.Server, args[1]); PermissionsHandler.CopyRolePermissions(fromRole, toRole); await e.Channel.SendMessage($"Copied permission settings from **{fromRole.Name}** to **{toRole.Name}**."); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "cpc") .Alias(Prefix + "channelpermissionscopy") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one channel to another.\n**Usage**:`{Prefix}cpc Some Channel ~ Some other channel`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument."); return; } try { var fromChannel = PermissionHelper.ValidateChannel(e.Server, args[0]); var toChannel = PermissionHelper.ValidateChannel(e.Server, args[1]); PermissionsHandler.CopyChannelPermissions(fromChannel, toChannel); await e.Channel.SendMessage($"Copied permission settings from **{fromChannel.Name}** to **{toChannel.Name}**."); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "upc") .Alias(Prefix + "userpermissionscopy") .Description($"Copies BOT PERMISSIONS (not discord permissions) from one role to another.\n**Usage**:`{Prefix}upc @SomeUser ~ @SomeOtherUser`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Invalid number of '~'s in the argument."); return; } try { var fromUser = PermissionHelper.ValidateUser(e.Server, args[0]); var toUser = PermissionHelper.ValidateUser(e.Server, args[1]); PermissionsHandler.CopyUserPermissions(fromUser, toUser); await e.Channel.SendMessage($"Copied permission settings from **{fromUser.ToString()}**to * *{toUser.ToString()}**."); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "verbose") .Alias(Prefix + "v") .Description("Sets whether to show when a command/module is blocked.\n**Usage**: ;verbose true") .Parameter("arg", ParameterType.Required) .Do(async e => { var arg = e.GetArg("arg"); var val = PermissionHelper.ValidateBool(arg); PermissionsHandler.SetVerbosity(e.Server, val); await e.Channel.SendMessage($"Verbosity set to {val}.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "serverperms") .Alias(Prefix + "sp") .Description("Shows banned permissions for this server.") .Do(async e => { var perms = PermissionsHandler.GetServerPermissions(e.Server); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage("No permissions set for this server.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "roleperms") .Alias(Prefix + "rp") .Description("Shows banned permissions for a certain role. No argument means for everyone.\n**Usage**: ;rp AwesomeRole") .Parameter("role", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("role"); var role = e.Server.EveryoneRole; if (!string.IsNullOrWhiteSpace(arg)) { try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetRolePermissionsById(e.Server, role.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for **{role.Name}** role.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "channelperms") .Alias(Prefix + "cp") .Description("Shows banned permissions for a certain channel. No argument means for this channel.\n**Usage**: ;cp #dev") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("channel"); var channel = e.Channel; if (!string.IsNullOrWhiteSpace(arg)) { try { channel = PermissionHelper.ValidateChannel(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetChannelPermissionsById(e.Server, channel.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for **{channel.Name}** channel.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "userperms") .Alias(Prefix + "up") .Description("Shows banned permissions for a certain user. No argument means for yourself.\n**Usage**: ;up Wizkiller96") .Parameter("user", ParameterType.Unparsed) .Do(async e => { var user = e.User; if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) { try { user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); } catch (Exception ex) { await e.Channel.SendMessage("💢 Error: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetUserPermissionsById(e.Server, user.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"No permissions set for user **{user.Name}**.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "sm").Alias(Prefix + "servermodule") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description("Sets a module's permission at the server level.\n**Usage**: ;sm [module_name] enable") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); PermissionsHandler.SetServerModulePermission(e.Server, module, state); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "sc").Alias(Prefix + "servercommand") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description("Sets a command's permission at the server level.\n**Usage**: ;sc [command_name] disable") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); PermissionsHandler.SetServerCommandPermission(e.Server, command, state); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rm").Alias(Prefix + "rolemodule") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description("Sets a module's permission at the role level.\n**Usage**: ;rm [module_name] enable [role_name]") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { PermissionsHandler.SetRoleModulePermission(role, module, state); } await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); PermissionsHandler.SetRoleModulePermission(role, module, state); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rc").Alias(Prefix + "rolecommand") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description("Sets a command's permission at the role level.\n**Usage**: ;rc [command_name] disable [role_name]") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { PermissionsHandler.SetRoleCommandPermission(role, command, state); } await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **ALL** roles.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); PermissionsHandler.SetRoleCommandPermission(role, command, state); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "cm").Alias(Prefix + "channelmodule") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description("Sets a module's permission at the channel level.\n**Usage**: ;cm [module_name] enable [channel_name]") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var channelArg = e.GetArg("channel"); if (channelArg?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { PermissionsHandler.SetChannelModulePermission(channel, module, state); } await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false); } else if (string.IsNullOrWhiteSpace(channelArg)) { PermissionsHandler.SetChannelModulePermission(e.Channel, module, state); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{e.Channel.Name}** channel.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, channelArg); PermissionsHandler.SetChannelModulePermission(channel, module, state); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "cc").Alias(Prefix + "channelcommand") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description("Sets a command's permission at the channel level.\n**Usage**: ;cc [command_name] enable [channel_name]") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("channel")?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { PermissionsHandler.SetChannelCommandPermission(channel, command, state); } await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** on **ALL** channels.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); PermissionsHandler.SetChannelCommandPermission(channel, command, state); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "um").Alias(Prefix + "usermodule") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description("Sets a module's permission at the user level.\n**Usage**: ;um [module_name] enable [user_name]") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); PermissionsHandler.SetUserModulePermission(user, module, state); await e.Channel.SendMessage($"Module **{module}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "uc").Alias(Prefix + "usercommand") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description("Sets a command's permission at the user level.\n**Usage**: ;uc [command_name] enable [user_name]") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); PermissionsHandler.SetUserCommandPermission(user, command, state); await e.Channel.SendMessage($"Command **{command}** has been **{(state ? "enabled" : "disabled")}** for user **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "asm").Alias(Prefix + "allservermodules") .Parameter("bool", ParameterType.Required) .Description("Sets permissions for all modules at the server level.\n**Usage**: ;asm [enable/disable]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); foreach (var module in WizBot.Client.GetService <ModuleService>().Modules) { PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "asc").Alias(Prefix + "allservercommands") .Parameter("module", 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]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); foreach (var command in WizBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** on this server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "acm").Alias(Prefix + "allchannelmodules") .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description("Sets permissions for all modules at the channel level.\n**Usage**: ;acm [enable/disable] [channel_name]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var chArg = e.GetArg("channel"); var channel = string.IsNullOrWhiteSpace(chArg) ? e.Channel :PermissionHelper.ValidateChannel(e.Server, chArg); foreach (var module in WizBot.Client.GetService <ModuleService>().Modules) { PermissionsHandler.SetChannelModulePermission(channel, module.Name, state); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "acc").Alias(Prefix + "allchannelcommands") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .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]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); foreach (var command in WizBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{channel.Name}** channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "arm").Alias(Prefix + "allrolemodules") .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description("Sets permissions for all modules at the role level.\n**Usage**: ;arm [enable/disable] [role_name]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); foreach (var module in WizBot.Client.GetService <ModuleService>().Modules) { PermissionsHandler.SetRoleModulePermission(role, module.Name, state); } await e.Channel.SendMessage($"All modules have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "arc").Alias(Prefix + "allrolecommands") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .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]") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("channel")); foreach (var command in WizBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { PermissionsHandler.SetRoleCommandPermission(role, command.Text, state); } await e.Channel.SendMessage($"All commands from the **{module}** module have been **{(state ? "enabled" : "disabled")}** for **{role.Name}** role.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Something went terribly wrong - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "ubl") .Description("Blacklists a mentioned user.\n**Usage**: ;ubl [user_mention]") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); WizBot.Config.UserBlacklist.Add(usr.Id); ConfigHandler.SaveConfig(); await e.Channel.SendMessage($"`Sucessfully blacklisted user {usr.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "uubl") .Description($"Unblacklists a mentioned user.\n**Usage**: {Prefix}uubl [user_mention]") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); if (WizBot.Config.UserBlacklist.Contains(usr.Id)) { WizBot.Config.UserBlacklist.Remove(usr.Id); ConfigHandler.SaveConfig(); await e.Channel.SendMessage($"`Sucessfully unblacklisted user {usr.Name}`").ConfigureAwait(false); } else { await e.Channel.SendMessage($"`{usr.Name} was not in blacklist`").ConfigureAwait(false); } }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cbl") .Description("Blacklists a mentioned channel (#general for example).\n**Usage**: ;cbl [channel_mention]") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); WizBot.Config.UserBlacklist.Add(ch.Id); ConfigHandler.SaveConfig(); await e.Channel.SendMessage($"`Sucessfully blacklisted channel {ch.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cubl") .Description("Unblacklists a mentioned channel (#general for example).\n**Usage**: ;cubl [channel_mention]") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); WizBot.Config.UserBlacklist.Remove(ch.Id); ConfigHandler.SaveConfig(); await e.Channel.SendMessage($"`Sucessfully blacklisted channel {ch.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "sbl") .Description("Blacklists a server by a name or id (#general for example). **BOT OWNER ONLY**\n**Usage**: ;sbl [servername/serverid]") .Parameter("server", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { var arg = e.GetArg("server")?.Trim(); if (string.IsNullOrWhiteSpace(arg)) { return; } var server = WizBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? WizBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (server == null) { await e.Channel.SendMessage("Cannot find that server").ConfigureAwait(false); return; } var serverId = server.Id; WizBot.Config.ServerBlacklist.Add(serverId); ConfigHandler.SaveConfig(); //cleanup trivias and typeracing Modules.Games.Commands.Trivia.TriviaGame trivia; TriviaCommands.RunningTrivias.TryRemove(serverId, out trivia); TypingGame typeracer; SpeedTyping.RunningContests.TryRemove(serverId, out typeracer); await e.Channel.SendMessage($"`Sucessfully blacklisted server {server.Name}`").ConfigureAwait(false); }).ConfigureAwait(false); }); }); }
public override void Install(ModuleManager manager) { manager.CreateCommands("", cgb => { cgb.AddCheck(PermissionChecker.Instance); commands.ForEach(cmd => cmd.Init(cgb)); cgb.CreateCommand(Prefix + "permrole") .Alias(Prefix + "pr") .Description("Setzt eine Rolle, welche die Berechtigungen bearbeiten kann. Ohne Angabe wird die derzeitige Rolle gezeigt. Standard 'Pony'.") .Parameter("role", ParameterType.Unparsed) .Do(async e => { if (string.IsNullOrWhiteSpace(e.GetArg("role"))) { await e.Channel.SendMessage($"Derzeitige Berechtigungs-Rolle ist `{PermissionsHandler.GetServerPermissionsRoleName (e.Server)}`").ConfigureAwait(false); return; } var arg = e.GetArg("role"); Discord.Role role = null; try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { Console.WriteLine(ex.Message); await e.Channel.SendMessage($"Rolle `{arg}` existiert nicht. Erstelle zuerst eine Rolle mit diesem Namen.").ConfigureAwait(false); return; } await PermissionsHandler.SetPermissionsRole(e.Server, role.Name).ConfigureAwait(false); await e.Channel.SendMessage($"Rolle `{role.Name}` ist nun benötigt um die Berechtigungen zu bearbeiten.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "rolepermscopy") .Alias(Prefix + "rpc") .Description($"Kopiert BOT BERECHTIGUNGEN (nicht Discord Berechtigungen) von einer Rolle zu einer anderen. | `{Prefix}rpc Some Role ~ Some other role`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Ungültige Anzahl von '~'s in den Argumenten.").ConfigureAwait(false); return; } try { var fromRole = PermissionHelper.ValidateRole(e.Server, args[0]); var toRole = PermissionHelper.ValidateRole(e.Server, args[1]); await PermissionsHandler.CopyRolePermissions(fromRole, toRole).ConfigureAwait(false); await e.Channel.SendMessage($"CBerechtigungseinstellungen von **{fromRole.Name}** zu **{toRole.Name}** kopiert.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}").ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlpermscopy") .Alias(Prefix + "cpc") .Description($"Kopiert BOT BERECHTIGUNGEN (nicht Discord Berechtigungen) von einem Channel zu einem anderen. | `{Prefix}cpc Some Channel ~ Some other channel`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Ungültige Anzahl von '~'s in den Argumenten.").ConfigureAwait(false); return; } try { var fromChannel = PermissionHelper.ValidateChannel(e.Server, args[0]); var toChannel = PermissionHelper.ValidateChannel(e.Server, args[1]); await PermissionsHandler.CopyChannelPermissions(fromChannel, toChannel).ConfigureAwait(false); await e.Channel.SendMessage($"Berechtigungseinstellungen von **{fromChannel.Name}** zu **{toChannel.Name}** kopiert.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "usrpermscopy") .Alias(Prefix + "upc") .Description($"Kopiert BOT BERECHTIGUNGEN (nicht Discord Berechtigungen) von einem Benutzer, zu einem anderen. | `{Prefix}upc @SomeUser ~ @SomeOtherUser`") .Parameter("from_to", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("from_to")?.Trim(); if (string.IsNullOrWhiteSpace(arg) || !arg.Contains('~')) { return; } var args = arg.Split('~').Select(a => a.Trim()).ToArray(); if (args.Length > 2) { await e.Channel.SendMessage("💢Ungültige Anzahl von '~'s in den Argumenten."); return; } try { var fromUser = PermissionHelper.ValidateUser(e.Server, args[0]); var toUser = PermissionHelper.ValidateUser(e.Server, args[1]); await PermissionsHandler.CopyUserPermissions(fromUser, toUser).ConfigureAwait(false); await e.Channel.SendMessage($"Berechtigungseinstellungen von **{fromUser.ToString ()}** zu * *{toUser.ToString ()}** kopiert.").ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage($"💢{ex.Message}"); } }); cgb.CreateCommand(Prefix + "verbose") .Alias(Prefix + "v") .Description($"Ändert ob das blocken/entblocken eines Modules/Befehls angezeigt wird. | `{Prefix}verbose true`") .Parameter("arg", ParameterType.Required) .Do(async e => { var arg = e.GetArg("arg"); var val = PermissionHelper.ValidateBool(arg); await PermissionsHandler.SetVerbosity(e.Server, val).ConfigureAwait(false); await e.Channel.SendMessage($"Verbosity wurde gesetzt auf {val}.").ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "serverperms") .Alias(Prefix + "sp") .Description("Zeigt gebannte Berechtigungen für diesen Server.") .Do(async e => { var perms = PermissionsHandler.GetServerPermissions(e.Server); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage("Keine Berechtigungen für diesen Server vorhanden.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "roleperms") .Alias(Prefix + "rp") .Description($"Zeigt gebannt Berechtigungen für eine bestimmte Rolle. Kein Argument bedeutet für alle. | `{Prefix}rp AwesomeRole`") .Parameter("role", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("role"); var role = e.Server.EveryoneRole; if (!string.IsNullOrWhiteSpace(arg)) { try { role = PermissionHelper.ValidateRole(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Fehler: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetRolePermissionsById(e.Server, role.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"Keine Berechtigungen gesetzt für **{role.Name}** Rolle.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "chnlperms") .Alias(Prefix + "cp") .Description($"Zeigt gebannte Berechtigungen für einen bestimmten Channel. Kein Argument für derzeitigen Channel. | `{Prefix}cp #dev`") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { var arg = e.GetArg("channel"); var channel = e.Channel; if (!string.IsNullOrWhiteSpace(arg)) { try { channel = PermissionHelper.ValidateChannel(e.Server, arg); } catch (Exception ex) { await e.Channel.SendMessage("💢 Fehler: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetChannelPermissionsById(e.Server, channel.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"Keine Berechtigungen gesetzt für **{channel.Name}** Channel.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "userperms") .Alias(Prefix + "up") .Description($"Zeigt gebannte Berechtigungen für einen bestimmten Benutzer. Keine Argumente für sich selber. | `{Prefix}up Kwoth`") .Parameter("user", ParameterType.Unparsed) .Do(async e => { var user = e.User; if (!string.IsNullOrWhiteSpace(e.GetArg("user"))) { try { user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); } catch (Exception ex) { await e.Channel.SendMessage("💢 Fehler: " + ex.Message).ConfigureAwait(false); return; } } var perms = PermissionsHandler.GetUserPermissionsById(e.Server, user.Id); if (string.IsNullOrWhiteSpace(perms?.ToString())) { await e.Channel.SendMessage($"Keine Berechtigungen gesetzt für Benutzer **{user.Name}**.").ConfigureAwait(false); } await e.Channel.SendMessage(perms.ToString()).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "srvrmdl") .Alias(Prefix + "sm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Setzt die Berechtigung eines Moduls auf Serverlevel. | `{Prefix}sm \"module name\" enable`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); await PermissionsHandler.SetServerModulePermission(e.Server, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktiviert")}** auf diesem Server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "srvrcmd").Alias(Prefix + "sc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Setzt die Berechtigung eines Befehls auf Serverlevel. | `{Prefix}sc \"command name\" disable`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); await PermissionsHandler.SetServerCommandPermission(e.Server, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktiviert" : "deaktiviert")}** auf diesem Server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schied gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rolemdl").Alias(Prefix + "rm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Moduls auf Rollenlevel. | `{Prefix}rm \"module name\" enable MyRole`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktivert")}** für **ALLE** Rollen.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); await PermissionsHandler.SetRoleModulePermission(role, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktivert")}** für die **{role.Name}** Rolle.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "rolecmd").Alias(Prefix + "rc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Befehls auf Rollenlevel. | `{Prefix}rc \"command name\" disable MyRole`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktivert" : "deaktivert")}** für **ALLE** Rollen.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); await PermissionsHandler.SetRoleCommandPermission(role, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktivert" : "deaktiviert")}** für die **{role.Name}** Rolle.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlmdl").Alias(Prefix + "cm") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Moduls auf Channellevel. | `{Prefix}cm \"module name\" enable SomeChannel`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var channelArg = e.GetArg("channel"); if (channelArg?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktiviert")}** auf **ALLEN** Channels.").ConfigureAwait(false); } else if (string.IsNullOrWhiteSpace(channelArg)) { await PermissionsHandler.SetChannelModulePermission(e.Channel, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktiviert")}** im **{e.Channel.Name}** Channel.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, channelArg); await PermissionsHandler.SetChannelModulePermission(channel, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktiviert")}** für den **{channel.Name}** Channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "chnlcmd").Alias(Prefix + "cc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Befehls auf Channellevel. | `{Prefix}cc \"command name\" enable SomeChannel`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); if (e.GetArg("channel")?.ToLower() == "all") { foreach (var channel in e.Server.TextChannels) { await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktiviert" : "deaktivert")}** auf **ALLEN** Channeln.").ConfigureAwait(false); } else { var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); await PermissionsHandler.SetChannelCommandPermission(channel, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktiviert" : "deaktiviert")}** für den **{channel.Name}** Channel.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "usrmdl").Alias(Prefix + "um") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Moduls auf Benutzerlevel. | `{Prefix}um \"module name\" enable [user_name]`") .Do(async e => { try { var module = PermissionHelper.ValidateModule(e.GetArg("module")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); await PermissionsHandler.SetUserModulePermission(user, module, state).ConfigureAwait(false); await e.Channel.SendMessage($"Modul **{module}** wurde **{(state ? "aktiviert" : "deaktiviert")}** für Benutzer **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "usrcmd").Alias(Prefix + "uc") .Parameter("command", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("user", ParameterType.Unparsed) .Description($"Setzt die Berechtigung eines Befehls auf Benutzerlevel. | `{Prefix}uc \"command name\" enable [user_name]`") .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var user = PermissionHelper.ValidateUser(e.Server, e.GetArg("user")); await PermissionsHandler.SetUserCommandPermission(user, command, state).ConfigureAwait(false); await e.Channel.SendMessage($"Befehl **{command}** wurde **{(state ? "aktiviert" : "deaktiviert")}** für Benutzer **{user.Name}**.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allsrvrmdls").Alias(Prefix + "asm") .Parameter("bool", ParameterType.Required) .Description($"Setzt die Berechtigung aller Module auf Serverlevel. | `{Prefix}asm [enable/disable]`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); foreach (var module in MidnightBot.Client.GetService <ModuleService> ().Modules) { await PermissionsHandler.SetServerModulePermission(e.Server, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Module wurden **{(state ? "aktivert" : "deaktivert")}** auf diesem Server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allsrvrcmds").Alias(Prefix + "asc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Description($"Setzt Berechtigungen für alle Befehle eines bestimmten Moduls auf Serverlevel. | `{Prefix}asc \"module name\" [enable/disable]`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); foreach (var command in MidnightBot.Client.GetService <CommandService> ().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetServerCommandPermission(e.Server, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Befehle des **{module}** Moduls wurden **{(state ? "aktiviert" : "deaktiviert")}** auf diesem Server.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allchnlmdls").Alias(Prefix + "acm") .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Setzt Berechtigungen für alle Module auf Channellevel. | `{Prefix}acm [enable/disable] SomeChannel`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var chArg = e.GetArg("channel"); var channel = string.IsNullOrWhiteSpace(chArg) ? e.Channel : PermissionHelper.ValidateChannel(e.Server, chArg); foreach (var module in MidnightBot.Client.GetService <ModuleService> ().Modules) { await PermissionsHandler.SetChannelModulePermission(channel, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Module wurden **{(state ? "aktivert" : "deaktiviert")}** im **{channel.Name}** Channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allchnlcmds").Alias(Prefix + "acc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("channel", ParameterType.Unparsed) .Description($"Setzt Berechtigungen für alle Befehle eines bestimmten Moduls auf Channellevel. | `{Prefix}acc \"module name\" [enable/disable] SomeChannel`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); var channel = PermissionHelper.ValidateChannel(e.Server, e.GetArg("channel")); foreach (var command in MidnightBot.Client.GetService <CommandService> ().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetChannelCommandPermission(channel, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Befehle des **{module}** Moduls wurden **{(state ? "aktiviert" : "deaktiviert")}** im **{channel.Name}** Channel.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allrolemdls").Alias(Prefix + "arm") .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Setzt Berechtigung von allen Modulen auf Rollenlevel. | `{Prefix}arm [enable/disable] MyRole`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); foreach (var module in MidnightBot.Client.GetService <ModuleService> ().Modules) { await PermissionsHandler.SetRoleModulePermission(role, module.Name, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Module wurden **{(state ? "aktiviert" : "deaktiviert")}** für die **{role.Name}** Rolle.").ConfigureAwait(false); } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allrolecmds").Alias(Prefix + "arc") .Parameter("module", ParameterType.Required) .Parameter("bool", ParameterType.Required) .Parameter("role", ParameterType.Unparsed) .Description($"Setzt Berechtigungen für alle Befehle eines bestimmten Moduls auf Rollenlevel. | `{Prefix}arc \"module name\" [enable/disable] MyRole`") .Do(async e => { try { var state = PermissionHelper.ValidateBool(e.GetArg("bool")); var module = PermissionHelper.ValidateModule(e.GetArg("module")); if (e.GetArg("role")?.ToLower() == "all") { foreach (var role in e.Server.Roles) { foreach (var command in MidnightBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false); } } await e.Channel.SendMessage($"Alle Befehle des **{module}** Moduls wurden **{(state ? "aktiviert" : "deaktiviert")}** für **alle Rollen**.").ConfigureAwait(false); } else { var role = PermissionHelper.ValidateRole(e.Server, e.GetArg("role")); foreach (var command in MidnightBot.Client.GetService <CommandService>().AllCommands.Where(c => c.Category == module)) { await PermissionsHandler.SetRoleCommandPermission(role, command.Text, state).ConfigureAwait(false); } await e.Channel.SendMessage($"Alle Befehle des **{module}** Moduls wurden **{(state ? "aktiviert" : "deaktiviert")}** für die **{role.Name}** Rolle.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Etwas ist schief gelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "ubl") .Description($"Blacklists einen Benutzer. | `{Prefix}ubl [user_mention]`") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); MidnightBot.Config.UserBlacklist.Add(usr.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Benutzer {usr.Name}` erfolgreich geblacklisted.").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "uubl") .Description($"Unblacklisted einen erwähnten Benutzer. | `{Prefix}uubl [user_mention]`") .Parameter("user", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedUsers.Any()) { return; } var usr = e.Message.MentionedUsers.First(); if (MidnightBot.Config.UserBlacklist.Contains(usr.Id)) { MidnightBot.Config.UserBlacklist.Remove(usr.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Benutzer {usr.Name} erfolgreich aus der Blacklist entfernt`").ConfigureAwait(false); } else { await e.Channel.SendMessage($"`{usr.Name} war nicht auf der Blacklist`").ConfigureAwait(false); } }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cbl") .Description($"Blacklists einen erwähnten Channel (#general zum Beispiel). | `{Prefix}cbl #some_channel`") .Parameter("channel", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); MidnightBot.Config.UserBlacklist.Add(ch.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Channel {ch.Name}` erfolgreich geblacklisted.").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cubl") .Description($"Unblacklists einen erwähnten Channel (#general zum Beispiel). | `{Prefix}cubl #some_channel`") .Parameter("channel", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { if (!e.Message.MentionedChannels.Any()) { return; } var ch = e.Message.MentionedChannels.First(); MidnightBot.Config.UserBlacklist.Remove(ch.Id); await ConfigHandler.SaveConfig().ConfigureAwait(false); await e.Channel.SendMessage($"`Channel {ch.Name} erfolgreich von der Blacklist entfernt.`").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "sbl") .Description($"Blacklists einen Server per Name, oder ID (#general zum Beispiel). | `{Prefix}sbl [servername/serverid]`") .Parameter("server", ParameterType.Unparsed) .AddCheck(SimpleCheckers.OwnerOnly()) .Do(async e => { await Task.Run(async() => { var arg = e.GetArg("server")?.Trim(); if (string.IsNullOrWhiteSpace(arg)) { return; } var server = MidnightBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? MidnightBot.Client.FindServers(arg.Trim()).FirstOrDefault(); if (server == null) { await e.Channel.SendMessage("Kann den Server nicht finden.").ConfigureAwait(false); return; } var serverId = server.Id; MidnightBot.Config.ServerBlacklist.Add(serverId); await ConfigHandler.SaveConfig().ConfigureAwait(false); //cleanup trivias and typeracing Modules.Games.Commands.Trivia.TriviaGame trivia; TriviaCommands.RunningTrivias.TryRemove(serverId, out trivia); TypingGame typeracer; SpeedTyping.RunningContests.TryRemove(serverId, out typeracer); await e.Channel.SendMessage($"`Server {server.Name}` erfolgreich geblacklisted.").ConfigureAwait(false); }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "subl") .Description($"Unblacklists einen erwähnten Server (#general zum Beispiel). | `{Prefix}subl #some_channel`") .Parameter("server", ParameterType.Unparsed) .Do(async e => { await Task.Run(async() => { var arg = e.GetArg("server")?.Trim(); if (string.IsNullOrWhiteSpace(arg)) { return; } ulong serverId; if (!ulong.TryParse(arg, out serverId)) { await e.Channel.SendMessage("Id ungültig.").ConfigureAwait(false); return; } var server = MidnightBot.Client.Servers.FirstOrDefault(s => s.Id.ToString() == arg) ?? MidnightBot.Client.FindServers(arg.Trim()).FirstOrDefault(); MidnightBot.Config.ServerBlacklist.Remove(serverId); await ConfigHandler.SaveConfig().ConfigureAwait(false); if (server == null) { await e.Channel.SendMessage("Server nicht gefunden!").ConfigureAwait(false); } else { await e.Channel.SendMessage($"`Server {server.Name}` erfolgreich von Blacklist entfernt.").ConfigureAwait(false); } }).ConfigureAwait(false); }); cgb.CreateCommand(Prefix + "cmdcooldown") .Alias(Prefix + "cmdcd") .Description($"Setzt einen Cooldown für einen Befehl per Benutzer. Setze auf 0, um den Cooldown zu entfernen. | `{Prefix}cmdcd \"some cmd\" 5`") .Parameter("command", ParameterType.Required) .Parameter("secs", ParameterType.Required) .AddCheck(SimpleCheckers.ManageMessages()) .Do(async e => { try { var command = PermissionHelper.ValidateCommand(e.GetArg("command")); var secsStr = e.GetArg("secs").Trim(); int secs; if (!int.TryParse(secsStr, out secs) || secs < 0 || secs > 3600) { throw new ArgumentOutOfRangeException("secs", "Ungültiger zweiter Parameter. (Muss eine Zahl zwischen 0 und 3600 sein)"); } await PermissionsHandler.SetCommandCooldown(e.Server, command, secs).ConfigureAwait(false); if (secs == 0) { await e.Channel.SendMessage($"Befehl **{command}** hat jetzt keinen Cooldown mehr.").ConfigureAwait(false); } else { await e.Channel.SendMessage($"Befehl **{command}** hat nun einen **{secs} {(secs==1 ? "Sekunden" : "Sekunden")}** Cooldown.").ConfigureAwait(false); } } catch (ArgumentException exArg) { await e.Channel.SendMessage(exArg.Message).ConfigureAwait(false); } catch (Exception ex) { await e.Channel.SendMessage("Irgendwas ist schiefgelaufen - " + ex.Message).ConfigureAwait(false); } }); cgb.CreateCommand(Prefix + "allcmdcooldowns") .Alias(Prefix + "acmdcds") .Description("Zeigt eine Liste aller Befehle und Ihrer Cooldowns.") .Do(async e => { ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(e.Server.Id, out perms); if (perms == null) { return; } if (!perms.CommandCooldowns.Any()) { await e.Channel.SendMessage("`Keine Befehls-Cooldowns gesetzt.`").ConfigureAwait(false); return; } await e.Channel.SendMessage(SearchHelper.ShowInPrettyCode(perms.CommandCooldowns.Select(c => c.Key + ": " + c.Value + " Sekunden"), s => $"{s,-30}", 2)).ConfigureAwait(false); }); }); }