Using VoiceStore for GetTTSVoices request

This commit is contained in:
Tom 2024-10-18 03:18:40 +00:00
parent 1f7eb7f402
commit 6a5c24dc2c

View File

@ -1,5 +1,5 @@
using HermesSocketLibrary.db;
using HermesSocketLibrary.Requests; using HermesSocketLibrary.Requests;
using HermesSocketServer.Store;
using ILogger = Serilog.ILogger; using ILogger = Serilog.ILogger;
namespace HermesSocketServer.Requests namespace HermesSocketServer.Requests
@ -7,24 +7,20 @@ namespace HermesSocketServer.Requests
public class GetTTSUsers : IRequest public class GetTTSUsers : IRequest
{ {
public string Name => "get_tts_users"; public string Name => "get_tts_users";
private readonly Database _database; private ChatterStore _chatters;
private readonly ILogger _logger; private ILogger _logger;
public GetTTSUsers(Database database, ILogger logger) public GetTTSUsers(ChatterStore chatters, ILogger logger)
{ {
_database = database; _chatters = chatters;
_logger = logger; _logger = logger;
} }
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data) public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
{ {
var temp = new Dictionary<string, object>() { { "user", sender } }; var temp = _chatters.Get(sender);
IDictionary<long, string> users = new Dictionary<long, string>();
string sql = $"SELECT \"ttsVoiceId\", \"chatterId\" FROM \"TtsChatVoice\" WHERE \"userId\" = @user";
await _database.Execute(sql, temp, (r) => users.Add(r.GetInt64(1), r.GetString(0)));
_logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {sender}]"); _logger.Information($"Fetched all chatters' selected tts voice for channel [channel: {sender}]");
return new RequestResult(true, users, notifyClientsOnAccount: false); return new RequestResult(true, temp, notifyClientsOnAccount: false);
} }
} }
} }