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