Skip to content

Added ChannelModerate #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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}" });
}
}
}