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,35 @@
using System.Collections.Concurrent;
using System.Text.Json;
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class GetTTSUsersAck : IRequestAck
{
public string Name => "get_tts_users";
private readonly User _user;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public GetTTSUsersAck(User user, JsonSerializerOptions options, ILogger logger)
{
_user = user;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var users = JsonSerializer.Deserialize<IDictionary<long, string>>(json, _options);
if (users == null)
return;
var temp = new ConcurrentDictionary<long, string>();
foreach (var entry in users)
temp.TryAdd(entry.Key, entry.Value);
_user.VoicesSelected = temp;
_logger.Information($"Updated chatters' selected voice [count: {temp.Count()}]");
}
}
}