2024-12-27 23:31:36 +00:00
|
|
|
using HermesSocketServer.Models;
|
2024-10-20 18:07:18 +00:00
|
|
|
using HermesSocketServer.Store;
|
2024-08-10 19:36:32 +00:00
|
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
|
|
|
|
namespace HermesSocketServer.Requests
|
|
|
|
{
|
|
|
|
public class UpdateDefaultTTSVoice : IRequest
|
|
|
|
{
|
|
|
|
public string Name => "update_default_tts_voice";
|
2024-10-20 20:39:13 +00:00
|
|
|
public string[] RequiredKeys => ["user", "voice"];
|
2024-10-20 18:07:18 +00:00
|
|
|
private UserStore _users;
|
2024-08-10 19:36:32 +00:00
|
|
|
private ILogger _logger;
|
|
|
|
|
2024-10-20 18:07:18 +00:00
|
|
|
public UpdateDefaultTTSVoice(UserStore users, ILogger logger)
|
2024-08-10 19:36:32 +00:00
|
|
|
{
|
2024-10-20 18:07:18 +00:00
|
|
|
_users = users;
|
2024-08-10 19:36:32 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-12-27 23:31:36 +00:00
|
|
|
public async Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
2024-08-10 19:36:32 +00:00
|
|
|
{
|
2024-12-27 23:31:36 +00:00
|
|
|
string user = data["user"].ToString()!;
|
|
|
|
string voice = data["voice"].ToString()!;
|
2024-08-10 19:36:32 +00:00
|
|
|
|
2024-12-27 23:31:36 +00:00
|
|
|
var success = _users.Modify(user, (user) => user.DefaultVoice = voice);
|
2024-10-20 18:07:18 +00:00
|
|
|
if (!success)
|
2024-12-27 23:31:36 +00:00
|
|
|
return RequestResult.Failed("Unable to find user data.");
|
2024-10-20 18:07:18 +00:00
|
|
|
|
2024-12-27 23:31:36 +00:00
|
|
|
_logger.Information($"Updated default TTS voice for channel [channel: {channel.Id}][voice: {voice}]");
|
2024-10-20 20:39:13 +00:00
|
|
|
return RequestResult.Successful(null);
|
2024-08-10 19:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|