hermes-client/Hermes/Socket/Requests/GetChatterIdsAck.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System.Text.Json;
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class GetChatterIdsAck : IRequestAck
{
public string Name => "get_chatter_ids";
private readonly User _user;
private readonly JsonSerializerOptions _options;
private readonly ILogger _logger;
public GetChatterIdsAck(User user, JsonSerializerOptions options, ILogger logger)
{
_user = user;
_options = options;
_logger = logger;
}
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
{
var chatters = JsonSerializer.Deserialize<IEnumerable<long>>(json, _options);
if (chatters == null)
{
_logger.Warning("Chatters is null.");
return;
}
if (!chatters.Any())
{
_logger.Warning("Chatters is empty.");
return;
}
_user.Chatters = [.. chatters];
_logger.Information($"Fetched chatters [count: {chatters.Count()}]");
}
}
}