Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
40
Hermes/Socket/Requests/GetTTSVoicesAck.cs
Normal file
40
Hermes/Socket/Requests/GetTTSVoicesAck.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using Serilog;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class GetTTSVoicesAck : IRequestAck
|
||||
{
|
||||
public string Name => "get_tts_voices";
|
||||
private readonly User _user;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetTTSVoicesAck(User user, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_user = user;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var voices = JsonSerializer.Deserialize<IEnumerable<VoiceDetails>>(json, _options);
|
||||
if (voices == null)
|
||||
{
|
||||
_logger.Warning("Voices received is null.");
|
||||
return;
|
||||
}
|
||||
if (!voices.Any())
|
||||
{
|
||||
_logger.Warning("Voices received is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
_user.VoicesAvailable = new ConcurrentDictionary<string, string>(voices.ToDictionary(e => e.Id, e => e.Name));
|
||||
_logger.Information($"Fetched all available voices for TTS [count: {_user.VoicesAvailable.Count}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user