38 lines
1.3 KiB
C#
38 lines
1.3 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 async Task<RequestResult> Grant(string sender, IDictionary<string, object>? data)
|
|
{
|
|
data["voice"] = data["voice"].ToString();
|
|
data["voiceid"] = data["voiceid"].ToString();
|
|
|
|
var result = _voices.Set(data["voiceid"].ToString(), new Voice()
|
|
{
|
|
Id = data["voiceid"].ToString()!,
|
|
Name = data["voice"].ToString()!
|
|
});
|
|
if (result)
|
|
{
|
|
_logger.Information($"Updated voice's [voice id: {data["voiceid"]}] name [new name: {data["voice"]}]");
|
|
return RequestResult.Successful(null);
|
|
}
|
|
return RequestResult.Failed("Something went wrong when updating the cache.");
|
|
}
|
|
}
|
|
} |