From 3f168a21f104f8e3812b19bb06792622f9451f26 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 30 Sep 2016 17:16:30 +0200 Subject: [PATCH] Permissions now friendly to custom reactions (soon:tm:) --- src/NadekoBot/Modules/Help/Help.cs | 15 +++++++++++++-- .../Permissions/PermissionExtensions.cs | 19 +++++++++++++------ src/NadekoBot/Services/CommandHandler.cs | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index bb6fcd65..adfabeee 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -19,8 +19,19 @@ namespace NadekoBot.Modules.Help { public string HelpString { get { - var str = "To add me to your server, use this link -> \n"; - return str + String.Format(str, NadekoBot.Credentials.ClientId); + var str = @"To add me to your server, use this link -> +You can use `{1}modules` command to see a list of all modules. +You can use `{1}commands ModuleName` +(for example `{1}commands Administration`) to see a list of all of the commands in that module. +For a specific command help, use {1}h ""Command name"" (for example {1}h !!q) + + +**LIST OF COMMANDS CAN BE FOUND ON THIS LINK** + + + +Nadeko Support Server: https://discord.gg/0ehQwTK2RBjAxzEY"; + return String.Format(str, NadekoBot.Credentials.ClientId, NadekoBot.ModulePrefixes[typeof(Help).Name]); } } public Help(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client) diff --git a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs index 70905eaf..6a39a9ff 100644 --- a/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/PermissionExtensions.cs @@ -17,10 +17,17 @@ namespace NadekoBot.Modules.Permissions { var perms = permsEnumerable as List ?? permsEnumerable.ToList(); int throwaway; - return perms.CheckPermissions(message, command, out throwaway); + return perms.CheckPermissions(message, command.Name, command.Module.Name, out throwaway); } - public static bool CheckPermissions(this IEnumerable permsEnumerable, IUserMessage message, Command command, out int permIndex) + public static bool CheckPermissions(this IEnumerable permsEnumerable, IUserMessage message, string commandName, string moduleName) + { + var perms = permsEnumerable as List ?? permsEnumerable.ToList(); + int throwaway; + return perms.CheckPermissions(message, commandName, moduleName, out throwaway); + } + + public static bool CheckPermissions(this IEnumerable permsEnumerable, IUserMessage message, string commandName, string moduleName, out int permIndex) { var perms = permsEnumerable as List ?? permsEnumerable.ToList(); @@ -28,7 +35,7 @@ namespace NadekoBot.Modules.Permissions { var perm = perms[i]; - var result = perm.CheckPermission(message, command); + var result = perm.CheckPermission(message, commandName, moduleName); if (result == null) { @@ -47,12 +54,12 @@ namespace NadekoBot.Modules.Permissions //null = not applicable //true = applicable, allowed //false = applicable, not allowed - public static bool? CheckPermission(this Permission perm, IUserMessage message, Command command) + public static bool? CheckPermission(this Permission perm, IUserMessage message, string commandName, string moduleName) { if (!((perm.SecondaryTarget == SecondaryPermissionType.Command && - perm.SecondaryTargetName.ToLowerInvariant() == command.Text.ToLowerInvariant()) || + perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant()) || (perm.SecondaryTarget == SecondaryPermissionType.Module && - perm.SecondaryTargetName.ToLowerInvariant() == command.Module.Name.ToLowerInvariant()) || + perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant()) || perm.SecondaryTarget == SecondaryPermissionType.AllModules)) return null; diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 7a562ca7..0a7f6372 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -164,7 +164,7 @@ namespace NadekoBot.Services if (guild != null) { int index; - if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd, out index)) + if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd.Name, cmd.Module.Name, out index)) { var returnMsg = $"Permission number #{index} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action."; return new Tuple(cmd, SearchResult.FromError(CommandError.Exception, returnMsg));