using HermesSocketServer.Models; using HermesSocketServer.Store; using ILogger = Serilog.ILogger; namespace HermesSocketServer.Requests { public class CreateTTSVoice : IRequest { public string Name => "create_tts_voice"; public string[] RequiredKeys => ["voice"]; private IStore _voices; private ILogger _logger; private Random _random; public CreateTTSVoice(VoiceStore voices, ILogger logger) { _voices = voices; _logger = logger; _random = new Random(); } public Task Grant(Channel channel, IDictionary data) { string voice = data["voice"].ToString()!; string id = RandomString(25); var result = _voices.Set(id, new Voice() { Id = id, Name = voice }); if (result) { _logger.Information($"Added a new voice [voice: {voice}][voice id: {id}]"); return Task.FromResult(RequestResult.Successful(id)); } return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache.")); } private string RandomString(int length) { const string chars = "abcdefghijklmnopqrstuvwxyz0123456789"; return new string(Enumerable.Repeat(chars, length) .Select(s => s[_random.Next(s.Length)]).ToArray()); } } }