-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
Channel VIP Events
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EventSubNotification<ChannelVip>> | ||
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs GitHub Actions / release-preview
|
||
{ } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Handler for 'channel.vip.add' notifications | ||
/// </summary> | ||
public class ChannelVipAddHandler : INotificationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public string SubscriptionType => "channel.vip.add"; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelVip>>(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}" }); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Handler for 'channel.vip.remove' notifications | ||
/// </summary> | ||
public class ChannelVipRemoveHandler : INotificationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public string SubscriptionType => "channel.vip.remove"; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelVip>>(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}" }); | ||
} | ||
} | ||
} | ||
} |