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

Open
wants to merge 3 commits 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,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 @@ -77,6 +77,14 @@ public class EventSubWebsocketClient
/// </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 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}" });
}
}
}
}