Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
48
Hermes/Socket/Requests/GetEmotesAck.cs
Normal file
48
Hermes/Socket/Requests/GetEmotesAck.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Chat.Emotes;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class GetEmotesAck : IRequestAck
|
||||
{
|
||||
public string Name => "get_emotes";
|
||||
private readonly IEmoteDatabase _emotes;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public GetEmotesAck(IEmoteDatabase emotes, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_emotes = emotes;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<IEnumerable<EmoteInfo>>(json, _options);
|
||||
if (data == null)
|
||||
{
|
||||
_logger.Warning("Emotes is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
var count = 0;
|
||||
var duplicateNames = 0;
|
||||
foreach (var emote in data)
|
||||
{
|
||||
if (_emotes.Get(emote.Name) == null)
|
||||
{
|
||||
_emotes.Add(emote.Name, emote.Id);
|
||||
count++;
|
||||
}
|
||||
else
|
||||
duplicateNames++;
|
||||
}
|
||||
_logger.Information($"Fetched emotes of various sources [count: {count}]");
|
||||
if (duplicateNames > 0)
|
||||
_logger.Warning($"Found {duplicateNames} emotes with duplicate names.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user