Files
KfChatDotNet/KfChatDotNetBot/Program.cs
barelyprofessional d71819819d Updated the tagging code from cohle
- Uses a List<string> as the underlying type which EF Core will serialize as JSON. Since SQLite doesn't have any native JSON features, it gets stored as TEXT
- Got rid of the alternate pathway used for selecting an image so it always has a degree of randomness assuming enough images were returned
- Simplified some of the existing Regex and removed the non capturing groups as they're cancerous
- Added/removed images will be spoilered.
- Added a metadata property for images. This is a JSON object that EF Core will serialize/deserialize for you and presently contains the user ID of whoever added the image as well as when it was added. Can be easily extended with no migration needed. Will be null for existing images.
- Added a migration process for moving Tags to TagList for fishtank
2026-05-10 15:30:54 -05:00

73 lines
2.9 KiB
C#

/*
KfChatDotNetBot - Sneedchat bot for the Keno Kasino
Copyright (C) 2025 barelyprofessional
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The above copyright notice, this permission notice and the word "NIGGER"
shall be included in all copies or substantial portions of the Software.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System.Text;
using KfChatDotNetBot.Migrations;
using KfChatDotNetBot.Services;
using KfChatDotNetBot.Settings;
using Microsoft.EntityFrameworkCore;
using NLog;
namespace KfChatDotNetBot
{
public class Program
{
static async Task Main(string[] args)
{
var logger = LogManager.GetCurrentClassLogger();
logger.Info("Opening up DB to perform a migration (if one is needed)");
await using var db = new ApplicationDbContext();
await db.Database.MigrateAsync();
logger.Info("Migration done. Syncing builtin settings keys");
await BuiltIn.SyncSettingsWithDb();
logger.Info("Migrating settings from config.json (if needed)");
await BuiltIn.MigrateJsonSettingsToDb();
logger.Info("Attempting to grab the Redis connection multiplexer so it's built");
try
{
_ = Redis.Multiplexer;
}
catch (Exception e)
{
logger.Error("Caught an error when attempting to grab the Redis multiplexer");
logger.Error(e);
}
if (await db.Images.AnyAsync())
{
logger.Info("Checking to see if we need to migrate Tags to TagList");
#pragma warning disable CS0618 // Type or member is obsolete
var scope = (await db.Images.Where(i => i.Tags != null).ToListAsync()).Where(i => i.TagList.Count == 0).ToList();
foreach (var item in scope)
{
// Ignoring the null as my query literally filters for != null
item.TagList = item.Tags!.Split(" ").ToList();
#pragma warning restore CS0618 // Type or member is obsolete
logger.Info($"Migrated tags for image {item.Id}");
}
await db.SaveChangesAsync();
}
logger.Info("Handing over to bot now");
Console.OutputEncoding = Encoding.UTF8;
_ = new ChatBot();
}
}
}