2024-08-10 15:36:32 -04:00
|
|
|
using HermesSocketLibrary.Requests;
|
2024-10-20 14:07:18 -04:00
|
|
|
using HermesSocketServer.Store;
|
2024-08-10 15:36:32 -04:00
|
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
|
|
|
|
namespace HermesSocketServer.Requests
|
|
|
|
{
|
|
|
|
public class UpdateDefaultTTSVoice : IRequest
|
|
|
|
{
|
|
|
|
public string Name => "update_default_tts_voice";
|
2024-10-20 14:07:18 -04:00
|
|
|
private UserStore _users;
|
2024-08-10 15:36:32 -04:00
|
|
|
private ILogger _logger;
|
|
|
|
|
2024-10-20 14:07:18 -04:00
|
|
|
public UpdateDefaultTTSVoice(UserStore users, ILogger logger)
|
2024-08-10 15:36:32 -04:00
|
|
|
{
|
2024-10-20 14:07:18 -04:00
|
|
|
_users = users;
|
2024-08-10 15:36:32 -04:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
|
|
|
{
|
|
|
|
if (data == null)
|
|
|
|
{
|
|
|
|
_logger.Warning("Data received from request is null. Ignoring it.");
|
|
|
|
return new RequestResult(false, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
data["user"] = data["user"].ToString();
|
|
|
|
data["voice"] = data["voice"].ToString();
|
|
|
|
|
2024-10-20 14:07:18 -04:00
|
|
|
var success = _users.Modify(data["user"].ToString(), (user) => user.DefaultVoice = data["voice"].ToString()!);
|
|
|
|
if (!success)
|
|
|
|
return new RequestResult(false, "Unable to find user data.", notifyClientsOnAccount: false);
|
|
|
|
|
2024-08-10 15:36:32 -04:00
|
|
|
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
|
|
|
|
return new RequestResult(true, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|