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 16:39:13 -04:00
|
|
|
public string[] RequiredKeys => ["user", "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)
|
|
|
|
{
|
|
|
|
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)
|
2024-10-20 16:39:13 -04:00
|
|
|
return RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false);
|
2024-10-20 14:07:18 -04:00
|
|
|
|
2024-08-10 15:36:32 -04:00
|
|
|
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
|
2024-10-20 16:39:13 -04:00
|
|
|
return RequestResult.Successful(null);
|
2024-08-10 15:36:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|