41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using HermesSocketLibrary.Requests.Messages;
|
|
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, TTSVoice> _voices;
|
|
private ILogger _logger;
|
|
|
|
public UpdateTTSVoice(IStore<string, TTSVoice> 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 voice = new TTSVoice()
|
|
{
|
|
Id = voiceId,
|
|
Name = voiceName
|
|
};
|
|
|
|
var result = _voices.Modify(voiceId, voice);
|
|
if (result)
|
|
{
|
|
_logger.Information($"Updated voice's name on channel [voice id: {voiceId}][name: {voiceName}][channel: {channel.Id}]");
|
|
return Task.FromResult(RequestResult.Successful(voice));
|
|
}
|
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
|
}
|
|
}
|
|
} |