Add !quote stats (v1)
This commit is contained in:
parent
c031d2bfb4
commit
5cf1248bf0
2 changed files with 56 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
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<IMessage> GetLastMessageByUser(IUser user)
|
private async Task<IMessage> GetLastMessageByUser(IUser user)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -160,6 +160,15 @@ quote:
|
||||||
NotFoundWithId:
|
NotFoundWithId:
|
||||||
EN: "I couldn't find a quote with that ID :disappointed:"
|
EN: "I couldn't find a quote with that ID :disappointed:"
|
||||||
CHDE: "Ich chan kei quote finde mit därri 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:
|
rank:
|
||||||
InvalidType:
|
InvalidType:
|
||||||
EN: "Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`'"
|
EN: "Valid types are '`messages`' '`karma`', '`rolls`' and '`cookies`'"
|
||||||
|
|
Loading…
Reference in a new issue