hermes-server/Requests/GetEnabledTTSVoices.cs

33 lines
1.2 KiB
C#
Raw Normal View History

using HermesSocketLibrary.db;
2024-12-27 23:31:36 +00:00
using HermesSocketServer.Models;
using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests
{
public class GetEnabledTTSVoices : IRequest
{
public string Name => "get_enabled_tts_voices";
public string[] RequiredKeys => [];
private readonly Database _database;
private readonly ILogger _logger;
public GetEnabledTTSVoices(Database database, ILogger logger)
{
_database = database;
_logger = logger;
}
2024-12-27 23:31:36 +00:00
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
{
2024-12-27 23:31:36 +00:00
var temp = new Dictionary<string, object>() { { "user", channel.Id } };
var voices = new List<string>();
string sql = $"SELECT v.name FROM \"TtsVoiceState\" s "
+ "INNER JOIN \"TtsVoice\" v ON s.\"ttsVoiceId\" = v.id "
+ "WHERE \"userId\" = @user AND state = true";
await _database.Execute(sql, temp, (r) => voices.Add(r.GetString(0)));
2024-12-27 23:31:36 +00:00
_logger.Information($"Fetched all enabled TTS voice for channel [channel: {channel.Id}]");
return RequestResult.Successful(voices, notifyClientsOnAccount: false);
}
}
}