Fixed redemptions not loading properly

This commit is contained in:
Tom 2024-11-08 16:11:24 +00:00
parent 66f2bf7ec6
commit 0932c1c38e
3 changed files with 8 additions and 13 deletions

View File

@ -193,16 +193,10 @@ namespace TwitchChatTTS.Hermes.Socket
private async Task FetchRedeemableActions(IEnumerable<Redemption> redemptions) private async Task FetchRedeemableActions(IEnumerable<Redemption> redemptions)
{ {
var requestId = _callbackManager.GenerateKeyForCallback(new HermesRequestData()
{
Data = new Dictionary<string, object>() { { "redemptions", redemptions } }
});
await Send(3, new RequestMessage() await Send(3, new RequestMessage()
{ {
RequestId = requestId,
Type = "get_redeemable_actions", Type = "get_redeemable_actions",
Data = null Data = new Dictionary<string, object>() { { "redemptions", redemptions } }
}); });
} }

View File

@ -31,9 +31,10 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
return; return;
} }
if (requestData["redemptions"] is not IEnumerable<Redemption> redemptions) IEnumerable<Redemption>? redemptions = JsonSerializer.Deserialize<IEnumerable<Redemption>>(requestData["redemptions"].ToString() ?? string.Empty, _options);
if (redemptions == null)
{ {
_logger.Warning("Failed to read the redemptions while updating redemption actions."); _logger.Warning($"Failed to read the redemptions while updating redemption actions [class type: {requestData["redemptions"].GetType().Name}]");
return; return;
} }

View File

@ -30,7 +30,7 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
{ {
hermesRequestData = _callbacks.Take(requestId); hermesRequestData = _callbacks.Take(requestId);
if (hermesRequestData == null) if (hermesRequestData == null)
_logger.Warning($"Could not find callback for request [request id: {requestId}][type: {GetType().Name}]"); _logger.Warning($"Could not find callback for request [request id: {requestId}][type: {Name}]");
else if (hermesRequestData.Data == null) else if (hermesRequestData.Data == null)
hermesRequestData.Data = new Dictionary<string, object>(); hermesRequestData.Data = new Dictionary<string, object>();
} }
@ -39,11 +39,11 @@ namespace TwitchChatTTS.Hermes.Socket.Requests
if (redemptions != null) if (redemptions != null)
{ {
_logger.Information($"Redemptions loaded [count: {redemptions.Count()}]"); _logger.Information($"Redemptions loaded [count: {redemptions.Count()}]");
if (hermesRequestData != null) if (hermesRequestData?.Data != null)
{ {
hermesRequestData.Data!.Add("redemptions", redemptions); hermesRequestData.Data.Add("redemptions", redemptions);
_logger.Debug($"Callback was found for request [request id: {requestId}][type: {GetType().Name}]"); _logger.Debug($"Callback was found for request [request id: {requestId}][type: {Name}]");
hermesRequestData.Callback?.Invoke(hermesRequestData.Data); hermesRequestData.Callback?.Invoke(hermesRequestData.Data);
} }
} }