Skip to content

Add support for ChannelChatMessageDelete and ChannelChatNotification #51

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

Merged
merged 2 commits into from
May 14, 2025
Merged
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,8 @@
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
using TwitchLib.EventSub.Websockets.Core.Models;
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel
{
public class ChannelChatMessageDeleteArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelChatMessageDelete>>
{
}
}
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 ChannelChatNotificationArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelChatNotification>>
{
}
}
8 changes: 8 additions & 0 deletions TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
/// <summary>
/// Event that triggers on "channel.ad_break.begin" notifications
/// </summary>
public event AsyncEventHandler<ChannelAdBreakBeginArgs> ChannelAdBreakBegin;

Check warning on line 52 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelAdBreakBegin' is never used

/// <summary>
/// Event that triggers on "channel.ban" notifications
Expand Down Expand Up @@ -77,6 +77,14 @@
/// </summary>
public event AsyncEventHandler<ChannelChatMessageArgs> ChannelChatMessage;
/// <summary>
/// Event that triggers on "channel.chat.message_delete" notifications
/// </summary>
public event AsyncEventHandler<ChannelChatMessageDeleteArgs> ChannelChatMessageDelete;
/// <summary>
/// Event that triggers on "channel.chat.notification" notifications
/// </summary>
public event AsyncEventHandler<ChannelChatNotificationArgs> ChannelChatNotification;
/// <summary>
/// Event that triggers on "channel.cheer" notifications
/// </summary>
public event AsyncEventHandler<ChannelCheerArgs> ChannelCheer;
Expand All @@ -101,7 +109,7 @@
/// <summary>
/// Event that triggers on "channel.guest_star_guest.update" notifications
/// </summary>
public event AsyncEventHandler<ChannelGuestStarGuestUpdateArgs> ChannelGuestStarGuestUpdate;

Check warning on line 112 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelGuestStarGuestUpdate' is never used
/// <summary>
/// Event that triggers on "channel.guest_star_session.begin" notifications
/// </summary>
Expand All @@ -117,7 +125,7 @@
/// <summary>
/// Event that triggers on "channel.guest_star_slot.update" notifications
/// </summary>
public event AsyncEventHandler<ChannelGuestStarSlotUpdateArgs> ChannelGuestStarSlotUpdate;

Check warning on line 128 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelGuestStarSlotUpdate' is never used

/// <summary>
/// Event that triggers on "channel.hype_train.begin" notifications
Expand All @@ -130,7 +138,7 @@
/// <summary>
/// Event that triggers on "channel.hype_train.progress" notifications
/// </summary>
public event AsyncEventHandler<ChannelHypeTrainProgressArgs> ChannelHypeTrainProgress;

Check warning on line 141 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelHypeTrainProgress' is never used

Check warning on line 141 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelHypeTrainProgress' is never used

/// <summary>
/// Event that triggers on "channel.moderator.add" notifications
Expand All @@ -144,7 +152,7 @@
/// <summary>
/// Event that triggers on "channel.vip.add" notifications
/// </summary>
public event AsyncEventHandler<ChannelVipArgs> ChannelVipAdd;

Check warning on line 155 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelVipAdd' is never used
/// <summary>
/// Event that triggers on "channel.vip.remove" notifications
/// </summary>
Expand All @@ -161,7 +169,7 @@
/// <summary>
/// Event that triggers on "channel.channel_points_custom_reward.update" notifications
/// </summary>
public event AsyncEventHandler<ChannelPointsCustomRewardArgs> ChannelPointsCustomRewardUpdate;

Check warning on line 172 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelPointsCustomRewardUpdate' is never used

/// <summary>
/// Event that triggers on "channel.channel_points_automatic_reward_redemption.add" notifications
Expand Down Expand Up @@ -197,7 +205,7 @@
/// <summary>
/// Event that triggers on "channel.prediction.end" notifications
/// </summary>
public event AsyncEventHandler<ChannelPredictionEndArgs> ChannelPredictionEnd;

Check warning on line 208 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelPredictionEnd' is never used
/// <summary>
/// Event that triggers on "channel.prediction.lock" notifications
/// </summary>
Expand Down Expand Up @@ -265,7 +273,7 @@
/// <summary>
/// Event that triggers on "channel.warning.send" notifications
/// </summary>
public event AsyncEventHandler<ChannelWarningSendArgs> ChannelWarningSend;

Check warning on line 276 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.ChannelWarningSend' is never used

/// <summary>
/// Event that triggers on "channel.unban" notifications
Expand All @@ -289,7 +297,7 @@
/// <summary>
/// Event that triggers on "user.update" notifications
/// </summary>
public event AsyncEventHandler<UserUpdateArgs> UserUpdate;

Check warning on line 300 in TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

View workflow job for this annotation

GitHub Actions / check-buildstatus

The event 'EventSubWebsocketClient.UserUpdate' is never used

/// <summary>
/// Event that triggers on "user.whisper.message" notifications
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.Chat
{
public class ChatMessageDeleteHandler : INotificationHandler
{
public string SubscriptionType => "channel.chat.message_delete";

public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelChatMessageDelete>>(jsonString.AsSpan(), serializerOptions);
if (data is null)
throw new InvalidOperationException("Parsed JSON cannot be null!");
client.RaiseEvent("ChannelChatMessageDelete", new ChannelChatMessageDeleteArgs { 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,30 @@
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.Chat
{
public class ChatNotificationHandler : INotificationHandler
{
public string SubscriptionType => "channel.chat.notification";

public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelChatNotification>>(jsonString.AsSpan(), serializerOptions);
if (data is null)
throw new InvalidOperationException("Parsed JSON cannot be null!");
client.RaiseEvent("ChannelChatNotification", new ChannelChatNotificationArgs { Notification = data });
}
catch (Exception ex)
{
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" });
}
}
}
}