-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelAdBreakBeginArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ChannelAdBreakBeginArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelAdBreakBegin>> | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelChatMessageArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using TwitchLib.EventSub.Core.SubscriptionTypes.Channel; | ||
using TwitchLib.EventSub.Websockets.Core.Models; | ||
|
||
namespace TwitchLib.EventSub.Websockets.Core.EventArgs.Channel | ||
{ | ||
public class ChannelChatMessageArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelChatMessage>> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
TwitchLib.EventSub.Websockets/Handler/Channel/Ads/AdBreakBeginHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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.Ads | ||
{ | ||
/// <summary> | ||
/// Handler for 'channel.ad_break.begin' notifications | ||
/// </summary> | ||
public class AdBreakBeginHandler : INotificationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public string SubscriptionType => "channel.ad_break.begin"; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelAdBreakBegin>>(jsonString.AsSpan(), serializerOptions); | ||
if (data is null) | ||
throw new InvalidOperationException("Parsed JSON cannot be null!"); | ||
client.RaiseEvent("ChannelAdBreakBegin", new ChannelAdBreakBeginArgs { Notification = data }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
TwitchLib.EventSub.Websockets/Handler/Channel/ChatMessageHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
public class ChatMessageHandler : INotificationHandler | ||
{ | ||
public string SubscriptionType => "channel.chat.message"; | ||
|
||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelChatMessage>>(jsonString.AsSpan(), serializerOptions); | ||
if (data is null) | ||
throw new InvalidOperationException("Parsed JSON cannot be null!"); | ||
client.RaiseEvent("ChannelChatMessage", new ChannelChatMessageArgs { Notification = data }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters