mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Added commands for getting Rainbet betting info
This commit is contained in:
61
KfChatDotNetBot/Commands/RainbetCommands.cs
Normal file
61
KfChatDotNetBot/Commands/RainbetCommands.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Humanizer;
|
||||
using KfChatDotNetBot.Models.DbModels;
|
||||
using KfChatDotNetBot.Settings;
|
||||
using KfChatDotNetWsClient.Models.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace KfChatDotNetBot.Commands;
|
||||
|
||||
public class RainbetStatsCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^rainbet stats (?<window>\d+)$")
|
||||
];
|
||||
public string HelpText => "Get betting statistics in the given window";
|
||||
public bool HideFromHelp => false;
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var window = Convert.ToInt32(arguments["window"].Value);
|
||||
var start = DateTimeOffset.UtcNow.AddHours(-window);
|
||||
await using var db = new ApplicationDbContext();
|
||||
// EF SQLite doesn't support filtering on dates :(
|
||||
var bets = (await db.RainbetBets.ToListAsync(ctx)).Where(b => b.UpdatedAt.UtcDateTime > start).ToList();
|
||||
if (bets.Count == 0)
|
||||
{
|
||||
botInstance.SendChatMessage("No bets captured during this window", true);
|
||||
return;
|
||||
}
|
||||
var output = $"Rainbet stats for the last {window} hours (as seen on the bet feed):[br]" +
|
||||
$"Bets: {bets.Count:N0}; Payout: ${bets.Sum(b => b.Payout)}; Wagered: {bets.Sum(b => b.Value):C}";
|
||||
botInstance.SendChatMessage(output, true);
|
||||
}
|
||||
}
|
||||
|
||||
public class RainbetRecentBetCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^rainbet recent$")
|
||||
];
|
||||
public string HelpText => "Get the most recent 3 bets";
|
||||
public bool HideFromHelp => false;
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var settings = await Helpers.GetMultipleValues([
|
||||
BuiltIn.Keys.KiwiFarmsGreenColor, BuiltIn.Keys.KiwiFarmsRedColor, BuiltIn.Keys.HowlggDivisionAmount
|
||||
]);
|
||||
await using var db = new ApplicationDbContext();
|
||||
// EF SQLite doesn't support filtering on dates :(
|
||||
var bets = (await db.RainbetBets.ToListAsync(ctx)).OrderByDescending(j => j.UpdatedAt).Take(3).ToList();
|
||||
var output = "Most recent 3 bets on Rainbet (as seen on the bet feed):";
|
||||
foreach (var bet in bets)
|
||||
{
|
||||
var color = settings[BuiltIn.Keys.KiwiFarmsGreenColor].Value;
|
||||
if (bet.Payout < bet.Value) color = settings[BuiltIn.Keys.KiwiFarmsRedColor].Value;
|
||||
output += $"[br]Value: {bet.Value:C}; Payout: [color={color}]{bet.Payout:C}[/color]; Multi: {bet.Multiplier:N2}x; Game: {bet.GameName}; {(DateTimeOffset.UtcNow - bet.UpdatedAt).Humanize(precision: 1)} ago";
|
||||
}
|
||||
botInstance.SendChatMessage(output, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user