mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Untested Juice statistics command
This commit is contained in:
@@ -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<Regex> Patterns => [
|
||||
new Regex("^juice stats"),
|
||||
new Regex(@"^juice stats (?<top>\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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user