From 7b34981f83072af0ab1d90eca26a602165423bde Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 12 May 2024 01:32:11 -0700 Subject: [PATCH] feat: ChannelSuspiciousUserMessage, ChannelSuspiciousUserUpdate --- .../ChannelSuspiciousUserMessageArgs.cs | 12 ++++++ .../ChannelSuspiciousUserUpdateArgs.cs | 12 ++++++ .../EventSubWebsocketClient.cs | 10 +++++ .../ChannelSuspiciousUserMessageHandler.cs | 39 +++++++++++++++++++ .../ChannelSuspiciousUserUpdateHandler.cs | 39 +++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserMessageArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserUpdateArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserMessageHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserUpdateHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserMessageArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserMessageArgs.cs new file mode 100644 index 0000000..e0db5b7 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserMessageArgs.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public class ChannelSuspiciousUserMessageArgs : TwitchLibEventSubEventArgs> + { + } +} diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserUpdateArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserUpdateArgs.cs new file mode 100644 index 0000000..5b8d851 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelSuspiciousUserUpdateArgs.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel +{ + public sealed class ChannelSuspiciousUserUpdateArgs : TwitchLibEventSubEventArgs> + { + } +} diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index 2182fb9..2833dfa 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -242,6 +242,16 @@ public class EventSubWebsocketClient /// public event AsyncEventHandler ChannelSubscriptionMessage; + /// + /// Event that triggers on "channel.suspicious_user.message" notifications + /// + public event AsyncEventHandler ChannelSuspiciousUserMessage; + + /// + /// Event that triggers on "channel.suspicious_user.update" notifications + /// + public event AsyncEventHandler ChannelSuspiciousUserUpdate; + /// /// Event that triggers on "channel.unban" notifications /// diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserMessageHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserMessageHandler.cs new file mode 100644 index 0000000..8616f65 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserMessageHandler.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +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.SuspiciousUser +{ + /// + /// Handler for 'channel.suspicious_user.message' notifications + /// + public class ChannelSuspiciousUserMessageHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.suspicious_user.message"; + + /// + 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("ChannelSuspiciousUserMessage", new ChannelSuspiciousUserMessageArgs { 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/SuspiciousUser/ChannelSuspiciousUserUpdateHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserUpdateHandler.cs new file mode 100644 index 0000000..af11ae8 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/SuspiciousUser/ChannelSuspiciousUserUpdateHandler.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; +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.SuspiciousUser +{ + /// + /// Handler for 'channel.suspicious_user.update' notifications + /// + public class ChannelSuspiciousUserUpdateHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.suspicious_user.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("ChannelSuspiciousUserUpdate", new ChannelSuspiciousUserUpdateArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); + } + } + } +}