From 123b75b7c9ad20936d1e8e89056026d6a9954714 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 19 Jul 2016 16:53:09 +0200 Subject: [PATCH] ;acmdcds added to benefit ;cmdcd, permission system can now take aliases --- .../Permissions/Classes/PermissionHelper.cs | 4 +++- .../Modules/Permissions/PermissionsModule.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/NadekoBot/Modules/Permissions/Classes/PermissionHelper.cs b/NadekoBot/Modules/Permissions/Classes/PermissionHelper.cs index aef62ac8..c972953e 100644 --- a/NadekoBot/Modules/Permissions/Classes/PermissionHelper.cs +++ b/NadekoBot/Modules/Permissions/Classes/PermissionHelper.cs @@ -55,9 +55,11 @@ namespace NadekoBot.Modules.Permissions.Classes if (string.IsNullOrWhiteSpace(commandText)) throw new ArgumentNullException(nameof(commandText)); + var normalizedCmdTxt = commandText.Trim().ToUpperInvariant(); + foreach (var com in NadekoBot.Client.GetService().AllCommands) { - if (com.Text.ToLower().Equals(commandText.Trim().ToLower())) + if (com.Text.ToUpperInvariant().Equals(normalizedCmdTxt) || com.Aliases.Select(c=>c.ToUpperInvariant()).Contains(normalizedCmdTxt)) return com.Text; } throw new NullReferenceException("That command does not exist."); diff --git a/NadekoBot/Modules/Permissions/PermissionsModule.cs b/NadekoBot/Modules/Permissions/PermissionsModule.cs index 82cf1c34..4c13b9ff 100644 --- a/NadekoBot/Modules/Permissions/PermissionsModule.cs +++ b/NadekoBot/Modules/Permissions/PermissionsModule.cs @@ -1,5 +1,6 @@ using Discord.Commands; using Discord.Modules; +using NadekoBot.Classes; using NadekoBot.Classes.JSONModels; using NadekoBot.Extensions; using NadekoBot.Modules.Games.Commands; @@ -809,6 +810,24 @@ namespace NadekoBot.Modules.Permissions 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.") + .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); + }); }); } }