diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningAcknowledgeArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningAcknowledgeArgs.cs new file mode 100644 index 0000000..acfad2e --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningAcknowledgeArgs.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 ChannelWarningAcknowledgeArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningSendArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningSendArgs.cs new file mode 100644 index 0000000..e05d67a --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningSendArgs.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 ChannelWarningSendArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index c93d48b..40d530d 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -257,6 +257,16 @@ public class EventSubWebsocketClient /// public event AsyncEventHandler ChannelSuspiciousUserUpdate; + /// + /// Event that triggers on "channel.warning.acknowledge" notifications + /// + public event AsyncEventHandler ChannelWarningAcknowledge; + + /// + /// Event that triggers on "channel.warning.send" notifications + /// + public event AsyncEventHandler ChannelWarningSend; + /// /// Event that triggers on "channel.unban" notifications /// diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningAcknowledgeHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningAcknowledgeHandler.cs new file mode 100644 index 0000000..b6787f5 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningAcknowledgeHandler.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.Warning +{ + /// + /// Handler for 'channel.warning.acknowledge' notifications + /// + public class ChannelWarningAcknowledgeHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.warning.acknowledge"; + + /// + 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("ChannelWarningAcknowledge", new ChannelWarningAcknowledgeArgs { 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/Warning/ChannelWarningSendHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningSendHandler.cs new file mode 100644 index 0000000..236d9c9 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningSendHandler.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.Warning +{ + /// + /// Handler for 'channel.warning.send' notifications + /// + public class ChannelWarningSendHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.warning.send"; + + /// + 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("ChannelWarningSend", new ChannelWarningSendArgs { Notification = data }); + } + catch (Exception ex) + { + client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); + } + } + } +}