Added missing websocket support for Redemptions and Actions. Fixed Ad Break actions. Cleaned some code.

This commit is contained in:
Tom
2025-01-07 15:30:13 +00:00
parent 77b37f04b6
commit 64cb0c1f6d
17 changed files with 227 additions and 36 deletions

View File

@ -25,14 +25,14 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
if (message.IsAutomatic)
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][automatic: true]");
else
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
_logger.Information($"Ad break has begun [duration: {message.DurationSeconds} seconds][automatic: false][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
try
{
var actions = _redemptionManager.Get("adbreak_begin");
if (!actions.Any())
if (actions.Any())
{
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break");
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break begin");
foreach (var action in actions)
try
@ -46,20 +46,27 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
else
_logger.Debug($"No redeemable actions for ad break begin was found");
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break begin");
}
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Task.Run(async () =>
Task.Run(async () =>
{
try
{
await Task.Delay(TimeSpan.FromSeconds(message.DurationSeconds));
if (message.IsAutomatic)
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][automatic: true]");
else
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
actions = _redemptionManager.Get("adbreak_end");
if (!actions.Any())
_logger.Information($"Ad break has ended [duration: {message.DurationSeconds} seconds][automatic: false][requester: {message.RequesterUserLogin}][requester id: {message.RequesterUserId}]");
var actions = _redemptionManager.Get("adbreak_end");
if (actions.Any())
{
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break");
_logger.Debug($"Found {actions.Count()} actions for this Twitch ad break end");
foreach (var action in actions)
try
@ -73,13 +80,13 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers
}
else
_logger.Debug($"No redeemable actions for ad break end was found");
});
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break end");
}
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
catch (Exception ex)
{
_logger.Error(ex, $"Failed to fetch the redeemable actions for ad break begin");
}
}
}
}