hermes-server/Requests/UpdateDefaultTTSVoice.cs

33 lines
1.1 KiB
C#
Raw Normal View History

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