From f0f4e514dd5aedb60477626b14a9fc0747b13a23 Mon Sep 17 00:00:00 2001 From: Proddy Date: Mon, 15 Apr 2024 21:47:16 +0100 Subject: [PATCH 1/4] Channel VIP Events Add support for `channel.vip.add` and `channel.vip.remove`. Requires https://github.com/TwitchLib/TwitchLib.EventSub.Core/pull/27 --- .../Core/EventArgs/Channel/ChannelVIPArgs.cs | 8 ++++ .../EventSubWebsocketClient.cs | 9 +++++ .../Channel/VIPs/ChannelVIPAddHandler.cs | 37 +++++++++++++++++++ .../Channel/VIPs/ChannelVIPRemoveHandler.cs | 37 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs new file mode 100644 index 0000000..ebcbf39 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.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 ChannelVIPArgs : TwitchLibEventSubEventArgs> + { } +} \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index 75cd279..6c943f4 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -141,6 +141,15 @@ public class EventSubWebsocketClient /// public event AsyncEventHandler ChannelModeratorRemove; + /// + /// Event that triggers on "channel.vip.add" notifications + /// + public event AsyncEventHandler ChannelVIPAdd; + /// + /// Event that triggers on "channel.vip.remove" notifications + /// + public event AsyncEventHandler ChannelVIPRemove; + /// /// Event that triggers on "channel.channel_points_custom_reward.add" notifications /// diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs new file mode 100644 index 0000000..062810b --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.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.VIPs +{ + /// + /// Handler for 'channel.vip.add' notifications + /// + public class ChannelVIPAddHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.vip.add"; + + /// + 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("ChannelVIPAdd", new ChannelVIPArgs { 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 diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs new file mode 100644 index 0000000..fcfbf23 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.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.VIPs +{ + /// + /// Handler for 'channel.vip.remove' notifications + /// + public class ChannelVIPRemoveHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.vip.remove"; + + /// + 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("ChannelVIPRemove", new ChannelVIPArgs { 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 From 7c7ebdf4e874f8d97c32bd8447a98880ed6e4d20 Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 17 Apr 2024 18:03:15 +0100 Subject: [PATCH 2/4] Casing corrections --- .../Channel/{ChannelVIPArgs.cs => ChannelVipArgs.cs} | 2 +- TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs | 4 ++-- .../{ChannelVIPAddHandler.cs => ChannelVipAddHandler.cs} | 6 +++--- ...hannelVIPRemoveHandler.cs => ChannelVipRemoveHandler.cs} | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) rename TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/{ChannelVIPArgs.cs => ChannelVipArgs.cs} (65%) rename TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/{ChannelVIPAddHandler.cs => ChannelVipAddHandler.cs} (84%) rename TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/{ChannelVIPRemoveHandler.cs => ChannelVipRemoveHandler.cs} (84%) diff --git a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs similarity index 65% rename from TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs rename to TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs index ebcbf39..4e7d517 100644 --- a/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVIPArgs.cs +++ b/TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs @@ -3,6 +3,6 @@ namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel { - public class ChannelVIPArgs : TwitchLibEventSubEventArgs> + public class ChannelVipArgs : TwitchLibEventSubEventArgs> { } } \ No newline at end of file diff --git a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs index 6c943f4..2182fb9 100644 --- a/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs +++ b/TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs @@ -144,11 +144,11 @@ public class EventSubWebsocketClient /// /// Event that triggers on "channel.vip.add" notifications /// - public event AsyncEventHandler ChannelVIPAdd; + public event AsyncEventHandler ChannelVipAdd; /// /// Event that triggers on "channel.vip.remove" notifications /// - public event AsyncEventHandler ChannelVIPRemove; + public event AsyncEventHandler ChannelVipRemove; /// /// Event that triggers on "channel.channel_points_custom_reward.add" notifications diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs similarity index 84% rename from TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs rename to TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs index 062810b..e40483d 100644 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPAddHandler.cs +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs @@ -11,7 +11,7 @@ namespace TwitchLib.EventSub.Websockets.Handler.Channel.VIPs /// /// Handler for 'channel.vip.add' notifications /// - public class ChannelVIPAddHandler : INotificationHandler + public class ChannelVipAddHandler : INotificationHandler { /// public string SubscriptionType => "channel.vip.add"; @@ -21,12 +21,12 @@ public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerial { try { - var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); if (data is null) throw new InvalidOperationException("Parsed JSON cannot be null!"); - client.RaiseEvent("ChannelVIPAdd", new ChannelVIPArgs { Notification = data }); + client.RaiseEvent("ChannelVipAdd", new ChannelVipArgs { Notification = data }); } catch (Exception ex) { diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs similarity index 84% rename from TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs rename to TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs index fcfbf23..ce130af 100644 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVIPRemoveHandler.cs +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs @@ -11,7 +11,7 @@ namespace TwitchLib.EventSub.Websockets.Handler.Channel.VIPs /// /// Handler for 'channel.vip.remove' notifications /// - public class ChannelVIPRemoveHandler : INotificationHandler + public class ChannelVipRemoveHandler : INotificationHandler { /// public string SubscriptionType => "channel.vip.remove"; @@ -21,12 +21,12 @@ public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerial { try { - var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); + var data = JsonSerializer.Deserialize>(jsonString.AsSpan(), serializerOptions); if (data is null) throw new InvalidOperationException("Parsed JSON cannot be null!"); - client.RaiseEvent("ChannelVIPRemove", new ChannelVIPArgs { Notification = data }); + client.RaiseEvent("ChannelVipRemove", new ChannelVipArgs { Notification = data }); } catch (Exception ex) { From 307c7dd8231dbc93b512e0f180d618d137eb4f7e Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 17 Apr 2024 18:05:39 +0100 Subject: [PATCH 3/4] More casing corrections --- .../Channel/VIPs/ChannelVipAddHandler.cs | 2 +- .../Channel/VIPs/ChannelVipRemoveHandler.cs | 2 +- .../Channel/Vips/ChannelVipAddHandler.cs | 37 +++++++++++++++++++ .../Channel/Vips/ChannelVipRemoveHandler.cs | 37 +++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipAddHandler.cs create mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipRemoveHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs index e40483d..1b11576 100644 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs @@ -6,7 +6,7 @@ using TwitchLib.EventSub.Websockets.Core.Handler; using TwitchLib.EventSub.Websockets.Core.Models; -namespace TwitchLib.EventSub.Websockets.Handler.Channel.VIPs +namespace TwitchLib.EventSub.Websockets.Handler.Channel.Vips { /// /// Handler for 'channel.vip.add' notifications diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs index ce130af..34bb979 100644 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs @@ -6,7 +6,7 @@ using TwitchLib.EventSub.Websockets.Core.Handler; using TwitchLib.EventSub.Websockets.Core.Models; -namespace TwitchLib.EventSub.Websockets.Handler.Channel.VIPs +namespace TwitchLib.EventSub.Websockets.Handler.Channel.Vips { /// /// Handler for 'channel.vip.remove' notifications diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipAddHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipAddHandler.cs new file mode 100644 index 0000000..1b11576 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipAddHandler.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.Vips +{ + /// + /// Handler for 'channel.vip.add' notifications + /// + public class ChannelVipAddHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.vip.add"; + + /// + 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("ChannelVipAdd", new ChannelVipArgs { 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 diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipRemoveHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipRemoveHandler.cs new file mode 100644 index 0000000..34bb979 --- /dev/null +++ b/TwitchLib.EventSub.Websockets/Handler/Channel/Vips/ChannelVipRemoveHandler.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.Vips +{ + /// + /// Handler for 'channel.vip.remove' notifications + /// + public class ChannelVipRemoveHandler : INotificationHandler + { + /// + public string SubscriptionType => "channel.vip.remove"; + + /// + 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("ChannelVipRemove", new ChannelVipArgs { 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 From d09b926c66f248d291e732bbf84cc4abba24f39e Mon Sep 17 00:00:00 2001 From: Proddy Date: Wed, 17 Apr 2024 18:07:04 +0100 Subject: [PATCH 4/4] Deleting duplicate directory --- .../Channel/VIPs/ChannelVipAddHandler.cs | 37 ------------------- .../Channel/VIPs/ChannelVipRemoveHandler.cs | 37 ------------------- 2 files changed, 74 deletions(-) delete mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs delete mode 100644 TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs deleted file mode 100644 index 1b11576..0000000 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipAddHandler.cs +++ /dev/null @@ -1,37 +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.Vips -{ - /// - /// Handler for 'channel.vip.add' notifications - /// - public class ChannelVipAddHandler : INotificationHandler - { - /// - public string SubscriptionType => "channel.vip.add"; - - /// - 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("ChannelVipAdd", new ChannelVipArgs { 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 diff --git a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs b/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs deleted file mode 100644 index 34bb979..0000000 --- a/TwitchLib.EventSub.Websockets/Handler/Channel/VIPs/ChannelVipRemoveHandler.cs +++ /dev/null @@ -1,37 +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.Vips -{ - /// - /// Handler for 'channel.vip.remove' notifications - /// - public class ChannelVipRemoveHandler : INotificationHandler - { - /// - public string SubscriptionType => "channel.vip.remove"; - - /// - 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("ChannelVipRemove", new ChannelVipArgs { 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