Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
using TwitchLib.EventSub.Websockets.Core.Models;

namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;

/// <summary>
/// <see href="https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelmoderate-v2">Twitch Documentation</see><br/>
/// When a moderator performs a moderation action in a channel.<br/>
/// Required Scopes: Check documenation for full list<br/>
/// </summary>
public class ChannelModerateArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelModerate>>
{ }
12 changes: 8 additions & 4 deletions TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ public class EventSubWebsocketClient
/// </summary>
public event AsyncEventHandler<ChannelHypeTrainProgressArgs> ChannelHypeTrainProgress;

/// <summary>
/// Event that triggers on "channel.moderator.add" notifications
/// </summary>
public event AsyncEventHandler<ChannelModeratorArgs> ChannelModeratorAdd;
/// <summary>
/// Event that triggers on "channel.moderate" notifications
/// </summary>
public event AsyncEventHandler<ChannelModerateArgs> ChannelModerate;
/// <summary>
/// Event that triggers on "channel.moderator.add" notifications
/// </summary>
public event AsyncEventHandler<ChannelModeratorArgs> ChannelModeratorAdd;
/// <summary>
/// Event that triggers on "channel.moderator.remove" notifications
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.Moderation;

/// <summary>
/// Handler for 'channel.moderate' notifications
/// </summary>
public class ChannelModerateHandler : INotificationHandler
{
/// <inheritdoc />
public string SubscriptionType => "channel.moderate";

/// <inheritdoc />
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelModerate>>(jsonString.AsSpan(), serializerOptions);

if (data is null)
throw new InvalidOperationException("Parsed JSON cannot be null!");

client.RaiseEvent("ChannelModerate", new ChannelModerateArgs { Notification = data });
}
catch (Exception ex)
{
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" });
}
}
}