From 5cf1248bf04df3b5a6c1fe8bb46a4019057904ad Mon Sep 17 00:00:00 2001 From: runebaas Date: Mon, 11 May 2020 23:44:15 +0200 Subject: [PATCH] Add !quote stats (v1) --- Geekbot.net/Commands/Utils/Quote/Quote.cs | 48 ++++++++++++++++++- Geekbot.net/Lib/Localization/Translations.yml | 9 ++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Geekbot.net/Commands/Utils/Quote/Quote.cs b/Geekbot.net/Commands/Utils/Quote/Quote.cs index f568036..454ad9b 100644 --- a/Geekbot.net/Commands/Utils/Quote/Quote.cs +++ b/Geekbot.net/Commands/Utils/Quote/Quote.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Threading.Tasks; using Discord; @@ -192,6 +192,52 @@ namespace Geekbot.net.Commands.Utils.Quote } } + [Command("stats")] + [Summary("Show quote stats for this server")] + public async Task GetQuoteStatsForServer() + { + try + { + var transContext = await _translationHandler.GetGuildContext(Context); + var eb = new EmbedBuilder(); + eb.Author = new EmbedAuthorBuilder() + { + IconUrl = Context.Guild.IconUrl, + Name = $"{Context.Guild.Name} - {transContext.GetString("QuoteStats")}" + }; + + var totalQuotes = _database.Quotes.Count(row => row.GuildId == Context.Guild.Id.AsLong()); + if (totalQuotes == 0) + { + await ReplyAsync(transContext.GetString("NoQuotesFound")); + return; + } + eb.AddInlineField(transContext.GetString("TotalQuotes"), totalQuotes); + + var mostQuotedPerson = _database.Quotes + .Where(row => row.GuildId == Context.Guild.Id.AsLong()) + .GroupBy(row => row.UserId) + .Max(row => row.Key); + var user = Context.Client.GetUserAsync(mostQuotedPerson.AsUlong()).Result ?? new UserPolyfillDto {Username = "Unknown User"}; + eb.AddInlineField(transContext.GetString("MostQuotesPerson"), user); + + var quotesByYear = _database.Quotes + .Where(row => row.GuildId == Context.Guild.Id.AsLong()) + .GroupBy(row => row.Time.Year) + .Select(row => new { year = row.Key, amount = row.Count()}); + foreach (var year in quotesByYear) + { + eb.AddInlineField(year.year.ToString(), year.amount); + } + + await ReplyAsync("", false, eb.Build()); + } + catch (Exception e) + { + await _errorHandler.HandleCommandException(e, Context); + } + } + private async Task GetLastMessageByUser(IUser user) { try diff --git a/Geekbot.net/Lib/Localization/Translations.yml b/Geekbot.net/Lib/Localization/Translations.yml index 5744741..a19a6f3 100644 --- a/Geekbot.net/Lib/Localization/Translations.yml +++ b/Geekbot.net/Lib/Localization/Translations.yml @@ -160,6 +160,15 @@ quote: NotFoundWithId: EN: "I couldn't find a quote with that ID :disappointed:" CHDE: "Ich chan kei quote finde mit därri ID :disappointed:" + QuoteStats: + EN: "Quote Stats" + CHDE: "Quote statistike" + TotalQuotes: + EN: "Total" + CHDE: "Total" + MostQuotesPerson: + EN: "Most quoted person" + CHDE: "Meist quoteti person" rank: InvalidType: EN: "Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`'"