hermes-server/Requests/UpdateDefaultTTSVoice.cs

32 lines
1.1 KiB
C#

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;
}
public async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
{
data["user"] = data["user"].ToString();
data["voice"] = data["voice"].ToString();
var success = _users.Modify(data["user"].ToString(), (user) => user.DefaultVoice = data["voice"].ToString()!);
if (!success)
return RequestResult.Failed("Unable to find user data.", notifyClientsOnAccount: false);
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
return RequestResult.Successful(null);
}
}
}