Skip to content

Commit

Permalink
Merge pull request #26 from Hampo/dev
Browse files Browse the repository at this point in the history
Channel VIP Events
  • Loading branch information
swiftyspiffy authored Apr 22, 2024
2 parents cf9adcd + d09b926 commit c5a0a14
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
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

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelVipArgs.cs

View workflow job for this annotation

GitHub Actions / release-preview

The type or namespace name 'ChannelVip' could not be found (are you missing a using directive or an assembly reference?)
{ }
}
9 changes: 9 additions & 0 deletions TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public class EventSubWebsocketClient
/// </summary>
public event AsyncEventHandler<ChannelModeratorArgs> ChannelModeratorRemove;

/// <summary>
/// Event that triggers on "channel.vip.add" notifications
/// </summary>
public event AsyncEventHandler<ChannelVipArgs> ChannelVipAdd;
/// <summary>
/// Event that triggers on "channel.vip.remove" notifications
/// </summary>
public event AsyncEventHandler<ChannelVipArgs> ChannelVipRemove;

/// <summary>
/// Event that triggers on "channel.channel_points_custom_reward.add" notifications
/// </summary>
Expand Down
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}" });
}
}
}
}

0 comments on commit c5a0a14

Please sign in to comment.