;acmdcds added to benefit ;cmdcd, permission system can now take aliases

This commit is contained in:
Kwoth 2016-07-19 16:53:09 +02:00
parent 3b8e9a6af7
commit 123b75b7c9
2 changed files with 22 additions and 1 deletions

View File

@ -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<CommandService>().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.");

View File

@ -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);
});
});
}
}