From 2fb3d1f87b02857d600f7b95e77f77307b6c4c2d Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Thu, 5 Sep 2024 21:31:13 +0800 Subject: [PATCH] Added gmkasino commands --- KfChatDotNetBot/Commands/AdminCommands.cs | 91 +++++++++++++++++++++++ KfChatDotNetBot/Commands/MemeCommands.cs | 8 +- KfChatDotNetBot/Settings/BuiltIn.cs | 11 +++ 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/KfChatDotNetBot/Commands/AdminCommands.cs b/KfChatDotNetBot/Commands/AdminCommands.cs index d7df7e9..e047901 100644 --- a/KfChatDotNetBot/Commands/AdminCommands.cs +++ b/KfChatDotNetBot/Commands/AdminCommands.cs @@ -1,6 +1,7 @@ using System.Text.RegularExpressions; using Humanizer; using KfChatDotNetBot.Models.DbModels; +using KfChatDotNetBot.Settings; using KfChatDotNetWsClient.Models.Events; using Microsoft.EntityFrameworkCore; @@ -32,4 +33,94 @@ public class SetRightCommand : ICommand await db.SaveChangesAsync(ctx); botInstance.SendChatMessage($"@{message.Author.Username}, {targetUser.KfUsername}'s right set to {right.Humanize()}", true); } +} + +public class GmKasinoAddCommand : ICommand +{ + public List Patterns => [ + new Regex(@"^admin gmkasino add (?.+)$") + ]; + + public string? HelpText => "Add an image to the gmkasino image list"; + public UserRight RequiredRight => UserRight.TrueAndHonest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + var images = (await Helpers.GetValue(BuiltIn.Keys.BotGmKasinoImageRotation)).JsonDeserialize>(); + if (images == null) + { + botInstance.SendChatMessage("Images list was null", true); + return; + } + var newImage = arguments["image"].Value; + if (images.Contains(newImage)) + { + botInstance.SendChatMessage("Image is already in the list", true); + return; + } + + images.Add(newImage); + await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGmKasinoImageRotation, images); + botInstance.SendChatMessage("Updated list of images", true); + } +} + +public class GmKasinoRemoveCommand : ICommand +{ + public List Patterns => [ + new Regex(@"^admin gmkasino remove (?.+)$") + ]; + + public string? HelpText => "Remove an image in the gmkasino image list"; + public UserRight RequiredRight => UserRight.TrueAndHonest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + var images = (await Helpers.GetValue(BuiltIn.Keys.BotGmKasinoImageRotation)).JsonDeserialize>(); + if (images == null) + { + botInstance.SendChatMessage("Images list was null", true); + return; + } + var targetImage = arguments["image"].Value; + if (!images.Contains(targetImage)) + { + botInstance.SendChatMessage("Image is not in the list", true); + return; + } + + images.Remove(targetImage); + await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGmKasinoImageRotation, images); + botInstance.SendChatMessage("Updated list of images", true); + } +} + +public class GmKasinoListCommand : ICommand +{ + public List Patterns => [ + new Regex(@"^admin gmkasino list$") + ]; + + public string? HelpText => "Dump out the list of images for gmkasino"; + public UserRight RequiredRight => UserRight.TrueAndHonest; + public TimeSpan Timeout => TimeSpan.FromSeconds(10); + public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx) + { + var images = (await Helpers.GetValue(BuiltIn.Keys.BotGmKasinoImageRotation)).JsonDeserialize>(); + if (images == null) + { + botInstance.SendChatMessage("Images list was null", true); + return; + } + + var result = "List of images:"; + var i = 0; + foreach (var image in images) + { + i++; + result += $"[br]{i}: {image}"; + } + + botInstance.SendChatMessage(result, true); + } } \ No newline at end of file diff --git a/KfChatDotNetBot/Commands/MemeCommands.cs b/KfChatDotNetBot/Commands/MemeCommands.cs index fe2ce96..3adebc1 100644 --- a/KfChatDotNetBot/Commands/MemeCommands.cs +++ b/KfChatDotNetBot/Commands/MemeCommands.cs @@ -1,5 +1,6 @@ using System.Text.RegularExpressions; using KfChatDotNetBot.Models.DbModels; +using KfChatDotNetBot.Settings; using KfChatDotNetWsClient.Models.Events; namespace KfChatDotNetBot.Commands; @@ -64,7 +65,10 @@ public class GmKasinoCommand : ICommand public TimeSpan Timeout => TimeSpan.FromSeconds(10); 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/QMzBRmH7/hiiiii.gif[/img]", true); + var images = (await Helpers.GetValue(BuiltIn.Keys.BotGmKasinoImageRotation)).JsonDeserialize>(); + if (images == null) return; + var random = new Random(); + var image = images[random.Next(images.Count)]; + botInstance.SendChatMessage($"[img]{image}[/img]", true); } } \ No newline at end of file diff --git a/KfChatDotNetBot/Settings/BuiltIn.cs b/KfChatDotNetBot/Settings/BuiltIn.cs index 7a286c1..b2aa6a0 100644 --- a/KfChatDotNetBot/Settings/BuiltIn.cs +++ b/KfChatDotNetBot/Settings/BuiltIn.cs @@ -439,6 +439,16 @@ public static class BuiltIn Default = "{}", IsSecret = true, CacheDuration = TimeSpan.FromHours(1) + }, + new BuiltInSettingsModel + { + Key = Keys.BotGmKasinoImageRotation, + Regex = ".+", + Description = "Rotation of images for the !gmkasino command", + // It's a JSON array + Default = "[\"https://i.postimg.cc/QMzBRmH7/hiiiii.gif\"]", + IsSecret = false, + CacheDuration = TimeSpan.FromHours(1) } ]; @@ -480,5 +490,6 @@ public static class BuiltIn public static string ChipsggBmjUsername = "Chipsgg.BmjUsername"; public static string RestreamUrl = "RestreamUrl"; public static string KiwiFarmsCookies = "KiwiFarms.Cookies"; + public static string BotGmKasinoImageRotation = "Bot.GmKasinoImageRotation"; } } \ No newline at end of file