From e53150f7907c633410198e212d54dffaa2a2ef65 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:43:32 +0800 Subject: [PATCH] Untested Juice statistics command --- KfChatDotNetBot/Commands/JuiceCommand.cs | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/KfChatDotNetBot/Commands/JuiceCommand.cs b/KfChatDotNetBot/Commands/JuiceCommand.cs index a31a9de..b536018 100644 --- a/KfChatDotNetBot/Commands/JuiceCommand.cs +++ b/KfChatDotNetBot/Commands/JuiceCommand.cs @@ -45,4 +45,51 @@ public class JuiceCommand : ICommand botInstance.SendChatMessage($"You gotta wait {secondsRemaining.Humanize(precision: 2, minUnit: TimeUnit.Second)} for another juicer", true); } +} + +public class JuiceStatsCommand : ICommand +{ + public List Patterns => [ + new Regex("^juice stats"), + new Regex(@"^juice stats (?\d+)$") + ]; + public string HelpText => "Get juice stats!"; + public bool HideFromHelp => false; + public UserRight RequiredRight => UserRight.Guest; + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + int top; + if (arguments.TryGetValue("top", out var argument)) + { + top = Convert.ToInt32(argument.Value); + if (top > 10) + { + botInstance.SendChatMessage($"'{top}' exceeds the limit on the amount of leeches you can return", true); + return; + } + } + else + { + top = 3; + } + + await using var db = new ApplicationDbContext(); + var topLeeches = await db.Juicers.GroupBy(u => u.User).Select(l => new + { + User = l.Key.KfUsername, + Amount = l.Sum(a => a.Amount) + }).OrderByDescending(x => x.Amount).Take(top).ToListAsync(ctx); + var sum = await db.Juicers.SumAsync(s => s.Amount, cancellationToken: ctx); + var count = await db.Juicers.CountAsync(ctx); + var totalUsers = await db.Juicers.Select(j => j.User).Distinct().CountAsync(ctx); + var msg = $"Total Juicers: {count:N0}; Total Handed Out: KKK{sum:C}; Total Users Juiced: {totalUsers:N0}; Average Juicers / User: {count / totalUsers:N}[br]Top Leeches: "; + var i = 0; + foreach (var leech in topLeeches) + { + i++; + msg += $"{i}. {leech.User} with KKK{leech.Amount:C} juiced; "; + } + + botInstance.SendChatMessage(msg, true); + } } \ No newline at end of file