Added Actions & Redemptions updates via websocket messages. Updated RedemptionManager due to live changes.
This commit is contained in:
35
Hermes/Socket/Requests/UpdateRedeemableActionAck.cs
Normal file
35
Hermes/Socket/Requests/UpdateRedeemableActionAck.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketLibrary.Requests.Messages;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Twitch.Redemptions;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class UpdateRedeemableActionAck : IRequestAck
|
||||
{
|
||||
public string Name => "update_redeemable_action";
|
||||
private readonly IRedemptionManager _redemptions;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public UpdateRedeemableActionAck(IRedemptionManager redemptions, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_redemptions = redemptions;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var action = JsonSerializer.Deserialize<RedeemableAction>(json, _options);
|
||||
if (action == null)
|
||||
{
|
||||
_logger.Warning($"Redeemable action data received is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
_redemptions.Update(action);
|
||||
_logger.Information($"A new redeemable action has been created [action name: {action.Name}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user