diff --git a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs index 3a110f79..ae76811f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs @@ -191,6 +191,39 @@ namespace NadekoBot.Modules.Administration await Context.Channel.EmbedAsync(embed); } + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + [RequireUserPermission(GuildPermission.BanMembers)] + public async Task WarnlogAll(int page = 1) + { + if (--page < 0) + return; + IGrouping[] warnings; + using (var uow = _db.UnitOfWork) + { + warnings = uow.Warnings.GetAll().GroupBy(x => x.UserId).ToArray(); + } + + await Context.Channel.SendPaginatedConfirmAsync((DiscordSocketClient)Context.Client, page, async (curPage) => + { + var ws = await Task.WhenAll(warnings.Skip(curPage * 15) + .Take(15) + .ToArray() + .Select(async x => + { + var all = x.Count(); + var forgiven = x.Count(y => y.Forgiven); + var total = all - forgiven; + return ((await Context.Guild.GetUserAsync(x.Key))?.ToString() ?? x.Key.ToString()) + $" | {total} ({all} - {forgiven})"; + })); + + return new EmbedBuilder() + .WithTitle(GetText("warnings_list")) + .WithDescription(string.Join("\n", ws)); + + }, warnings.Length / 15); + } + [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequireUserPermission(GuildPermission.BanMembers)] diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 064a19ba..8ddcf04d 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -3258,6 +3258,15 @@ `{0}warnlog @b1nzy` + + warnlogall + + + See a list of all warnings on the server. 15 users per page. + + + `{0}warnlogall` or `{0}warnlogall 2` + warn diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 10e97e14..8488071b 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -66,15 +66,16 @@ namespace NadekoBot.Extensions ms.Seek(0, SeekOrigin.Begin); return ms; } - + public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func pageFunc, int? lastPage = null, bool addPaginatedFooter = true) => + channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), lastPage, addPaginatedFooter); /// /// danny kamisama /// - public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func pageFunc, int? lastPage = null, bool addPaginatedFooter = true) + public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) { - var embed = pageFunc(currentPage); + var embed = await pageFunc(currentPage).ConfigureAwait(false); - if(addPaginatedFooter) + if (addPaginatedFooter) embed.AddPaginatedFooter(currentPage, lastPage); var msg = await channel.EmbedAsync(embed) as IUserMessage; @@ -82,8 +83,8 @@ namespace NadekoBot.Extensions if (lastPage == 0) return; - - await msg.AddReactionAsync( arrow_left).ConfigureAwait(false); + + await msg.AddReactionAsync(arrow_left).ConfigureAwait(false); await msg.AddReactionAsync(arrow_right).ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false); @@ -96,7 +97,7 @@ namespace NadekoBot.Extensions { if (currentPage == 0) return; - var toSend = pageFunc(--currentPage); + var toSend = await pageFunc(--currentPage).ConfigureAwait(false); if (addPaginatedFooter) toSend.AddPaginatedFooter(currentPage, lastPage); await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false); @@ -105,7 +106,7 @@ namespace NadekoBot.Extensions { if (lastPage == null || lastPage > currentPage) { - var toSend = pageFunc(++currentPage); + var toSend = await pageFunc(++currentPage).ConfigureAwait(false); if (addPaginatedFooter) toSend.AddPaginatedFooter(currentPage, lastPage); await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false); @@ -315,7 +316,7 @@ namespace NadekoBot.Extensions return list; } } - + /// /// Easy use of fast, efficient case-insensitive Contains check with StringComparison Member Types /// CurrentCulture, CurrentCultureIgnoreCase, InvariantCulture, InvariantCultureIgnoreCase, Ordinal, OrdinalIgnoreCase @@ -482,4 +483,4 @@ namespace NadekoBot.Extensions : usr.GetAvatarUrl(ImageFormat.Auto); } } -} +} \ No newline at end of file diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index 872008cb..9edb025c 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -303,7 +303,7 @@ "help_server_permission": "Requires {0} server permission.", "help_table_of_contents": "Table of contents", "help_usage": "Usage", - "help_module": "Module: {0}", + "help_module": "Module: {0}", "nsfw_autohentai_started": "Autohentai started. Reposting every {0}s with one of the following tags:\n{1}", "nsfw_tag": "Tag", "gambling_animal_race": "Animal race", @@ -735,6 +735,7 @@ "administration_warned_on_by": "On {0} at {1} by {2}", "administration_warnings_cleared": "All warnings have been cleared for {0}.", "administration_warnings_none": "No warning on this page.", + "administration_warnings_list": "List of all warned users on the server.", "administration_warnlog_for": "Warnlog for {0}", "administration_warnpl_none": "No punishments set.", "administration_warn_cleared_by": "cleared by {0}",