Skip to content

Commit

Permalink
Merge pull request #43 from AoshiW/WhisperReceived
Browse files Browse the repository at this point in the history
add `Whisper Received`
  • Loading branch information
Mahsaap authored Nov 5, 2024
2 parents cde682a + 8942f6c commit 129f195
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using TwitchLib.EventSub.Core.SubscriptionTypes.User;
using TwitchLib.EventSub.Websockets.Core.Models;

namespace TwitchLib.EventSub.Websockets.Core.EventArgs.User
{
public class UserWhisperMessageArgs : TwitchLibEventSubEventArgs<EventSubNotification<UserWhisperMessage>>
{ }
}
5 changes: 5 additions & 0 deletions TwitchLib.EventSub.Websockets/EventSubWebsocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ public class EventSubWebsocketClient
/// </summary>
public event AsyncEventHandler<UserUpdateArgs> UserUpdate;

/// <summary>
/// Event that triggers on "user.whisper.message" notifications
/// </summary>
public event AsyncEventHandler<UserWhisperMessageArgs> UserWhisperMessage;

#endregion

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions TwitchLib.EventSub.Websockets/Handler/User/UserUpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,31 @@ public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerial
client.RaiseEvent("ErrorOccurred", new ErrorOccuredArgs { Exception = ex, Message = $"Error encountered while trying to handle {SubscriptionType} notification! Raw Json: {jsonString}" });
}
}
}
/// <summary>
/// Handler for 'user.whisper.message' notifications
/// </summary>
public class UserWhisperMessageHandler : INotificationHandler
{
/// <inheritdoc />
public string SubscriptionType => "user.whisper.message";

/// <inheritdoc />
public void Handle(EventSubWebsocketClient client, string jsonString, JsonSerializerOptions serializerOptions)
{
try
{
var data = JsonSerializer.Deserialize<EventSubNotification<UserWhisperMessage>>(jsonString.AsSpan(), serializerOptions);

if (data is null)
throw new InvalidOperationException("Parsed JSON cannot be null!");

client.RaiseEvent("UserWhisperMessage", new UserWhisperMessageArgs { 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
Expand Up @@ -30,7 +30,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="TwitchLib.EventSub.Core" Version="2.5.3-preview-d80beed" />
<PackageReference Include="TwitchLib.EventSub.Core" Version="2.5.3-preview-ce9df77" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down

0 comments on commit 129f195

Please sign in to comment.