Skip to content

Commit 532b5cd

Browse files
authored
Merge pull request #52 from iryis/dev
Add support for Shared Chat
2 parents 7f9f259 + c3c2f75 commit 532b5cd

7 files changed

+150
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
2+
using TwitchLib.EventSub.Websockets.Core.Models;
3+
4+
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel
5+
{
6+
public class ChannelSharedChatSessionBeginArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelSharedChatSessionBegin>>
7+
{ }
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
2+
using TwitchLib.EventSub.Websockets.Core.Models;
3+
4+
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel
5+
{
6+
public class ChannelSharedChatSessionEndArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelSharedChatSessionEnd>>
7+
{ }
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
2+
using TwitchLib.EventSub.Websockets.Core.Models;
3+
4+
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel
5+
{
6+
public class ChannelSharedChatSessionUpdateArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelSharedChatSessionUpdate>>
7+
{ }
8+
}

TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,21 @@ public class EventSubWebsocketClient
303303
/// Event that triggers on "user.whisper.message" notifications
304304
/// </summary>
305305
public event AsyncEventHandler<UserWhisperMessageArgs> UserWhisperMessage;
306+
307+
/// <summary>
308+
/// Event that triggers on "channel.shared_chat.begin" notifications
309+
/// </summary>
310+
public event AsyncEventHandler<ChannelSharedChatSessionBeginArgs> ChannelSharedChatSessionBegin;
311+
312+
/// <summary>
313+
/// Event that triggers on "channel.shared_chat.update" notifications
314+
/// </summary>
315+
public event AsyncEventHandler<ChannelSharedChatSessionUpdateArgs> ChannelSharedChatSessionUpdate;
316+
317+
/// <summary>
318+
/// Event that triggers on "channel.shared_chat.end" notifications
319+
/// </summary>
320+
public event AsyncEventHandler<ChannelSharedChatSessionEndArgs> ChannelSharedChatSessionEnd;
306321

307322
#endregion
308323

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text.Json;
3+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
4+
using TwitchLib.EventSub.Websockets.Core.EventArgs;
5+
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
6+
using TwitchLib.EventSub.Websockets.Core.Handler;
7+
using TwitchLib.EventSub.Websockets.Core.Models;
8+
9+
namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat
10+
{
11+
/// <summary>
12+
/// Handler for 'channel.shared_chat.begin' notifications
13+
/// </summary>
14+
public class ChannelSharedChatSessionBeginHandler : INotificationHandler
15+
{
16+
/// <inheritdoc />
17+
public string SubscriptionType => "channel.shared_chat.begin";
18+
19+
/// <inheritdoc />
20+
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
21+
{
22+
try
23+
{
24+
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelSharedChatSessionBegin>>(jsonString.AsSpan(), serializerOptions);
25+
26+
if (data is null)
27+
throw new InvalidOperationException("Parsed JSON cannot be null!");
28+
29+
client.RaiseEvent("ChannelSharedChatSessionBegin", new ChannelSharedChatSessionBeginArgs { Notification = data });
30+
}
31+
catch (Exception ex)
32+
{
33+
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.begin notification! Raw Json: {jsonString}" });
34+
}
35+
}
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text.Json;
3+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
4+
using TwitchLib.EventSub.Websockets.Core.EventArgs;
5+
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
6+
using TwitchLib.EventSub.Websockets.Core.Handler;
7+
using TwitchLib.EventSub.Websockets.Core.Models;
8+
9+
namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat
10+
{
11+
/// <summary>
12+
/// Handler for 'channel.shared_chat.end' notifications
13+
/// </summary>
14+
public class ChannelSharedChatSessionEndHandler : INotificationHandler
15+
{
16+
/// <inheritdoc />
17+
public string SubscriptionType => "channel.shared_chat.end";
18+
19+
/// <inheritdoc />
20+
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
21+
{
22+
try
23+
{
24+
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelSharedChatSessionEnd>>(jsonString.AsSpan(), serializerOptions);
25+
26+
if (data is null)
27+
throw new InvalidOperationException("Parsed JSON cannot be null!");
28+
29+
client.RaiseEvent("ChannelSharedChatSessionEnd", new ChannelSharedChatSessionEndArgs { Notification = data });
30+
}
31+
catch (Exception ex)
32+
{
33+
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.end notification! Raw Json: {jsonString}" });
34+
}
35+
}
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Text.Json;
3+
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel;
4+
using TwitchLib.EventSub.Websockets.Core.EventArgs;
5+
using TwitchLib.EventSub.Websockets.Core.EventArgs.Channel;
6+
using TwitchLib.EventSub.Websockets.Core.Handler;
7+
using TwitchLib.EventSub.Websockets.Core.Models;
8+
9+
namespace TwitchLib.EventSub.Websockets.Handler.Channel.SharedChat
10+
{
11+
/// <summary>
12+
/// Handler for 'channel.shared_chat.update' notifications
13+
/// </summary>
14+
public class ChannelSharedChatSessionUpdateHandler : INotificationHandler
15+
{
16+
/// <inheritdoc />
17+
public string SubscriptionType => "channel.shared_chat.update";
18+
19+
/// <inheritdoc />
20+
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
21+
{
22+
try
23+
{
24+
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelSharedChatSessionUpdate>>(jsonString.AsSpan(), serializerOptions);
25+
26+
if (data is null)
27+
throw new InvalidOperationException("Parsed JSON cannot be null!");
28+
29+
client.RaiseEvent("ChannelSharedChatSessionUpdate", new ChannelSharedChatSessionUpdateArgs { Notification = data });
30+
}
31+
catch (Exception ex)
32+
{
33+
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle channel.shared_chat.update notification! Raw Json: {jsonString}" });
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)