From 909ab60042e353428e1a21b901d472d2a2d0bfed Mon Sep 17 00:00:00 2001 From: 13xforever Date: Mon, 18 Feb 2019 00:44:28 +0500 Subject: [PATCH] command to list warnings issued by a specific mod --- CompatBot/Commands/Warnings.ListGroup.cs | 47 +++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/CompatBot/Commands/Warnings.ListGroup.cs b/CompatBot/Commands/Warnings.ListGroup.cs index 55612c78..e1646c0b 100644 --- a/CompatBot/Commands/Warnings.ListGroup.cs +++ b/CompatBot/Commands/Warnings.ListGroup.cs @@ -69,6 +69,51 @@ namespace CompatBot.Commands await ctx.SendAutosplitMessageAsync(new StringBuilder("Warning count per user:").Append(table)).ConfigureAwait(false); } + [Command("by"), RequiresBotModRole] + [Description("Shows warnings issued by the specified moderator")] + public async Task By(CommandContext ctx, ulong moderatorId, [Description("Optional number of items to show. Default is 10")] int number = 10) + { + if (number < 1) + number = 10; + var table = new AsciiTable( + new AsciiColumn("ID", alignToRight: true), + new AsciiColumn("Username", maxWidth: 24), + new AsciiColumn("User ID", disabled: !ctx.Channel.IsPrivate, alignToRight: true), + new AsciiColumn("On date (UTC)"), + new AsciiColumn("Reason"), + new AsciiColumn("Context", disabled: !ctx.Channel.IsPrivate) + ); + using (var db = new BotDb()) + { + var query = from warn in db.Warning + where warn.IssuerId == moderatorId + orderby warn.Id descending + select warn; + foreach (var row in query.Take(number)) + { + var username = await ctx.GetUserNameAsync(row.DiscordId).ConfigureAwait(false); + var timestamp = row.Timestamp.HasValue ? new DateTime(row.Timestamp.Value, DateTimeKind.Utc).ToString("u") : null; + table.Add(row.Id.ToString(), username, row.DiscordId.ToString(), timestamp, row.Reason, row.FullReason); + } + } + var modname = await ctx.GetUserNameAsync(moderatorId, defaultName: "Unknown mod").ConfigureAwait(false); + await ctx.SendAutosplitMessageAsync(new StringBuilder($"Recent warnings issued by {modname}:").Append(table)).ConfigureAwait(false); + + } + + [Command("by"), RequiresBotModRole] + public Task By(CommandContext ctx, DiscordUser moderator, [Description("Optional number of items to show. Default is 10")] int number = 10) + => By(ctx, moderator.Id, number); + + [Command("by"), RequiresBotModRole] + public Task By(CommandContext ctx, string me, [Description("Optional number of items to show. Default is 10")] int number = 10) + { + if (me?.ToLowerInvariant() == "me") + return By(ctx, ctx.User.Id, number); + + return Task.CompletedTask; + } + [Command("recent"), Aliases("last", "all"), RequiresBotModRole] [Description("Shows last issued warnings in chronological order")] public async Task Last(CommandContext ctx, [Description("Optional number of items to show. Default is 10")] int number = 10) @@ -97,7 +142,7 @@ namespace CompatBot.Commands table.Add(row.Id.ToString(), username, row.DiscordId.ToString(), modname, timestamp, row.Reason, row.FullReason); } } - await ctx.SendAutosplitMessageAsync(new StringBuilder("Last issued warnings:").Append(table)).ConfigureAwait(false); + await ctx.SendAutosplitMessageAsync(new StringBuilder("Recent warnings:").Append(table)).ConfigureAwait(false); } private async Task CheckListPermissionAsync(CommandContext ctx, ulong userId)