38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using HermesSocketLibrary.Requests;
|
|
using HermesSocketServer.Store;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace HermesSocketServer.Requests
|
|
{
|
|
public class UpdateDefaultTTSVoice : IRequest
|
|
{
|
|
public string Name => "update_default_tts_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)
|
|
{
|
|
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();
|
|
|
|
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);
|
|
|
|
_logger.Information($"Updated default TTS voice for channel [channel: {sender}][voice: {data["voice"]}]");
|
|
return new RequestResult(true, null);
|
|
}
|
|
}
|
|
} |