diff --git a/KfChatDotNetBot/Commands/HowlggCommands.cs b/KfChatDotNetBot/Commands/HowlggCommands.cs index 45dc41b..c40ff5c 100644 --- a/KfChatDotNetBot/Commands/HowlggCommands.cs +++ b/KfChatDotNetBot/Commands/HowlggCommands.cs @@ -15,7 +15,7 @@ public class HowlggStatsCommand : ICommand 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, GroupCollection arguments, CancellationToken ctx) + 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); @@ -42,7 +42,7 @@ public class HowlggRecentBetCommand : ICommand 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, GroupCollection arguments, CancellationToken ctx) + 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 diff --git a/KfChatDotNetBot/Commands/ICommand.cs b/KfChatDotNetBot/Commands/ICommand.cs index 95801c1..d162f9e 100644 --- a/KfChatDotNetBot/Commands/ICommand.cs +++ b/KfChatDotNetBot/Commands/ICommand.cs @@ -11,5 +11,5 @@ internal interface ICommand bool HideFromHelp { get; } UserRight RequiredRight { get; } - Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx); + Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx); } \ No newline at end of file diff --git a/KfChatDotNetBot/Commands/JuiceCommand.cs b/KfChatDotNetBot/Commands/JuiceCommand.cs index aab634f..a31a9de 100644 --- a/KfChatDotNetBot/Commands/JuiceCommand.cs +++ b/KfChatDotNetBot/Commands/JuiceCommand.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; using Humanizer; +using Humanizer.Localisation; using KfChatDotNetBot.Models.DbModels; using KfChatDotNetBot.Settings; using KfChatDotNetWsClient.Models.Events; @@ -13,11 +14,12 @@ public class JuiceCommand : ICommand public string HelpText => "Get juice!"; public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, 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; + // Have to attach the entity because it is coming from another DB context + // https://stackoverflow.com/questions/52718652/ef-core-sqlite-sqlite-error-19-unique-constraint-failed + db.Users.Attach(user); var juicerSettings = await Helpers.GetMultipleValues([BuiltIn.Keys.JuiceAmount, BuiltIn.Keys.JuiceCooldown]); var cooldown = juicerSettings[BuiltIn.Keys.JuiceCooldown].ToType(); var amount = juicerSettings[BuiltIn.Keys.JuiceAmount].ToType(); @@ -41,6 +43,6 @@ public class JuiceCommand : ICommand return; } - botInstance.SendChatMessage($"You gotta wait {secondsRemaining.Humanize(precision: 2)} for another juicer", true); + botInstance.SendChatMessage($"You gotta wait {secondsRemaining.Humanize(precision: 2, minUnit: TimeUnit.Second)} for another juicer", true); } } \ No newline at end of file diff --git a/KfChatDotNetBot/Commands/MemeCommands.cs b/KfChatDotNetBot/Commands/MemeCommands.cs index 82885e5..a6ca3af 100644 --- a/KfChatDotNetBot/Commands/MemeCommands.cs +++ b/KfChatDotNetBot/Commands/MemeCommands.cs @@ -11,7 +11,7 @@ public class InsanityCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, 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"); @@ -25,7 +25,7 @@ public class TwistedCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, 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 🤯"); @@ -39,7 +39,7 @@ public class HelpMeCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) { // ReSharper disable once StringLiteralTypo botInstance.SendChatMessage("[img]https://i.postimg.cc/fTw6tGWZ/ineedmoneydumbfuck.png[/img]", true); @@ -53,7 +53,7 @@ public class SentCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) { // ReSharper disable once StringLiteralTypo botInstance.SendChatMessage("[img]https://i.ibb.co/GHq7hb1/4373-g-N5-HEH2-Hkc.png[/img]", true); diff --git a/KfChatDotNetBot/Commands/TimeCommand.cs b/KfChatDotNetBot/Commands/TimeCommand.cs index b0256c7..412baf4 100644 --- a/KfChatDotNetBot/Commands/TimeCommand.cs +++ b/KfChatDotNetBot/Commands/TimeCommand.cs @@ -11,7 +11,7 @@ public class TimeCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) { var bmt = new DateTimeOffset(TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time").BaseUtcOffset); diff --git a/KfChatDotNetBot/Commands/WhoisCommand.cs b/KfChatDotNetBot/Commands/WhoisCommand.cs index 78a0f94..f7fb671 100644 --- a/KfChatDotNetBot/Commands/WhoisCommand.cs +++ b/KfChatDotNetBot/Commands/WhoisCommand.cs @@ -15,16 +15,16 @@ public class WhoisCommand : ICommand public bool HideFromHelp => false; public UserRight RequiredRight => UserRight.Guest; - public async Task RunCommand(ChatBot botInstance, MessageModel message, GroupCollection arguments, CancellationToken ctx) + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, 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) + var queryUser = await db.Users.FirstOrDefaultAsync(u => u.KfUsername == query, cancellationToken: ctx); + if (queryUser == 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); + botInstance.SendChatMessage($"@{message.Author.Username}, {queryUser.KfUsername}'s ID is {queryUser.KfId}", true); } } \ No newline at end of file diff --git a/KfChatDotNetBot/Services/BotCommands.cs b/KfChatDotNetBot/Services/BotCommands.cs index 2bce4bd..a48940a 100644 --- a/KfChatDotNetBot/Services/BotCommands.cs +++ b/KfChatDotNetBot/Services/BotCommands.cs @@ -62,7 +62,7 @@ internal class BotCommands _bot.SendChatMessage($"@{message.Author.Username}, you do not have access to use this command. Your rank: {user.UserRight.Humanize()}; Required rank: {command.RequiredRight.Humanize()}", true); break; } - var task = Task.Run(() => command.RunCommand(_bot, message, match.Groups, _cancellationToken), _cancellationToken); + var task = Task.Run(() => command.RunCommand(_bot, message, user, match.Groups, _cancellationToken), _cancellationToken); _commandTasks.Add(task); } }