mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-03 13:02:03 -04:00
Added gmkasino commands
This commit is contained in:
@@ -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<Regex> Patterns => [
|
||||
new Regex(@"^admin gmkasino add (?<image>.+)$")
|
||||
];
|
||||
|
||||
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<List<string>>();
|
||||
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<Regex> Patterns => [
|
||||
new Regex(@"^admin gmkasino remove (?<image>.+)$")
|
||||
];
|
||||
|
||||
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<List<string>>();
|
||||
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<Regex> 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<List<string>>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<List<string>>();
|
||||
if (images == null) return;
|
||||
var random = new Random();
|
||||
var image = images[random.Next(images.Count)];
|
||||
botInstance.SendChatMessage($"[img]{image}[/img]", true);
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user