Cleaned up request acks. Added internal service bus for internal messaging.

This commit is contained in:
Tom
2024-11-08 15:32:42 +00:00
parent fe2eb86a08
commit 66f2bf7ec6
33 changed files with 1326 additions and 415 deletions

View File

@@ -0,0 +1,41 @@
using System.Text.Json;
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class GetEnabledTTSVoicesAck : IRequestAck
{
public string Name => "get_enabled_tts_voices";
private readonly User _user;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public GetEnabledTTSVoicesAck(User user, JsonSerializerOptions options, ILogger logger)
{
_user = user;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var enabledTTSVoices = JsonSerializer.Deserialize<IEnumerable<string>>(json, _options);
if (enabledTTSVoices == null)
{
_logger.Warning("Failed to load enabled tts voices.");
return;
}
if (_user.VoicesEnabled == null)
_user.VoicesEnabled = enabledTTSVoices.ToHashSet();
else
{
_user.VoicesEnabled.Clear();
foreach (var voice in enabledTTSVoices)
_user.VoicesEnabled.Add(voice);
}
_logger.Information($"TTS voices [count: {_user.VoicesEnabled.Count}] have been enabled.");
}
}
}