From b47d06fa10143061642272fad3fb4f44035c430a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 10 Dec 2016 23:58:55 +0100 Subject: [PATCH] Permissions module prettified --- .../Permissions/Commands/BlacklistCommands.cs | 3 +- .../Permissions/Commands/CmdCdsCommands.cs | 12 +++-- .../Modules/Permissions/Permissions.cs | 50 +++++++++---------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs index d218b9b0..2d90a2e7 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/BlacklistCommands.cs @@ -1,6 +1,7 @@ ๏ปฟusing Discord; using Discord.Commands; using NadekoBot.Attributes; +using NadekoBot.Extensions; using NadekoBot.Modules.Games.Trivia; using NadekoBot.Services; using NadekoBot.Services.Database.Models; @@ -104,7 +105,7 @@ namespace NadekoBot.Modules.Permissions } - await channel.SendMessageAsync(":ok:").ConfigureAwait(false); + await channel.SendConfirmAsync($"Blacklisted a `{type}` with id `{id}`").ConfigureAwait(false); } } } diff --git a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs index 8ef8f5c4..c18bf8ed 100644 --- a/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/Commands/CmdCdsCommands.cs @@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Permissions var channel = (ITextChannel)imsg.Channel; if (secs < 0 || secs > 3600) { - await channel.SendMessageAsync("โš ๏ธ Invalid second parameter. (Must be a number between 0 and 3600)").ConfigureAwait(false); + await channel.SendErrorAsync("Invalid second parameter. (Must be a number between 0 and 3600)").ConfigureAwait(false); return; } @@ -68,10 +68,14 @@ namespace NadekoBot.Modules.Permissions { var activeCds = activeCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); activeCds.RemoveWhere(ac => ac.Command == command.Text.ToLowerInvariant()); - await channel.SendMessageAsync($"๐Ÿšฎ Command **{command}** has no coooldown now and all existing cooldowns have been cleared.").ConfigureAwait(false); + await channel.SendConfirmAsync($"๐Ÿšฎ Command **{command}** has no coooldown now and all existing cooldowns have been cleared.") + .ConfigureAwait(false); } else - await channel.SendMessageAsync($"โœ… Command **{command}** now has a **{secs} {(secs == 1 ? "second" : "seconds")}** cooldown.").ConfigureAwait(false); + { + await channel.SendConfirmAsync($"โœ… Command **{command}** now has a **{secs} {"seconds".SnPl(secs)}** cooldown.") + .ConfigureAwait(false); + } } [NadekoCommand, Usage, Description, Aliases] @@ -82,7 +86,7 @@ namespace NadekoBot.Modules.Permissions var localSet = commandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); if (!localSet.Any()) - await channel.SendMessageAsync("โ„น๏ธ `No command cooldowns set.`").ConfigureAwait(false); + await channel.SendConfirmAsync("โ„น๏ธ `No command cooldowns set.`").ConfigureAwait(false); else await channel.SendTableAsync("", localSet.Select(c => c.CommandName + ": " + c.Seconds + " secs"), s => $"{s,-30}", 2).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 815896f6..d3de046c 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -7,6 +7,7 @@ using NadekoBot.Services; using Discord; using NadekoBot.Services.Database.Models; using System.Collections.Concurrent; +using NadekoBot.Extensions; namespace NadekoBot.Modules.Permissions { @@ -62,7 +63,7 @@ namespace NadekoBot.Modules.Permissions await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync("โ„น๏ธ I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false); + await channel.SendConfirmAsync("โ„น๏ธ I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -75,7 +76,7 @@ namespace NadekoBot.Modules.Permissions var config = uow.GuildConfigs.For(channel.Guild.Id, set => set); if (role == null) { - await channel.SendMessageAsync($"โ„น๏ธ Current permission role is **{config.PermissionRole}**.").ConfigureAwait(false); + await channel.SendConfirmAsync($"โ„น๏ธ Current permission role is **{config.PermissionRole}**.").ConfigureAwait(false); return; } else { @@ -90,7 +91,7 @@ namespace NadekoBot.Modules.Permissions } } - await channel.SendMessageAsync($"โœ… Users now require **{role.Name}** role in order to edit permissions.").ConfigureAwait(false); + await channel.SendConfirmAsync($"Users now require **{role.Name}** role in order to edit permissions.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -109,10 +110,7 @@ namespace NadekoBot.Modules.Permissions toSend = Format.Code($"๐Ÿ“„ Permissions page {page}") + "\n\n" + String.Join("\n", perms.AsEnumerable().Skip((page - 1) * 20).Take(20).Select(p => $"`{(i++)}.` {(p.Next == null ? Format.Bold(p.GetCommand(channel.Guild) + " [uneditable]") : (p.GetCommand(channel.Guild)))}")); } - if (string.IsNullOrWhiteSpace(toSend)) - await channel.SendMessageAsync("โ—๏ธ`No permissions set.`").ConfigureAwait(false); - else - await channel.SendMessageAsync(toSend).ConfigureAwait(false); + await channel.SendMessageAsync(toSend).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -156,11 +154,11 @@ namespace NadekoBot.Modules.Permissions uow2._context.SaveChanges(); } - await channel.SendMessageAsync($"โœ… {imsg.Author.Mention} removed permission **{p.GetCommand(channel.Guild)}** from position #{index + 1}.").ConfigureAwait(false); + await channel.SendConfirmAsync($"โœ… {imsg.Author.Mention} removed permission **{p.GetCommand(channel.Guild)}** from position #{index + 1}.").ConfigureAwait(false); } catch (ArgumentOutOfRangeException) { - await channel.SendMessageAsync("โ—๏ธ`No command on that index found.`").ConfigureAwait(false); + await channel.SendErrorAsync("โ—๏ธ`No command on that index found.`").ConfigureAwait(false); } } @@ -208,13 +206,13 @@ namespace NadekoBot.Modules.Permissions { if (!fromFound) { - await channel.SendMessageAsync($"โ—๏ธ`Can't find permission at index `#{++from}`").ConfigureAwait(false); + await channel.SendErrorAsync($"Can't find permission at index `#{++from}`").ConfigureAwait(false); return; } if (!toFound) { - await channel.SendMessageAsync($"โ—๏ธ`Can't find permission at index `#{++to}`").ConfigureAwait(false); + await channel.SendErrorAsync($"Can't find permission at index `#{++to}`").ConfigureAwait(false); return; } } @@ -264,14 +262,14 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"โœ… `Moved permission:` \"{fromPerm.GetCommand(channel.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false); + await channel.SendConfirmAsync($"`Moved permission:` \"{fromPerm.GetCommand(channel.Guild)}\" `from #{++from} to #{++to}.`").ConfigureAwait(false); return; } catch (Exception e) when (e is ArgumentOutOfRangeException || e is IndexOutOfRangeException) { } } - await channel.SendMessageAsync("`Invalid index(es) specified.`").ConfigureAwait(false); + await channel.SendErrorAsync("`Invalid index(es) specified.`").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -300,7 +298,7 @@ namespace NadekoBot.Modules.Permissions await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command on this server.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -328,7 +326,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of **`{module.Name}`** module on this server.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of **`{module.Name}`** module on this server.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -356,7 +354,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{user}` user.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -384,7 +382,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{user}` user.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -412,7 +410,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{role}` role.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -440,7 +438,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{role}` role.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -471,9 +469,9 @@ namespace NadekoBot.Modules.Permissions } } catch (Exception ex) { - Console.WriteLine(ex); + _log.Error(ex); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{chnl}` channel.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{command.Text}` command for `{chnl}` channel.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -501,7 +499,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `{module.Name}` module for `{chnl}` channel.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -529,7 +527,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{chnl}` channel.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -557,7 +555,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{role}` role.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -585,7 +583,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` for `{user}` user.").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] @@ -624,7 +622,7 @@ namespace NadekoBot.Modules.Permissions }, (id, old) => { old.RootPermission = config.RootPermission; return old; }); await uow.CompleteAsync().ConfigureAwait(false); } - await channel.SendMessageAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false); + await channel.SendConfirmAsync($"{(action.Value ? "โœ… Allowed" : "๐Ÿ†— Denied")} usage of `ALL MODULES` on this server.").ConfigureAwait(false); } } }