2024-11-08 10:32:42 -05:00
|
|
|
using System.Text.Json;
|
|
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
|
|
using Serilog;
|
|
|
|
using TwitchChatTTS.Bus;
|
|
|
|
using TwitchChatTTS.Bus.Data;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
|
|
|
{
|
|
|
|
public class GetRedeemableActionsAck : IRequestAck
|
|
|
|
{
|
|
|
|
public string Name => "get_redeemable_actions";
|
|
|
|
private readonly ServiceBusCentral _bus;
|
|
|
|
private readonly JsonSerializerOptions _options;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
public GetRedeemableActionsAck(
|
|
|
|
ServiceBusCentral bus,
|
|
|
|
JsonSerializerOptions options,
|
|
|
|
ILogger logger)
|
|
|
|
{
|
|
|
|
_bus = bus;
|
|
|
|
_options = options;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
|
|
|
{
|
|
|
|
if (requestData == null)
|
|
|
|
{
|
|
|
|
_logger.Warning("Request data is null.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-11-08 11:11:24 -05:00
|
|
|
IEnumerable<Redemption>? redemptions = JsonSerializer.Deserialize<IEnumerable<Redemption>>(requestData["redemptions"].ToString() ?? string.Empty, _options);
|
|
|
|
if (redemptions == null)
|
2024-11-08 10:32:42 -05:00
|
|
|
{
|
2024-11-08 11:11:24 -05:00
|
|
|
_logger.Warning($"Failed to read the redemptions while updating redemption actions [class type: {requestData["redemptions"].GetType().Name}]");
|
2024-11-08 10:32:42 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerable<RedeemableAction>? actions = JsonSerializer.Deserialize<IEnumerable<RedeemableAction>>(json, _options);
|
|
|
|
if (actions == null)
|
|
|
|
{
|
|
|
|
_logger.Warning("Failed to read the redeemable actions for redemptions.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Information($"Redeemable actions loaded [count: {actions.Count()}]");
|
|
|
|
_bus.Send(this, "redemptions_initiation", new RedemptionInitiation() {
|
|
|
|
Redemptions = redemptions,
|
|
|
|
Actions = actions.ToDictionary(a => a.Name, a => a)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|