From 80caf60c5e0e0d5dfedc1d276cdaf2fcc207fb5e Mon Sep 17 00:00:00 2001 From: Iris <68797873+iryis@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:16:11 -0500 Subject: [PATCH 1/2] Add Chat Notificiation and Shared Chat handlers --- .../Channel/ChannelChatNotificationArgs.cs | 9 +++++ .../ChannelSharedChatSessionBeginArgs.cs | 8 ++++ .../ChannelSharedChatSessionEndArgs.cs | 8 ++++ .../ChannelSharedChatSessionUpdateArgs.cs | 8 ++++ .../EventSubWebsocketClient.cs | 20 ++++++++++ .../Channel/ChatNotificationHandler.cs | 33 +++++++++++++++++ .../ChannelSharedChatSessionBeginHandler.cs | 37 +++++++++++++++++++ .../ChannelSharedChatSessionEndHandler.cs | 37 +++++++++++++++++++ .../ChannelSharedChatSessionUpdateHandler.cs | 37 +++++++++++++++++++ 9 files changed, 197 insertions(+) create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionBeginArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionEndArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionUpdateArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionBeginHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionEndHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionUpdateHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs new file mode 100644 index 0000000..b960e5b --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs @@ -0,0 +1,9 @@ +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public class ChannelChatNotificationArgs : TwitchLibEventSubEventArgs> + { + } +} diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionBeginArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionBeginArgs.cs new file mode 100644 index 0000000..76a0403 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionBeginArgs.cs @@ -0,0 +1,8 @@ +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public class ChannelSharedChatSessionBeginArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionEndArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionEndArgs.cs new file mode 100644 index 0000000..82c81fb --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionEndArgs.cs @@ -0,0 +1,8 @@ +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public class ChannelSharedChatSessionEndArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionUpdateArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionUpdateArgs.cs new file mode 100644 index 0000000..d996faa --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSharedChatSessionUpdateArgs.cs @@ -0,0 +1,8 @@ +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public class ChannelSharedChatSessionUpdateArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index 40d530d..560b849 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -295,6 +295,26 @@ public class EventSubWebsocketClient /// Event that triggers on "user.whisper.message" notifications /// public event AsyncEventHandler UserWhisperMessage; + + /// + /// Event that triggers on "channel.shared_chat.begin" notifications + /// + public event AsyncEventHandler ChannelSharedChatSessionBegin; + + /// + /// Event that triggers on "channel.shared_chat.update" notifications + /// + public event AsyncEventHandler ChannelSharedChatSessionUpdate; + + /// + /// Event that triggers on "channel.shared_chat.end" notifications + /// + public event AsyncEventHandler ChannelSharedChatSessionEnd; + + /// + /// Event that triggers on "channel.chat.notification" notifications + /// + public event AsyncEventHandler ChannelChatNotification; #endregion diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs new file mode 100644 index 0000000..4ca773e --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs @@ -0,0 +1,33 @@ +using System; +using System.Text.Json; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.EventArgs; +using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; +using TwitchLib.EventSub.Websockets.Core.Handler; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Handler.Channel +{ + /// + /// Handler for 'channel.chat.notification' notifications + /// + public class ChatNotificationHandler : INotificationHandler + { + public string SubscriptionType => "channel.chat.notification"; + + public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) + { + try + { + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + if (data is null) + throw new InvalidOperationException("Parsed JSON cannot be null!"); + client.RaiseEvent("ChannelChatMessage", new ChannelChatNotificationArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); + } + } + } +} diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionBeginHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionBeginHandler.cs new file mode 100644 index 0000000..ea2f3e1 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionBeginHandler.cs @@ -0,0 +1,37 @@ +using System; +using System.Text.Json; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.EventArgs; +using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; +using TwitchLib.EventSub.Websockets.Core.Handler; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat +{ + /// + /// Handler for 'channel.shared_chat.begin' notifications + /// + public class ChannelSharedChatSessionBeginHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.shared_chat.begin"; + + /// + public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) + { + try + { + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + + if (data is null) + throw new InvalidOperationException("Parsed JSON cannot be null!"); + + client.RaiseEvent("ChannelSharedChatSessionBegin", new ChannelSharedChatSessionBeginArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.begin notification! Raw Json: {jsonString}" }); + } + } + } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionEndHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionEndHandler.cs new file mode 100644 index 0000000..ef0e972 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionEndHandler.cs @@ -0,0 +1,37 @@ +using System; +using System.Text.Json; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.EventArgs; +using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; +using TwitchLib.EventSub.Websockets.Core.Handler; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat +{ + /// + /// Handler for 'channel.shared_chat.end' notifications + /// + public class ChannelSharedChatSessionEndHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.shared_chat.end"; + + /// + public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) + { + try + { + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + + if (data is null) + throw new InvalidOperationException("Parsed JSON cannot be null!"); + + client.RaiseEvent("ChannelSharedChatSessionEnd", new ChannelSharedChatSessionEndArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.end notification! Raw Json: {jsonString}" }); + } + } + } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionUpdateHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionUpdateHandler.cs new file mode 100644 index 0000000..0047e0b --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/SharedChat/ChannelSharedChatSessionUpdateHandler.cs @@ -0,0 +1,37 @@ +using System; +using System.Text.Json; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.EventArgs; +using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; +using TwitchLib.EventSub.Websockets.Core.Handler; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat +{ + /// + /// Handler for 'channel.shared_chat.update' notifications + /// + public class ChannelSharedChatSessionUpdateHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.shared_chat.update"; + + /// + public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) + { + try + { + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + + if (data is null) + throw new InvalidOperationException("Parsed JSON cannot be null!"); + + client.RaiseEvent("ChannelSharedChatSessionUpdate", new ChannelSharedChatSessionUpdateArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.update notification! Raw Json: {jsonString}" }); + } + } + } +} \ No newline at end of file From c3c2f758ffdf4de36eeb1461db5c87b212a4737e Mon Sep 17 00:00:00 2001 From: Iris <68797873+iryis@users.noreply.github.com> Date: Wed, 26 Feb 2025 04:21:17 -0500 Subject: [PATCH 2/2] Remove chat notification (see 51) --- .../Channel/ChannelChatNotificationArgs.cs | 9 ----- .../EventSubWebsocketClient.cs | 5 --- .../Channel/ChatNotificationHandler.cs | 33 ------------------- 3 files changed, 47 deletions(-) delete mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs delete mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs deleted file mode 100644 index b960e5b..0000000 --- a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatNotificationArgs.cs +++ /dev/null @@ -1,9 +0,0 @@ -using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; -using TwitchLib.EventSub.Websockets.Core.Models; - -namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel -{ - public class ChannelChatNotificationArgs : TwitchLibEventSubEventArgs> - { - } -} diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index 560b849..56fa1fe 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -310,11 +310,6 @@ public class EventSubWebsocketClient /// Event that triggers on "channel.shared_chat.end" notifications /// public event AsyncEventHandler ChannelSharedChatSessionEnd; - - /// - /// Event that triggers on "channel.chat.notification" notifications - /// - public event AsyncEventHandler ChannelChatNotification; #endregion diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs deleted file mode 100644 index 4ca773e..0000000 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/ChatNotificationHandler.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Text.Json; -using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; -using TwitchLib.EventSub.Websockets.Core.EventArgs; -using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; -using TwitchLib.EventSub.Websockets.Core.Handler; -using TwitchLib.EventSub.Websockets.Core.Models; - -namespace TwitchLib.EventSub.Websockets.Handler.Channel -{ - /// - /// Handler for 'channel.chat.notification' notifications - /// - public class ChatNotificationHandler : INotificationHandler - { - public string SubscriptionType => "channel.chat.notification"; - - public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) - { - try - { - var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); - if (data is null) - throw new InvalidOperationException("Parsed JSON cannot be null!"); - client.RaiseEvent("ChannelChatMessage", new ChannelChatNotificationArgs { Notification = data }); - } - catch (Exception ex) - { - client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); - } - } - } -}