using HermesSocketLibrary.db; using ILogger = Serilog.ILogger; namespace HermesSocketServer.Requests { public class UpdateTTSVoiceState : IRequest { public string Name => "update_tts_voice_state"; public string[] RequiredKeys => ["voice", "state"]; private Database _database; private ILogger _logger; public UpdateTTSVoiceState(Database database, ILogger logger) { _database = database; _logger = logger; } public async Task Grant(string sender, IDictionary? data) { data["voice"] = data["voice"].ToString(); data["state"] = data["state"].ToString() == "True"; data["user"] = sender; string sql = "INSERT INTO \"TtsVoiceState\" (\"userId\", \"ttsVoiceId\", state) VALUES (@user, @voice, @state) ON CONFLICT (\"userId\", \"ttsVoiceId\") DO UPDATE SET state = @state"; var result = await _database.Execute(sql, data); _logger.Information($"Updated voice's [voice id: {data["voice"]}] state [new state: {data["state"]}][channel: {data["user"]}]"); if (result > 0) return RequestResult.Successful(null); return RequestResult.Failed("Something went wrong when updating the database."); } } }