From 8a0e55bb95eb8f5635fd59bdd8f04ce6301a3065 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 6 Aug 2024 21:15:05 +0000 Subject: [PATCH] Fixed Twitch subscriptions. Fixed typos. Fixed Twitch websocket reconnection. --- Twitch/Socket/Handlers/ChannelAdBreakHandler.cs | 4 ++-- Twitch/Socket/Handlers/ChannelCustomRedemptionHandler.cs | 4 ++-- Twitch/Socket/Handlers/ChannelFollowHandler.cs | 4 ++-- Twitch/Socket/Handlers/ChannelResubscriptionHandler.cs | 4 ++-- Twitch/Socket/Handlers/ChannelSubscriptionGiftHandler.cs | 4 ++-- Twitch/Socket/Handlers/ChannelSubscriptionHandler.cs | 6 +++--- Twitch/Socket/Handlers/NotificationHandler.cs | 4 ++-- Twitch/Socket/Handlers/SessionReconnectHandler.cs | 5 +---- Twitch/Socket/Handlers/SessionWelcomeHandler.cs | 2 ++ Twitch/Socket/TwitchConnectionManager.cs | 5 ++++- Twitch/Socket/TwitchWebsocketClient.cs | 2 ++ 11 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Twitch/Socket/Handlers/ChannelAdBreakHandler.cs b/Twitch/Socket/Handlers/ChannelAdBreakHandler.cs index 9a119a2..a10c576 100644 --- a/Twitch/Socket/Handlers/ChannelAdBreakHandler.cs +++ b/Twitch/Socket/Handlers/ChannelAdBreakHandler.cs @@ -33,7 +33,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get("adbreak"); if (!actions.Any()) { - _logger.Debug($"No redemable actions for ad break was found"); + _logger.Debug($"No redeemable actions for ad break was found"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch ad break"); @@ -45,7 +45,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: ad break]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: ad break]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/ChannelCustomRedemptionHandler.cs b/Twitch/Socket/Handlers/ChannelCustomRedemptionHandler.cs index 92c88d2..f203fa2 100644 --- a/Twitch/Socket/Handlers/ChannelCustomRedemptionHandler.cs +++ b/Twitch/Socket/Handlers/ChannelCustomRedemptionHandler.cs @@ -32,7 +32,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get(message.Reward.Id); if (!actions.Any()) { - _logger.Debug($"No redemable actions for this redeem was found [redeem: {message.Reward.Title}][redeem id: {message.Reward.Id}][transaction: {message.Id}]"); + _logger.Debug($"No redeemable actions for this redeem was found [redeem: {message.Reward.Title}][redeem id: {message.Reward.Id}][transaction: {message.Id}]"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch channel point redemption [redeem: {message.Reward.Title}][redeem id: {message.Reward.Id}][transaction: {message.Id}]"); @@ -44,7 +44,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: {message.Reward.Title}][redeem id: {message.Reward.Id}][transaction: {message.Id}]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: {message.Reward.Title}][redeem id: {message.Reward.Id}][transaction: {message.Id}]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/ChannelFollowHandler.cs b/Twitch/Socket/Handlers/ChannelFollowHandler.cs index 072fa06..c6fae0b 100644 --- a/Twitch/Socket/Handlers/ChannelFollowHandler.cs +++ b/Twitch/Socket/Handlers/ChannelFollowHandler.cs @@ -28,7 +28,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get("follow"); if (!actions.Any()) { - _logger.Debug($"No redemable actions for follow was found"); + _logger.Debug($"No redeemable actions for follow was found"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch follow"); @@ -40,7 +40,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: follow]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: follow]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/ChannelResubscriptionHandler.cs b/Twitch/Socket/Handlers/ChannelResubscriptionHandler.cs index a0ec660..efeec08 100644 --- a/Twitch/Socket/Handlers/ChannelResubscriptionHandler.cs +++ b/Twitch/Socket/Handlers/ChannelResubscriptionHandler.cs @@ -28,7 +28,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get("subscription"); if (!actions.Any()) { - _logger.Debug($"No redemable actions for this subscription was found [message: {message.Message.Text}]"); + _logger.Debug($"No redeemable actions for this subscription was found [message: {message.Message.Text}]"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch subscription [message: {message.Message.Text}]"); @@ -40,7 +40,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: subscription][message: {message.Message.Text}]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: resubscription][message: {message.Message.Text}]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/ChannelSubscriptionGiftHandler.cs b/Twitch/Socket/Handlers/ChannelSubscriptionGiftHandler.cs index f494228..c4025d4 100644 --- a/Twitch/Socket/Handlers/ChannelSubscriptionGiftHandler.cs +++ b/Twitch/Socket/Handlers/ChannelSubscriptionGiftHandler.cs @@ -28,7 +28,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get("subscription.gift"); if (!actions.Any()) { - _logger.Debug($"No redemable actions for this gifted subscription was found"); + _logger.Debug($"No redeemable actions for this gifted subscription was found"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch gifted subscription [gifted: {message.UserLogin}][gifted id: {message.UserId}][Anonymous: {message.IsAnonymous}][cumulative: {message.CumulativeTotal ?? -1}]"); @@ -40,7 +40,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: gifted subscription]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: gifted subscription]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/ChannelSubscriptionHandler.cs b/Twitch/Socket/Handlers/ChannelSubscriptionHandler.cs index a2e1cd3..c93abe8 100644 --- a/Twitch/Socket/Handlers/ChannelSubscriptionHandler.cs +++ b/Twitch/Socket/Handlers/ChannelSubscriptionHandler.cs @@ -6,7 +6,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers { public class ChannelSubscriptionHandler : ITwitchSocketHandler { - public string Name => "channel.subscription"; + public string Name => "channel.subscribe"; private readonly IRedemptionManager _redemptionManager; private readonly ILogger _logger; @@ -30,7 +30,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var actions = _redemptionManager.Get("subscription"); if (!actions.Any()) { - _logger.Debug($"No redemable actions for this subscription was found [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]"); + _logger.Debug($"No redeemable actions for this subscription was found [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]"); return; } _logger.Debug($"Found {actions.Count} actions for this Twitch subscription [subscriber: {message.UserLogin}][subscriber id: {message.UserId}]"); @@ -42,7 +42,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers } catch (Exception ex) { - _logger.Error(ex, $"Failed to execute redeeemable action [action: {action.Name}][action type: {action.Type}][redeem: subscription][subscriber: {message.UserLogin}][subscriber id: {message.UserId}]"); + _logger.Error(ex, $"Failed to execute redeemable action [action: {action.Name}][action type: {action.Type}][redeem: subscription][subscriber: {message.UserLogin}][subscriber id: {message.UserId}]"); } } catch (Exception ex) diff --git a/Twitch/Socket/Handlers/NotificationHandler.cs b/Twitch/Socket/Handlers/NotificationHandler.cs index d6aaa7f..6da1e49 100644 --- a/Twitch/Socket/Handlers/NotificationHandler.cs +++ b/Twitch/Socket/Handlers/NotificationHandler.cs @@ -38,8 +38,8 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers _messageTypes.Add("channel.chat.message_delete", typeof(ChannelChatDeleteMessage)); _messageTypes.Add("channel.channel_points_custom_reward_redemption.add", typeof(ChannelCustomRedemptionMessage)); _messageTypes.Add("channel.follow", typeof(ChannelFollowMessage)); - _messageTypes.Add("channel.resubscription", typeof(ChannelResubscriptionMessage)); - _messageTypes.Add("channel.subscription.message", typeof(ChannelSubscriptionMessage)); + _messageTypes.Add("channel.subscribe", typeof(ChannelSubscriptionMessage)); + _messageTypes.Add("channel.subscription.message", typeof(ChannelResubscriptionMessage)); _messageTypes.Add("channel.subscription.gift", typeof(ChannelSubscriptionGiftMessage)); } diff --git a/Twitch/Socket/Handlers/SessionReconnectHandler.cs b/Twitch/Socket/Handlers/SessionReconnectHandler.cs index 4d4c7a6..7b27b9c 100644 --- a/Twitch/Socket/Handlers/SessionReconnectHandler.cs +++ b/Twitch/Socket/Handlers/SessionReconnectHandler.cs @@ -40,10 +40,7 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers var backup = _manager.GetBackupClient(); var identified = _manager.GetWorkingClient(); - if (identified != null && backup != identified) - { - await identified.DisconnectAsync(new SocketDisconnectionEventArgs("Closed", "Reconnection from another client.")); - } + _logger.Debug($"Reconnection received [receiver: {sender.UID}][main: {identified.UID}][backup: {backup.UID}]"); backup.URL = message.Session.ReconnectUrl; await backup.Connect(); diff --git a/Twitch/Socket/Handlers/SessionWelcomeHandler.cs b/Twitch/Socket/Handlers/SessionWelcomeHandler.cs index daec156..35f4932 100644 --- a/Twitch/Socket/Handlers/SessionWelcomeHandler.cs +++ b/Twitch/Socket/Handlers/SessionWelcomeHandler.cs @@ -47,6 +47,8 @@ namespace TwitchChatTTS.Twitch.Socket.Handlers "channel.chat.clear", "channel.chat.clear_user_messages", "channel.ad_break.begin", + "channel.subscribe", + "channel.subscription.gift", "channel.subscription.message", "channel.ban", "channel.channel_points_custom_reward_redemption.add" diff --git a/Twitch/Socket/TwitchConnectionManager.cs b/Twitch/Socket/TwitchConnectionManager.cs index ef45b79..3dcc116 100644 --- a/Twitch/Socket/TwitchConnectionManager.cs +++ b/Twitch/Socket/TwitchConnectionManager.cs @@ -71,7 +71,7 @@ namespace TwitchChatTTS.Twitch.Socket { if (_identified == client) { - _logger.Error("Twitch client has been re-identified."); + _logger.Warning("Twitch client has been re-identified."); return; } if (_backup != client) @@ -83,6 +83,7 @@ namespace TwitchChatTTS.Twitch.Socket if (_identified != null) { + _logger.Debug("Second Twitch client has been identified; hopefully a reconnection."); return; } @@ -101,10 +102,12 @@ namespace TwitchChatTTS.Twitch.Socket { if (_identified == client) { + _logger.Debug("Identified Twitch client has disconnected."); _identified = null; } else if (_backup == client) { + _logger.Debug("Backup Twitch client has disconnected."); _backup = null; } else diff --git a/Twitch/Socket/TwitchWebsocketClient.cs b/Twitch/Socket/TwitchWebsocketClient.cs index 8c71896..20e35c8 100644 --- a/Twitch/Socket/TwitchWebsocketClient.cs +++ b/Twitch/Socket/TwitchWebsocketClient.cs @@ -22,6 +22,7 @@ namespace TwitchChatTTS.Twitch.Socket public event EventHandler OnIdentified; + public string UID { get; } public string URL; public bool Connected { get; private set; } public bool Identified { get; private set; } @@ -50,6 +51,7 @@ namespace TwitchChatTTS.Twitch.Socket _messageTypes.Add("session_reconnect", typeof(SessionWelcomeMessage)); _messageTypes.Add("notification", typeof(NotificationMessage)); + UID = Guid.NewGuid().ToString("D"); URL = "wss://eventsub.wss.twitch.tv/ws"; }