using System.Text.Json; using HermesSocketLibrary.db; using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Store.Internal; namespace HermesSocketServer.Store { public class ActionStore : AutoSavedStore { private readonly string _userId; private readonly Database _database; private readonly Serilog.ILogger _logger; public ActionStore(string userId, DatabaseTable table, Database database, Serilog.ILogger logger) : base(table, database, logger) { _userId = userId; _database = database; _logger = logger; } public override async Task Load() { var data = new Dictionary() { { "user", _userId } }; string sql = $"SELECT name, type, data FROM \"Action\" WHERE \"userId\" = @user"; await _database.Execute(sql, data, (reader) => { var name = reader.GetString(0); _store.Add(name.ToString(), new RedeemableAction() { UserId = _userId, Name = name, Type = reader.GetString(1), Data = JsonSerializer.Deserialize>(reader.GetString(2))! }); }); _logger.Information($"Loaded {_store.Count} TTS chatter voices from database."); } protected override void OnInitialAdd(string key, RedeemableAction value) { } protected override void OnInitialModify(string key, RedeemableAction value) { } protected override void OnInitialRemove(string key) { } } }