From 06ca1c5f8f96ce2f2f18e200f4004600f32746d1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 10 Apr 2017 19:56:10 +0200 Subject: [PATCH] You can now use actualcustomreactions as a module name to enable/disable actual custom reactions, as opposed to commands to manage them which are in CustomReactions module --- .../Games/Commands/PlantAndPickCommands.cs | 3 ++- .../Commands/GlobalPermissionCommands.cs | 2 +- .../Modules/Permissions/Permissions.cs | 8 +++---- src/NadekoBot/NadekoBot.cs | 1 + src/NadekoBot/TypeReaders/ModuleTypeReader.cs | 21 +++++++++++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index 7c081289..44eb474a 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -181,7 +181,7 @@ namespace NadekoBot.Modules.Games return old; }); } - +#if !GLOBAL_NADEKO [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.ManageMessages)] @@ -218,6 +218,7 @@ namespace NadekoBot.Modules.Games await ReplyConfirmLocalized("curgen_disabled").ConfigureAwait(false); } } +#endif private static KeyValuePair> GetRandomCurrencyImage() { diff --git a/src/NadekoBot/Modules/Permissions/Commands/GlobalPermissionCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/GlobalPermissionCommands.cs index 41ba61b3..e493f03d 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/GlobalPermissionCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/GlobalPermissionCommands.cs @@ -52,7 +52,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] - public async Task Gmod(ModuleInfo module) + public async Task Gmod(ModuleOrCrInfo module) { var moduleName = module.Name.ToLowerInvariant(); if (BlockedModules.Add(moduleName)) diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index a942fd7e..e9f92c66 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -363,7 +363,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task SrvrMdl(ModuleInfo module, PermissionAction action) + public async Task SrvrMdl(ModuleOrCrInfo module, PermissionAction action) { await AddPermissions(Context.Guild.Id, new Permissionv2 { @@ -419,7 +419,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task UsrMdl(ModuleInfo module, PermissionAction action, [Remainder] IGuildUser user) + public async Task UsrMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] IGuildUser user) { await AddPermissions(Context.Guild.Id, new Permissionv2 { @@ -480,7 +480,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task RoleMdl(ModuleInfo module, PermissionAction action, [Remainder] IRole role) + public async Task RoleMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] IRole role) { if (role == role.Guild.EveryoneRole) return; @@ -542,7 +542,7 @@ namespace NadekoBot.Modules.Permissions [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] - public async Task ChnlMdl(ModuleInfo module, PermissionAction action, [Remainder] ITextChannel chnl) + public async Task ChnlMdl(ModuleOrCrInfo module, PermissionAction action, [Remainder] ITextChannel chnl) { await AddPermissions(Context.Guild.Id, new Permissionv2 { diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index 6673cacb..075c12e8 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -112,6 +112,7 @@ namespace NadekoBot CommandService.AddTypeReader(new CommandTypeReader()); CommandService.AddTypeReader(new CommandOrCrTypeReader()); CommandService.AddTypeReader(new ModuleTypeReader()); + CommandService.AddTypeReader(new ModuleOrCrTypeReader()); CommandService.AddTypeReader(new GuildTypeReader()); diff --git a/src/NadekoBot/TypeReaders/ModuleTypeReader.cs b/src/NadekoBot/TypeReaders/ModuleTypeReader.cs index ae93576e..10278060 100644 --- a/src/NadekoBot/TypeReaders/ModuleTypeReader.cs +++ b/src/NadekoBot/TypeReaders/ModuleTypeReader.cs @@ -17,4 +17,25 @@ namespace NadekoBot.TypeReaders return Task.FromResult(TypeReaderResult.FromSuccess(module)); } } + + public class ModuleOrCrTypeReader : TypeReader + { + public override Task Read(ICommandContext context, string input) + { + input = input.ToLowerInvariant(); + var module = NadekoBot.CommandService.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToLowerInvariant() == input)?.Key; + if (module == null && input != "actualcustomreactions") + return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such module found.")); + + return Task.FromResult(TypeReaderResult.FromSuccess(new ModuleOrCrInfo + { + Name = input, + })); + } + } + + public class ModuleOrCrInfo + { + public string Name { get; set; } + } }