using HermesSocketLibrary.db; using HermesSocketLibrary.Requests.Messages; using HermesSocketServer.Store.Internal; using HermesSocketServer.Validators; namespace HermesSocketServer.Store { public class VoiceStateStore : AutoSavedStore { private readonly string _userId; private readonly VoiceIdValidator _idValidator; private readonly Database _database; private readonly Serilog.ILogger _logger; public VoiceStateStore(string userId, VoiceIdValidator voiceIdValidator, DatabaseTable table, Database database, Serilog.ILogger logger) : base(table, database, logger) { _userId = userId; _idValidator = voiceIdValidator; _database = database; _logger = logger; } public override async Task Load() { var data = new Dictionary() { { "user", _userId } }; string sql = "SELECT \"ttsVoiceId\", state FROM \"TtsVoiceState\" WHERE \"userId\" = @user"; await _database.Execute(sql, data, (reader) => { string id = reader.GetString(0); _store.Add(id, new TTSVoiceState() { Id = id, Enabled = reader.GetBoolean(1), UserId = _userId, }); }); _logger.Information($"Loaded {_store.Count} TTS voice states from database."); } protected override void OnInitialAdd(string key, TTSVoiceState value) { _idValidator.Check(value.Id); } protected override void OnInitialModify(string key, TTSVoiceState value) { } protected override void OnInitialRemove(string key) { } } }