-
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.
Add
Channel Warning
related handlers
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningAcknowledgeArgs.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 ChannelWarningAcknowledgeArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelWarningAcknowledge>> | ||
{ } | ||
} |
8 changes: 8 additions & 0 deletions
8
TwitchLib.EventSub.Websockets/Core/EventArgs/Channel/ChannelWarningSendArgs.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 ChannelWarningSendArgs : TwitchLibEventSubEventArgs<EventSubNotification<ChannelWarningSend>> | ||
{ } | ||
} |
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
37 changes: 37 additions & 0 deletions
37
TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningAcknowledgeHandler.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,37 @@ | ||
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.Warning | ||
{ | ||
/// <summary> | ||
/// Handler for 'channel.warning.acknowledge' notifications | ||
/// </summary> | ||
public class ChannelWarningAcknowledgeHandler : INotificationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public string SubscriptionType => "channel.warning.acknowledge"; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelWarningAcknowledge>>(jsonString.AsSpan(), serializerOptions); | ||
|
||
if (data is null) | ||
throw new InvalidOperationException("Parsed JSON cannot be null!"); | ||
|
||
client.RaiseEvent("ChannelWarningAcknowledge", new ChannelWarningAcknowledgeArgs { Notification = data }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
TwitchLib.EventSub.Websockets/Handler/Channel/Warning/ChannelWarningSendHandler.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,37 @@ | ||
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.Warning | ||
{ | ||
/// <summary> | ||
/// Handler for 'channel.warning.send' notifications | ||
/// </summary> | ||
public class ChannelWarningSendHandler : INotificationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public string SubscriptionType => "channel.warning.send"; | ||
|
||
/// <inheritdoc /> | ||
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions) | ||
{ | ||
try | ||
{ | ||
var data = JsonSerializer.Deserialize<EventSubNotification<ChannelWarningSend>>(jsonString.AsSpan(), serializerOptions); | ||
|
||
if (data is null) | ||
throw new InvalidOperationException("Parsed JSON cannot be null!"); | ||
|
||
client.RaiseEvent("ChannelWarningSend", new ChannelWarningSendArgs { Notification = data }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" }); | ||
} | ||
} | ||
} | ||
} |