.warnlogall command added

This commit is contained in:
Master Kwoth 2017-06-28 04:59:32 +02:00
parent e9365b7753
commit b08ad7cb77
4 changed files with 55 additions and 11 deletions

View File

@ -191,6 +191,39 @@ namespace NadekoBot.Modules.Administration
await Context.Channel.EmbedAsync(embed); 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<ulong, Warning>[] 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] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[RequireUserPermission(GuildPermission.BanMembers)] [RequireUserPermission(GuildPermission.BanMembers)]

View File

@ -3258,6 +3258,15 @@
<data name="warnlog_usage" xml:space="preserve"> <data name="warnlog_usage" xml:space="preserve">
<value>`{0}warnlog @b1nzy`</value> <value>`{0}warnlog @b1nzy`</value>
</data> </data>
<data name="warnlogall_cmd" xml:space="preserve">
<value>warnlogall</value>
</data>
<data name="warnlogall_desc" xml:space="preserve">
<value>See a list of all warnings on the server. 15 users per page.</value>
</data>
<data name="warnlogall_usage" xml:space="preserve">
<value>`{0}warnlogall` or `{0}warnlogall 2`</value>
</data>
<data name="warn_cmd" xml:space="preserve"> <data name="warn_cmd" xml:space="preserve">
<value>warn</value> <value>warn</value>
</data> </data>

View File

@ -66,15 +66,16 @@ namespace NadekoBot.Extensions
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
return ms; return ms;
} }
public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) =>
channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), lastPage, addPaginatedFooter);
/// <summary> /// <summary>
/// danny kamisama /// danny kamisama
/// </summary> /// </summary>
public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, Task<EmbedBuilder>> 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); embed.AddPaginatedFooter(currentPage, lastPage);
var msg = await channel.EmbedAsync(embed) as IUserMessage; var msg = await channel.EmbedAsync(embed) as IUserMessage;
@ -83,7 +84,7 @@ namespace NadekoBot.Extensions
return; return;
await msg.AddReactionAsync( arrow_left).ConfigureAwait(false); await msg.AddReactionAsync(arrow_left).ConfigureAwait(false);
await msg.AddReactionAsync(arrow_right).ConfigureAwait(false); await msg.AddReactionAsync(arrow_right).ConfigureAwait(false);
await Task.Delay(2000).ConfigureAwait(false); await Task.Delay(2000).ConfigureAwait(false);
@ -96,7 +97,7 @@ namespace NadekoBot.Extensions
{ {
if (currentPage == 0) if (currentPage == 0)
return; return;
var toSend = pageFunc(--currentPage); var toSend = await pageFunc(--currentPage).ConfigureAwait(false);
if (addPaginatedFooter) if (addPaginatedFooter)
toSend.AddPaginatedFooter(currentPage, lastPage); toSend.AddPaginatedFooter(currentPage, lastPage);
await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false); await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false);
@ -105,7 +106,7 @@ namespace NadekoBot.Extensions
{ {
if (lastPage == null || lastPage > currentPage) if (lastPage == null || lastPage > currentPage)
{ {
var toSend = pageFunc(++currentPage); var toSend = await pageFunc(++currentPage).ConfigureAwait(false);
if (addPaginatedFooter) if (addPaginatedFooter)
toSend.AddPaginatedFooter(currentPage, lastPage); toSend.AddPaginatedFooter(currentPage, lastPage);
await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false); await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false);

View File

@ -735,6 +735,7 @@
"administration_warned_on_by": "On {0} at {1} by {2}", "administration_warned_on_by": "On {0} at {1} by {2}",
"administration_warnings_cleared": "All warnings have been cleared for {0}.", "administration_warnings_cleared": "All warnings have been cleared for {0}.",
"administration_warnings_none": "No warning on this page.", "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_warnlog_for": "Warnlog for {0}",
"administration_warnpl_none": "No punishments set.", "administration_warnpl_none": "No punishments set.",
"administration_warn_cleared_by": "cleared by {0}", "administration_warn_cleared_by": "cleared by {0}",