38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using HermesSocketServer.Models;
|
|
using HermesSocketServer.Store;
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
namespace HermesSocketServer.Requests
|
|
{
|
|
public class UpdateTTSVoice : IRequest
|
|
{
|
|
public string Name => "update_tts_voice";
|
|
public string[] RequiredKeys => ["voice", "voiceId"];
|
|
private IStore<string, Voice> _voices;
|
|
private ILogger _logger;
|
|
|
|
public UpdateTTSVoice(VoiceStore voices, ILogger logger)
|
|
{
|
|
_voices = voices;
|
|
_logger = logger;
|
|
}
|
|
|
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
|
{
|
|
string voiceName = data["voice"].ToString()!;
|
|
string voiceId = data["voiceid"].ToString()!;
|
|
|
|
var result = _voices.Set(voiceId, new Voice()
|
|
{
|
|
Id = voiceId,
|
|
Name = voiceName
|
|
});
|
|
if (result)
|
|
{
|
|
_logger.Information($"Updated voice's [voice id: {voiceId}] name [new name: {voiceName}]");
|
|
return Task.FromResult(RequestResult.Successful(null));
|
|
}
|
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
|
}
|
|
}
|
|
} |