Big update introducing ghetto command interface, settings, database and howl.gg bet feed scraping

This commit is contained in:
barelyprofessional
2024-07-18 01:37:15 +10:00
parent 936bf743a5
commit d61a171e54
46 changed files with 2198 additions and 218 deletions

View File

@@ -0,0 +1,15 @@
using System.Text.RegularExpressions;
using KfChatDotNetKickBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetKickBot.Commands;
internal interface ICommand
{
List<Regex> Patterns { get; }
string HelpText { get; }
bool HideFromHelp { get; }
UserRight RequiredRight { get; }
Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx);
}

View File

@@ -0,0 +1,46 @@
using System.Text.RegularExpressions;
using Humanizer;
using KfChatDotNetKickBot.Models.DbModels;
using KfChatDotNetKickBot.Settings;
using KfChatDotNetWsClient.Models.Events;
using Microsoft.EntityFrameworkCore;
namespace KfChatDotNetKickBot.Commands;
public class JuiceCommand : ICommand
{
public List<Regex> Patterns { get; } = [new Regex("^juiceme$")];
public string HelpText => "Get juice!";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
await using var db = new ApplicationDbContext();
var user = await db.Users.FirstOrDefaultAsync(u => u.KfId == message.Author.Id, cancellationToken: ctx);
if (user == null) return;
var juicerSettings = await Helpers.GetMultipleValues([BuiltIn.Keys.JuiceAmount, BuiltIn.Keys.JuiceCooldown]);
var cooldown = juicerSettings[BuiltIn.Keys.JuiceCooldown].ToType<int>();
var amount = juicerSettings[BuiltIn.Keys.JuiceAmount].ToType<int>();
var lastJuicer = (await db.Juicers.Where(j => j.User == user).ToListAsync(ctx)).OrderByDescending(j => j.JuicedAt).Take(1).ToList();
if (lastJuicer.Count == 0)
{
botInstance.SendChatMessage($"!juice {message.Author.Id} {amount}", true);
await db.Juicers.AddAsync(new JuicerDbModel
{ Amount = amount, User = user, JuicedAt = DateTimeOffset.UtcNow }, ctx);
await db.SaveChangesAsync(ctx);
return;
}
var secondsRemaining = lastJuicer[0].JuicedAt.AddSeconds(cooldown) - DateTimeOffset.UtcNow;
if (secondsRemaining.TotalSeconds <= 0)
{
botInstance.SendChatMessage($"!juice {message.Author.Id} {amount}", true);
await db.Juicers.AddAsync(new JuicerDbModel
{ Amount = amount, User = user, JuicedAt = DateTimeOffset.UtcNow }, ctx);
await db.SaveChangesAsync(ctx);
return;
}
botInstance.SendChatMessage($"You gotta wait {secondsRemaining.Humanize(precision: 2)} for another juicer", true);
}
}

View File

@@ -0,0 +1,61 @@
using System.Text.RegularExpressions;
using KfChatDotNetKickBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetKickBot.Commands;
public class InsanityCommand : ICommand
{
public List<Regex> Patterns => [new Regex("^insanity")];
public string HelpText => "Insanity";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
// ReSharper disable once StringLiteralTypo
botInstance.SendChatMessage("definition of insanity = doing the same thing over and over and over excecting a different result, and heres my dumbass trying to get rich every day and losing everythign i fucking touch every fucking time FUCK this bullshit FUCK MY LIEFdefinition of insanity = doing the same thing over and over and over excecting a different result, and heres my dumbass trying to get rich every day and losing everythign i fucking touch every fucking time FUCK this bullshit FUCK MY LIEF");
}
}
public class TwistedCommand : ICommand
{
public List<Regex> Patterns => [new Regex("^twisted")];
public string HelpText => "Get it twisted";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
// ReSharper disable once StringLiteralTypo
botInstance.SendChatMessage("🦍 🗣 GET IT TWISTED 🌪 , GAMBLE ✅ . PLEASE START GAMBLING 👍 . GAMBLING IS AN INVESTMENT 🎰 AND AN INVESTMENT ONLY 👍 . YOU WILL PROFIT 💰 , YOU WILL WIN ❗ . YOU WILL DO ALL OF THAT 💯 , YOU UNDERSTAND ⁉ YOU WILL BECOME A BILLIONAIRE 💵 📈 AND REBUILD YOUR FUCKING LIFE 🤯");
}
}
public class HelpMeCommand : ICommand
{
public List<Regex> Patterns => [new Regex("^helpme")];
public string HelpText => "Somebody please help me";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
// ReSharper disable once StringLiteralTypo
botInstance.SendChatMessage("[img]https://i.postimg.cc/fTw6tGWZ/ineedmoneydumbfuck.png[/img]", true);
}
}
public class SentCommand : ICommand
{
public List<Regex> Patterns => [new Regex("^sent$")];
public string HelpText => "Sent love";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
// ReSharper disable once StringLiteralTypo
botInstance.SendChatMessage("[img]https://i.ibb.co/GHq7hb1/4373-g-N5-HEH2-Hkc.png[/img]", true);
}
}

View File

@@ -0,0 +1,20 @@
using System.Text.RegularExpressions;
using KfChatDotNetKickBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
namespace KfChatDotNetKickBot.Commands;
public class TimeCommand : ICommand
{
public List<Regex> Patterns => [new Regex("^time")];
public string HelpText => "Get current time in BMT";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
var bmt = new DateTimeOffset(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").BaseUtcOffset);
botInstance.SendChatMessage($"It's currently {bmt:h:mm:ss tt} BMT");
}
}

View File

@@ -0,0 +1,30 @@
using System.Text.RegularExpressions;
using KfChatDotNetKickBot.Models.DbModels;
using KfChatDotNetWsClient.Models.Events;
using Microsoft.EntityFrameworkCore;
namespace KfChatDotNetKickBot.Commands;
public class WhoisCommand : ICommand
{
public List<Regex> Patterns => [
new Regex("^whois (?<user>.+)")
];
public string HelpText => "Lookup user IDs by username";
public bool HideFromHelp => false;
public UserRight RequiredRight => UserRight.Guest;
public async Task RunCommand(KickBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx)
{
await using var db = new ApplicationDbContext();
var query = arguments["user"].Value.TrimStart('@').TrimEnd(',').TrimEnd();
var user = await db.Users.FirstOrDefaultAsync(u => u.KfUsername == query, cancellationToken: ctx);
if (user == null)
{
botInstance.SendChatMessage($"Requested user '{query}' does not exist. (Note this is case-sensitive)", true);
return;
}
botInstance.SendChatMessage($"@{message.Author.Username}, {user.KfUsername}'s ID is {user.KfId}", true);
}
}