diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelModerateArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelModerateArgs.cs new file mode 100644 index 0000000..a70bf4e --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelModerateArgs.cs @@ -0,0 +1,12 @@ +using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; +using TwitchLib.EventSub.Websockets.Core.Models; + +namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel; + +/// +/// Twitch Documentation
+/// When a moderator performs a moderation action in a channel.
+/// Required Scopes: Check documenation for full list
+///
+public class ChannelModerateArgs : TwitchLibEventSubEventArgs> +{ } \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index c43a970..5f2ec16 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -132,10 +132,14 @@ public class EventSubWebsocketClient /// public event AsyncEventHandler ChannelHypeTrainProgress; - /// - /// Event that triggers on "channel.moderator.add" notifications - /// - public event AsyncEventHandler ChannelModeratorAdd; + /// + /// Event that triggers on "channel.moderate" notifications + /// + public event AsyncEventHandler ChannelModerate; + /// + /// Event that triggers on "channel.moderator.add" notifications + /// + public event AsyncEventHandler ChannelModeratorAdd; /// /// Event that triggers on "channel.moderator.remove" notifications /// diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelModerateHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelModerateHandler.cs new file mode 100644 index 0000000..16ff369 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/Moderation/ChannelModerateHandler.cs @@ -0,0 +1,36 @@ +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.Moderation; + +/// +/// Handler for 'channel.moderate' notifications +/// +public class ChannelModerateHandler : INotificationHandler +{ + /// + public string SubscriptionType => "channel.moderate"; + + /// + 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("ChannelModerate", new ChannelModerateArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); + } + } +} \ No newline at end of file