Skip to content

Commit

Permalink
Add Channel Warning related handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hampo committed Nov 5, 2024
1 parent 129f195 commit e78808b
Show file tree
Hide file tree
Showing 5 changed files with 100 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 ChannelWarningAcknowledgeArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelWarningAcknowledge>>
{ }
}
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 ChannelWarningSendArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelWarningSend>>
{ }
}
10 changes: 10 additions & 0 deletions TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ public class EventSubWebsocketClient
/// </summary>
public event AsyncEventHandler<ChannelSuspiciousUserUpdateArgs> ChannelSuspiciousUserUpdate;

/// <summary>
/// Event that triggers on "channel.warning.acknowledge" notifications
/// </summary>
public event AsyncEventHandler<ChannelWarningAcknowledgeArgs> ChannelWarningAcknowledge;

/// <summary>
/// Event that triggers on "channel.warning.send" notifications
/// </summary>
public event AsyncEventHandler<ChannelWarningSendArgs> ChannelWarningSend;

/// <summary>
/// Event that triggers on "channel.unban" 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.Warning
{
/// <summary>
/// Handler for 'channel.warning.acknowledge' notifications
/// </summary>
public class ChannelWarningAcknowledgeHandler : INotificationHandler
{
/// <inheritdoc />
public string SubscriptionType => "channel.warning.acknowledge";

/// <inheritdoc />
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelWarningAcknowledge>>(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}" });
}
}
}
}
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.Warning
{
/// <summary>
/// Handler for 'channel.warning.send' notifications
/// </summary>
public class ChannelWarningSendHandler : INotificationHandler
{
/// <inheritdoc />
public string SubscriptionType => "channel.warning.send";

/// <inheritdoc />
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelWarningSend>>(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}" });
}
}
}
}

0 comments on commit e78808b

Please sign in to comment.