mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-04-30 03:22:04 -04:00
Added a generic interface for retrieving images. Where multiple images exist, it'll retrieve the least seen. If there are sufficient images to work with, it'll randomly pick from a subset of the least seen to make it less predictable what's going to show up.
This commit is contained in:
@@ -17,4 +17,5 @@ public class ApplicationDbContext : DbContext
|
||||
public DbSet<RainbetBetsDbModel> RainbetBets { get; set; }
|
||||
public DbSet<TwitchViewCountDbModel> TwitchViewCounts { get; set; }
|
||||
public DbSet<ChipsggBetDbModel> ChipsggBets { get; set; }
|
||||
public DbSet<ImageDbModel> Images { get; set; }
|
||||
}
|
||||
@@ -37,186 +37,6 @@ public class SetRoleCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
var newImage = arguments["image"].Value;
|
||||
if (images.Contains(newImage))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Image is already in the list", true);
|
||||
return;
|
||||
}
|
||||
|
||||
images.Add(newImage);
|
||||
await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGmKasinoImageRotation, images);
|
||||
await botInstance.SendChatMessageAsync("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)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
var targetImage = arguments["image"].Value;
|
||||
if (!images.Contains(targetImage))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Image is not in the list", true);
|
||||
return;
|
||||
}
|
||||
|
||||
images.Remove(targetImage);
|
||||
await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGmKasinoImageRotation, images);
|
||||
await botInstance.SendChatMessageAsync("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)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = "List of images:";
|
||||
var i = 0;
|
||||
foreach (var image in images)
|
||||
{
|
||||
i++;
|
||||
result += $"[br]{i}: {image}";
|
||||
}
|
||||
|
||||
await botInstance.SendChatMessagesAsync(result.FancySplitMessage(partSeparator: "[br]"), true);
|
||||
}
|
||||
}
|
||||
|
||||
public class GnKasinoAddCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin gnkasino add (?<image>.+)$")
|
||||
];
|
||||
|
||||
public string? HelpText => "Add an image to the gnkasino 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.BotGnKasinoImageRotation)).JsonDeserialize<List<string>>();
|
||||
if (images == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
var newImage = arguments["image"].Value;
|
||||
if (images.Contains(newImage))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Image is already in the list", true);
|
||||
return;
|
||||
}
|
||||
|
||||
images.Add(newImage);
|
||||
await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGnKasinoImageRotation, images);
|
||||
await botInstance.SendChatMessageAsync("Updated list of images", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class GnKasinoRemoveCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin gnkasino remove (?<image>.+)$")
|
||||
];
|
||||
|
||||
public string? HelpText => "Remove an image in the gnkasino 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.BotGnKasinoImageRotation)).JsonDeserialize<List<string>>();
|
||||
if (images == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
var targetImage = arguments["image"].Value;
|
||||
if (!images.Contains(targetImage))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Image is not in the list", true);
|
||||
return;
|
||||
}
|
||||
|
||||
images.Remove(targetImage);
|
||||
await Helpers.SetValueAsJsonObject(BuiltIn.Keys.BotGnKasinoImageRotation, images);
|
||||
await botInstance.SendChatMessageAsync("Updated list of images", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class GnKasinoListCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin gnkasino list$")
|
||||
];
|
||||
|
||||
public string? HelpText => "Dump out the list of images for gnkasino";
|
||||
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.BotGnKasinoImageRotation)).JsonDeserialize<List<string>>();
|
||||
if (images == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("Images list was null", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = "List of images:";
|
||||
var i = 0;
|
||||
foreach (var image in images)
|
||||
{
|
||||
i++;
|
||||
result += $"[br]{i}: {image}";
|
||||
}
|
||||
|
||||
await botInstance.SendChatMessagesAsync(result.FancySplitMessage(partSeparator: "[br]"), true);
|
||||
}
|
||||
}
|
||||
|
||||
public class ToggleLiveStatusAdminCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
|
||||
159
KfChatDotNetBot/Commands/ImageCommands.cs
Normal file
159
KfChatDotNetBot/Commands/ImageCommands.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using KfChatDotNetBot.Models.DbModels;
|
||||
using KfChatDotNetBot.Services;
|
||||
using KfChatDotNetBot.Settings;
|
||||
using KfChatDotNetWsClient.Models.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace KfChatDotNetBot.Commands;
|
||||
|
||||
public class AddImageCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin image (?<key>\w+) add (?<url>.+)$"),
|
||||
new Regex(@"^admin images (?<key>\w+) add (?<url>.+)$")
|
||||
];
|
||||
public string? HelpText => "Add an image to the image rotation specified";
|
||||
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)
|
||||
{
|
||||
await using var db = new ApplicationDbContext();
|
||||
var imageKeys = (await Helpers.GetValue(BuiltIn.Keys.BotImageAcceptableKeys)).JsonDeserialize<List<string>>();
|
||||
if (imageKeys == null) throw new InvalidOperationException($"{BuiltIn.Keys.BotImageAcceptableKeys} was null");
|
||||
var key = arguments["key"].Value;
|
||||
var url = arguments["url"].Value;
|
||||
if (!imageKeys.Contains(key))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync(
|
||||
$"Key you specified is not supported. Available keys are: {string.Join(' ', imageKeys)}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await db.Images.AnyAsync(i => i.Key == key && i.Url == url, ctx))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("This image already exists in the database with this key", true);
|
||||
return;
|
||||
}
|
||||
|
||||
await db.Images.AddAsync(new ImageDbModel { Key = key, Url = url, LastSeen = DateTimeOffset.MinValue }, ctx);
|
||||
await db.SaveChangesAsync(ctx);
|
||||
await botInstance.SendChatMessageAsync("Added image to database", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class RemoveImageCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin image (?<key>\w+) remove (?<url>.+)$"),
|
||||
new Regex(@"^admin images (?<key>\w+) remove (?<url>.+)$"),
|
||||
new Regex(@"^admin image (?<key>\w+) delete (?<url>.+)$"),
|
||||
new Regex(@"^admin images (?<key>\w+) delete (?<url>.+)$")
|
||||
];
|
||||
public string? HelpText => "Remove an image from the image rotation specified";
|
||||
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)
|
||||
{
|
||||
await using var db = new ApplicationDbContext();
|
||||
var imageKeys = (await Helpers.GetValue(BuiltIn.Keys.BotImageAcceptableKeys)).JsonDeserialize<List<string>>();
|
||||
if (imageKeys == null) throw new InvalidOperationException($"{BuiltIn.Keys.BotImageAcceptableKeys} was null");
|
||||
var key = arguments["key"].Value;
|
||||
var url = arguments["url"].Value;
|
||||
if (!imageKeys.Contains(key))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync(
|
||||
$"Key you specified is not supported. Available keys are: {string.Join(' ', imageKeys)}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var image = await db.Images.FirstOrDefaultAsync(i => i.Key == key && i.Url == url, ctx);
|
||||
if (image == null)
|
||||
{
|
||||
await botInstance.SendChatMessageAsync("This image isn't in the database with this key", true);
|
||||
return;
|
||||
}
|
||||
|
||||
db.Images.Remove(image);
|
||||
await db.SaveChangesAsync(ctx);
|
||||
await botInstance.SendChatMessageAsync("Removed image from database", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class ListImageCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^admin image (?<key>\w+) list$"),
|
||||
new Regex(@"^admin images (?<key>\w+) list$")
|
||||
];
|
||||
public string? HelpText => "Remove an image from the image rotation specified";
|
||||
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)
|
||||
{
|
||||
await using var db = new ApplicationDbContext();
|
||||
var imageKeys = (await Helpers.GetValue(BuiltIn.Keys.BotImageAcceptableKeys)).JsonDeserialize<List<string>>();
|
||||
if (imageKeys == null) throw new InvalidOperationException($"{BuiltIn.Keys.BotImageAcceptableKeys} was null");
|
||||
var key = arguments["key"].Value;
|
||||
if (!imageKeys.Contains(key))
|
||||
{
|
||||
await botInstance.SendChatMessageAsync(
|
||||
$"Key you specified is not supported. Available keys are: {string.Join(' ', imageKeys)}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var images = db.Images.Where(i => i.Key == key);
|
||||
var i = 0;
|
||||
var result = $"List of images for {key}:";
|
||||
foreach (var image in images)
|
||||
{
|
||||
i++;
|
||||
result += $"[br]{i}: {image.Url}";
|
||||
}
|
||||
|
||||
await botInstance.SendChatMessagesAsync(result.FancySplitMessage(partSeparator: "[br]"),
|
||||
bypassSeshDetect: true);
|
||||
}
|
||||
}
|
||||
|
||||
[AllowAdditionalMatches]
|
||||
public class GetRandomImage : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex(@"^(?<key>\w+)")
|
||||
];
|
||||
public string? HelpText => "Get a random image";
|
||||
public UserRight RequiredRight => UserRight.Loser;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments,
|
||||
CancellationToken ctx)
|
||||
{
|
||||
await using var db = new ApplicationDbContext();
|
||||
var key = arguments["key"].Value.ToLower();
|
||||
var images = db.Images.Where(i => i.Key == key);
|
||||
if (!await images.AnyAsync(ctx)) return;
|
||||
var divideBy = (await Helpers.GetValue(BuiltIn.Keys.BotImageRandomSliceDivideBy)).ToType<int>();
|
||||
var limit = 1;
|
||||
var count = await images.CountAsync(ctx);
|
||||
if (count > divideBy)
|
||||
{
|
||||
limit = count / divideBy;
|
||||
}
|
||||
|
||||
// EF with SQLite can't sort on dates as it's just TEXT
|
||||
var selection = (await images.ToListAsync(ctx)).OrderBy(i => i.LastSeen).Take(limit).ToList();
|
||||
// MaxValue is never returned by Next so you don't need to -1 for indexing
|
||||
var image = selection[new Random().Next(0, selection.Count)];
|
||||
image.LastSeen = DateTimeOffset.UtcNow;
|
||||
db.Images.Update(image);
|
||||
await db.SaveChangesAsync(ctx);
|
||||
await botInstance.SendChatMessageAsync($"[img]{image.Url}[/img]", true);
|
||||
}
|
||||
}
|
||||
@@ -36,64 +36,6 @@ public class TwistedCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
public class HelpMeCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [new Regex("^helpme")];
|
||||
public string? HelpText => "Somebody please help me";
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
await botInstance.SendChatMessageAsync("[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 UserRight RequiredRight => UserRight.Guest;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
await botInstance.SendChatMessageAsync("[img]https://i.ibb.co/GHq7hb1/4373-g-N5-HEH2-Hkc.png[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class GmKasinoCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [new Regex("^gmkasino")];
|
||||
public string? HelpText => "Good Morning Kasino";
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
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) return;
|
||||
var random = new Random();
|
||||
var image = images[random.Next(images.Count)];
|
||||
await botInstance.SendChatMessageAsync($"[img]{image}[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class GnKasinoCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [new Regex("^gnkasino")];
|
||||
public string? HelpText => "Good Night, Kasino";
|
||||
public UserRight RequiredRight => UserRight.Loser;
|
||||
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.BotGnKasinoImageRotation)).JsonDeserialize<List<string>>();
|
||||
if (images == null) return;
|
||||
var random = new Random();
|
||||
var image = images[random.Next(images.Count)];
|
||||
await botInstance.SendChatMessageAsync($"[img]{image}[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class CrackedCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
@@ -117,51 +59,6 @@ public class CrackedCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
public class WinmanjackCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^winmanjack")
|
||||
];
|
||||
public string? HelpText => "winmanjack.jpg";
|
||||
public UserRight RequiredRight => UserRight.Loser;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var image = await Helpers.GetValue(BuiltIn.Keys.WinmanjackImgUrl);
|
||||
await botInstance.SendChatMessageAsync($"[img]{image.Value}[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class PraygeCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^prayge")
|
||||
];
|
||||
public string? HelpText => "prayge.jpg";
|
||||
public UserRight RequiredRight => UserRight.Loser;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var image = await Helpers.GetValue(BuiltIn.Keys.BotPraygeImgUrl);
|
||||
await botInstance.SendChatMessageAsync($"[img]{image.Value}[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class CrackpipeCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^crackpipe")
|
||||
];
|
||||
public string? HelpText => "crackpipe.gif";
|
||||
public UserRight RequiredRight => UserRight.Loser;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
var image = await Helpers.GetValue(BuiltIn.Keys.BotCrackpipeImgUrl);
|
||||
await botInstance.SendChatMessageAsync($"[img]{image.Value}[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class CleanCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
@@ -183,7 +80,7 @@ public class CleanCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
public class RehbCommand : ICommand
|
||||
public class RehabCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [
|
||||
new Regex("^rehab")
|
||||
@@ -320,19 +217,6 @@ public class JailCommand : ICommand
|
||||
}
|
||||
}
|
||||
|
||||
public class BassmanJackCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [new Regex("^bassmanjack")];
|
||||
public string? HelpText => "Bassman image";
|
||||
public UserRight RequiredRight => UserRight.Guest;
|
||||
public TimeSpan Timeout => TimeSpan.FromSeconds(10);
|
||||
public async Task RunCommand(ChatBot botInstance, MessageModel message, UserDbModel user, GroupCollection arguments, CancellationToken ctx)
|
||||
{
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
await botInstance.SendChatMessageAsync("[img]https://i.postimg.cc/SRstzMQt/boss-soy-koi.gif[/img]", true);
|
||||
}
|
||||
}
|
||||
|
||||
public class LastStreamCommand : ICommand
|
||||
{
|
||||
public List<Regex> Patterns => [new Regex("^laststream")];
|
||||
|
||||
291
KfChatDotNetBot/Migrations/20250207015155_Images.Designer.cs
generated
Normal file
291
KfChatDotNetBot/Migrations/20250207015155_Images.Designer.cs
generated
Normal file
@@ -0,0 +1,291 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using KfChatDotNetBot;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace KfChatDotNetBot.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20250207015155_Images")]
|
||||
partial class Images
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "9.0.1");
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.ChipsggBetDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("Amount")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("BetId")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTimeOffset>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Currency")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("CurrencyPrice")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("GameTitle")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("Multiplier")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTimeOffset>("Updated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("Win")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("Winnings")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ChipsggBets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.HowlggBetsDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("Bet")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("BetId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTimeOffset>("Date")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Game")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<long>("GameId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("Profit")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("HowlggBets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.ImageDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeen")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.JuicerDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<float>("Amount")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTimeOffset>("JuicedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Juicers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.RainbetBetsDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("BetId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTimeOffset>("BetSeenAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GameName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("Multiplier")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<float>("Payout")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("PublicId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("RainbetUserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTimeOffset>("UpdatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<float>("Value")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("RainbetBets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.SettingDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CacheDuration")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("Default")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsSecret")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Regex")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("ValueType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Settings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.TwitchViewCountDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("ServerTime")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Topic")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Viewers")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("TwitchViewCounts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.UserDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("Ignored")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("KfId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("KfUsername")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("UserRight")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.JuicerDbModel", b =>
|
||||
{
|
||||
b.HasOne("KfChatDotNetBot.Models.DbModels.UserDbModel", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
48
KfChatDotNetBot/Migrations/20250207015155_Images.cs
Normal file
48
KfChatDotNetBot/Migrations/20250207015155_Images.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace KfChatDotNetBot.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Images : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ValueType",
|
||||
table: "Settings",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Images",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Key = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Url = table.Column<string>(type: "TEXT", nullable: false),
|
||||
LastSeen = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Images", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Images");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ValueType",
|
||||
table: "Settings");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,28 @@ namespace KfChatDotNetBot.Migrations
|
||||
b.ToTable("HowlggBets");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.ImageDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTimeOffset>("LastSeen")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Url")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("KfChatDotNetBot.Models.DbModels.JuicerDbModel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
||||
9
KfChatDotNetBot/Models/DbModels/ImageDbModel.cs
Normal file
9
KfChatDotNetBot/Models/DbModels/ImageDbModel.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace KfChatDotNetBot.Models.DbModels;
|
||||
|
||||
public class ImageDbModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public required string Key { get; set; }
|
||||
public required string Url { get; set; }
|
||||
public required DateTimeOffset LastSeen { get; set; }
|
||||
}
|
||||
@@ -17,6 +17,8 @@ namespace KfChatDotNetBot
|
||||
await BuiltIn.SyncSettingsWithDb();
|
||||
logger.Info("Migrating settings from config.json (if needed)");
|
||||
await BuiltIn.MigrateJsonSettingsToDb();
|
||||
logger.Info("Migrating images over to the new system");
|
||||
await BuiltIn.MigrateImages();
|
||||
logger.Info("Handing over to bot now");
|
||||
Console.OutputEncoding = Encoding.UTF8;
|
||||
new ChatBot();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Json;
|
||||
using KfChatDotNetBot.Models;
|
||||
using KfChatDotNetBot.Models.DbModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NLog;
|
||||
|
||||
namespace KfChatDotNetBot.Settings;
|
||||
@@ -95,6 +96,89 @@ public static class BuiltIn
|
||||
|
||||
logger.Info("File renamed");
|
||||
}
|
||||
|
||||
public static async Task MigrateImages()
|
||||
{
|
||||
var logger = LogManager.GetCurrentClassLogger();
|
||||
await using var db = new ApplicationDbContext();
|
||||
logger.Info("Migrating images to the database table");
|
||||
if (await db.Images.AnyAsync())
|
||||
{
|
||||
logger.Info("Not continuing as there's already images in the database");
|
||||
return;
|
||||
}
|
||||
|
||||
var imagesToMigrate = await Helpers.GetMultipleValues([
|
||||
Keys.BotGmKasinoImageRotation, Keys.BotGnKasinoImageRotation, Keys.WinmanjackImgUrl, Keys.BotPraygeImgUrl,
|
||||
Keys.BotCrackpipeImgUrl
|
||||
]);
|
||||
|
||||
logger.Info("Migrating gmkasino images");
|
||||
foreach (var image in imagesToMigrate[Keys.BotGmKasinoImageRotation].JsonDeserialize<List<string>>() ?? [])
|
||||
{
|
||||
await db.Images.AddAsync(new ImageDbModel {Key = "gmkasino", LastSeen = DateTimeOffset.UtcNow, Url = image});
|
||||
}
|
||||
|
||||
logger.Info("Migrating gnkasino images");
|
||||
foreach (var image in imagesToMigrate[Keys.BotGnKasinoImageRotation].JsonDeserialize<List<string>>() ?? [])
|
||||
{
|
||||
await db.Images.AddAsync(new ImageDbModel {Key = "gnkasino", LastSeen = DateTimeOffset.UtcNow, Url = image});
|
||||
}
|
||||
|
||||
if (imagesToMigrate[Keys.WinmanjackImgUrl].Value != null)
|
||||
{
|
||||
logger.Info("Migrating winmanjack");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "winmanjack", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = imagesToMigrate[Keys.WinmanjackImgUrl].Value!
|
||||
});
|
||||
}
|
||||
|
||||
if (imagesToMigrate[Keys.BotPraygeImgUrl].Value != null)
|
||||
{
|
||||
logger.Info("Migrating prayge");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "prayge", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = imagesToMigrate[Keys.BotPraygeImgUrl].Value!
|
||||
});
|
||||
}
|
||||
|
||||
if (imagesToMigrate[Keys.BotCrackpipeImgUrl].Value != null)
|
||||
{
|
||||
logger.Info("Migrating crackpipe");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "crackpipe", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = imagesToMigrate[Keys.BotCrackpipeImgUrl].Value!
|
||||
});
|
||||
}
|
||||
|
||||
logger.Info("Adding bassmanjack");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "bassmanjack", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = "https://i.postimg.cc/SRstzMQt/boss-soy-koi.gif"
|
||||
});
|
||||
|
||||
logger.Info("Adding sent");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "sent", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = "https://i.ibb.co/GHq7hb1/4373-g-N5-HEH2-Hkc.png"
|
||||
});
|
||||
|
||||
logger.Info("Adding helpme");
|
||||
await db.Images.AddAsync(new ImageDbModel
|
||||
{
|
||||
Key = "helpme", LastSeen = DateTimeOffset.UtcNow,
|
||||
Url = "https://i.postimg.cc/fTw6tGWZ/ineedmoneydumbfuck.png"
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
logger.Info("Image migration complete");
|
||||
}
|
||||
|
||||
public static List<BuiltInSettingsModel> BuiltInSettings =
|
||||
[
|
||||
@@ -715,6 +799,16 @@ public static class BuiltIn
|
||||
ValueType = SettingValueType.Boolean
|
||||
},
|
||||
new BuiltInSettingsModel
|
||||
{
|
||||
Key = Keys.BotImageAcceptableKeys,
|
||||
Regex = ".+",
|
||||
Description = "List of valid keys for the image rotation feature",
|
||||
Default = "[\"gmkasino\", \"gnkasino\", \"winmanjack\", \"prayge\", \"crackpipe\", \"bassmanjack\", \"sent\", \"helpme\"]",
|
||||
IsSecret = false,
|
||||
CacheDuration = TimeSpan.FromHours(1),
|
||||
ValueType = SettingValueType.Array
|
||||
},
|
||||
new BuiltInSettingsModel
|
||||
{
|
||||
Key = Keys.BotToyStoryImage,
|
||||
Regex = ".+",
|
||||
@@ -723,6 +817,19 @@ public static class BuiltIn
|
||||
IsSecret = false,
|
||||
CacheDuration = TimeSpan.FromHours(1),
|
||||
ValueType = SettingValueType.Text
|
||||
},
|
||||
new BuiltInSettingsModel
|
||||
{
|
||||
Key = Keys.BotImageRandomSliceDivideBy,
|
||||
Regex = @"\d+",
|
||||
Description = "What value to divide the image count by for determining how many images to randomly choose from. " +
|
||||
"e.g. a value of 10 on 50 images means the 5 least seen images are chosen from randomly. " +
|
||||
"If the count of images is =< this value, it'll just grab the oldest image. " +
|
||||
"Fractions will be rounded, so a value of 5 with 7 images will round down and take the oldest image.",
|
||||
Default = "5",
|
||||
IsSecret = false,
|
||||
CacheDuration = TimeSpan.FromHours(1),
|
||||
ValueType = SettingValueType.Text
|
||||
}
|
||||
];
|
||||
|
||||
@@ -787,6 +894,8 @@ public static class BuiltIn
|
||||
public static string HowlggEnabled = "Howlgg.Enabled";
|
||||
public static string ChipsggEnabled = "Chipsgg.Enabled";
|
||||
public static string RainbetEnabled = "Rainbet.Enabled";
|
||||
public static string BotImageAcceptableKeys = "Bot.Image.AcceptableKeys";
|
||||
public static string BotToyStoryImage = "Bot.ToyStoryImage";
|
||||
public static string BotImageRandomSliceDivideBy = "Bot.Image.RandomSliceDivideBy";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user