35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.Text.Json;
|
|
using HermesSocketLibrary.Requests.Messages;
|
|
using Serilog;
|
|
using TwitchChatTTS.Twitch.Redemptions;
|
|
|
|
namespace TwitchChatTTS.Hermes.Socket.Requests
|
|
{
|
|
public class CreateRedemptionAck : IRequestAck
|
|
{
|
|
public string Name => "create_redemption";
|
|
private readonly IRedemptionManager _redemptions;
|
|
private readonly JsonSerializerOptions _options;
|
|
private readonly ILogger _logger;
|
|
|
|
public CreateRedemptionAck(IRedemptionManager redemptions, JsonSerializerOptions options, ILogger logger)
|
|
{
|
|
_redemptions = redemptions;
|
|
_options = options;
|
|
_logger = logger;
|
|
}
|
|
|
|
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
|
{
|
|
var redemption = JsonSerializer.Deserialize<Redemption>(json, _options);
|
|
if (redemption == null)
|
|
{
|
|
_logger.Warning($"Redemption data received is null.");
|
|
return;
|
|
}
|
|
|
|
_redemptions.Add(redemption);
|
|
_logger.Information($"A new redemption has been created [redemption id: {redemption.Id}][twitch redemption id: {redemption.TwitchRedemptionId}]");
|
|
}
|
|
}
|
|
} |