Skip to content

Commit

Permalink
Merge pull request #117 from pilky/raid-cancel-events
Browse files Browse the repository at this point in the history
Add support for raid_cancel_v2 event
  • Loading branch information
Syzuna authored Apr 28, 2023
2 parents 9b12b32 + 273fd50 commit 658e305
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion TwitchLib.PubSub/Enums/RaidType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public enum RaidType
/// <summary>
/// When the raid actually starts
/// </summary>
RaidGo
RaidGo,
/// <summary>
/// When the raid is cancelled
/// </summary>
RaidCancel
}
}
38 changes: 38 additions & 0 deletions TwitchLib.PubSub/Events/OnRaidCancelArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;

namespace TwitchLib.PubSub.Events {
/// <inheritdoc />
/// <summary>
/// Object representing the arguments for a raid cancel event
/// </summary>
public class OnRaidCancelArgs: EventArgs {
/// <summary>
/// The channel ID the event came from
/// </summary>
public string ChannelId;
/// <summary>
/// Property representing the id of the raid event
/// </summary>
public Guid Id;
/// <summary>
/// Property representing the target channel id
/// </summary>
public string TargetChannelId;
/// <summary>
/// Property representing the target channel login
/// </summary>
public string TargetLogin;
/// <summary>
/// Property representing the target display name
/// </summary>
public string TargetDisplayName;
/// <summary>
/// Property representing the target profile image url
/// </summary>
public string TargetProfileImage;
/// <summary>
/// Property representing the count of people in the raid
/// </summary>
public int ViewerCount;
}
}
12 changes: 12 additions & 0 deletions TwitchLib.PubSub/Models/Responses/Messages/RaidEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public RaidEvents(string jsonStr)
case "raid_go_v2":
Type = RaidType.RaidGo;
break;
case "raid_cancel_v2":
Type = RaidType.RaidCancel;
break;

}

Expand Down Expand Up @@ -118,6 +121,15 @@ public RaidEvents(string jsonStr)
TargetProfileImage = json.SelectToken("raid.target_profile_image").ToString();
ViewerCount = int.Parse(json.SelectToken("raid.viewer_count").ToString());
break;
case RaidType.RaidCancel:
Id = Guid.Parse(json.SelectToken("raid.id").ToString());
ChannelId = json.SelectToken("raid.source_id").ToString();
TargetChannelId = json.SelectToken("raid.target_id").ToString();
TargetLogin = json.SelectToken("raid.target_login").ToString();
TargetDisplayName = json.SelectToken("raid.target_display_name").ToString();
TargetProfileImage = json.SelectToken("raid.target_profile_image").ToString();
ViewerCount = int.Parse(json.SelectToken("raid.viewer_count").ToString());
break;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions TwitchLib.PubSub/TwitchPubSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public class TwitchPubSub : ITwitchPubSub
public event EventHandler<OnRaidGoArgs> OnRaidGo;
/// <inheritdoc />
/// <summary>
/// Fires when PubSub receives notice when a channel cancels the raid
/// </summary>
public event EventHandler<OnRaidCancelArgs> OnRaidCancel;
/// <inheritdoc />
/// <summary>
/// Fires when PubSub receives any data from Twitch
/// </summary>
public event EventHandler<OnLogArgs> OnLog;
Expand Down Expand Up @@ -647,6 +652,9 @@ private void ParseMessage(string message)
case RaidType.RaidGo:
OnRaidGo?.Invoke(this, new OnRaidGoArgs { Id = r.Id, ChannelId = r.ChannelId, TargetChannelId = r.TargetChannelId, TargetLogin = r.TargetLogin, TargetDisplayName = r.TargetDisplayName, TargetProfileImage = r.TargetProfileImage, ViewerCount = r.ViewerCount });
return;
case RaidType.RaidCancel:
OnRaidCancel?.Invoke(this, new OnRaidCancelArgs() { Id = r.Id, ChannelId = r.ChannelId, TargetChannelId = r.TargetChannelId, TargetLogin = r.TargetLogin, TargetDisplayName = r.TargetDisplayName, TargetProfileImage = r.TargetProfileImage, ViewerCount = r.ViewerCount });
return;
}
return;
case "predictions-channel-v1":
Expand Down

0 comments on commit 658e305

Please sign in to comment.