Skip to content

Commit

Permalink
feat: Raid Sent Off Event (#2767)
Browse files Browse the repository at this point in the history
* Added Raid Sent Off Event

* Changed name of incoming and outgoing raid
Changed description of raid outgoing completed
Changed icon for raids in activity manager
Changed filter description for raid viewer count

* Adjusting names to and icons of event.

---------

Co-authored-by: Erik Bigler <[email protected]>
  • Loading branch information
karrbs and ebiggz authored Sep 13, 2024
1 parent d1cf9c1 commit aec4eed
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 65 deletions.
197 changes: 148 additions & 49 deletions src/backend/events/builtin/twitch-event-source.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/backend/events/filters/builtin/raid-viewer-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const { ComparisonType } = require("../../../../shared/filter-constants");
module.exports = {
id: "firebot:raid-viewer-count",
name: "Raid Viewer Count",
description: "Filter by how many viewers have been brought over by the raid.",
description: "Filter by how many viewers have been brought or are being sent over by the raid.",
events: [
{ eventSourceId: "twitch", eventId: "raid" }
{ eventSourceId: "twitch", eventId: "raid" },
{ eventSourceId: "twitch", eventId: "raid-sent-off" }
],
comparisonTypes: [
ComparisonType.IS,
Expand All @@ -19,7 +20,6 @@ module.exports = {
],
valueType: "number",
predicate: (filterSettings, eventData) => {

const { comparisonType, value } = filterSettings;
const { eventMeta } = eventData;

Expand Down Expand Up @@ -48,4 +48,4 @@ module.exports = {
return false;
}
}
};
};
21 changes: 20 additions & 1 deletion src/backend/events/twitch-events/raid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import eventManager from "../../events/EventManager";

export function triggerRaid(
export function triggerIncomingRaid(
username: string,
userId: string,
userDisplayName: string,
Expand All @@ -12,4 +12,23 @@ export function triggerRaid(
userDisplayName,
viewerCount
});
}
export function triggerRaidSentOff(
username: string,
userId: string,
userDisplayName: string,
raidTargetUsername: string,
raidTargetUserId: string,
raidTargetUserDisplayName: string,
viewerCount = 0
): void {
eventManager.triggerEvent("twitch", "raid-sent-off", {
username,
userId,
userDisplayName,
raidTargetUsername,
raidTargetUserId,
raidTargetUserDisplayName,
viewerCount
});
}
25 changes: 21 additions & 4 deletions src/backend/twitch-api/eventsub/eventsub-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,33 @@ class TwitchEventSubClient {
});
this._subscriptions.push(customRewardRedemptionUpdateSubscription);

// Raid
const raidSubscription = this._eventSubListener.onChannelRaidTo(streamer.userId, (event) => {
twitchEventsHandler.raid.triggerRaid(
// Incoming Raid
const incomingRaidSubscription = this._eventSubListener.onChannelRaidTo(streamer.userId, (event) => {
twitchEventsHandler.raid.triggerIncomingRaid(
event.raidingBroadcasterName,
event.raidingBroadcasterId,
event.raidingBroadcasterDisplayName,
event.viewers
);
});
this._subscriptions.push(raidSubscription);
this._subscriptions.push(incomingRaidSubscription);

// Outbound Raid Sent Off
const outboundRaidSubscription = this._eventSubListener.onChannelRaidFrom(streamer.userId, (event) => {
// sent off
if (event.raidingBroadcasterId === streamer.userId && event.raidedBroadcasterId !== streamer.userId) {
twitchEventsHandler.raid.triggerRaidSentOff(
event.raidingBroadcasterName,
event.raidingBroadcasterId,
event.raidingBroadcasterDisplayName,
event.raidedBroadcasterName,
event.raidedBroadcasterId,
event.raidedBroadcasterDisplayName,
event.viewers
);
}
});
this._subscriptions.push(outboundRaidSubscription);

// Shoutout sent to another channel
const shoutoutSentSubscription = this._eventSubListener.onChannelShoutoutCreate(streamer.userId, streamer.userId, (event) => {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/variables/builtin/twitch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import charityVariables from './charity';
import cheerVariables from './cheer';
import cheermoteVariables from './cheermote';
import hypetrainVariables from './hype-train';
import raidVariables from './raid';
import rewardVariables from './reward';
import streamVariables from './stream';
import subVariables from './subs';
Expand All @@ -14,7 +15,6 @@ import followCount from './follow-count';
import pollWinningChoiceName from './poll-winning-choice-name';
import pollWinningChoiceVotes from './poll-winning-choice-votes';
import predictionWinningOutcomeName from './prediction-winning-outcome-name';
import raidViewerCounter from './raid-viewer-count';
import twitchChannelUrl from './twitch-channel-url';
import viewerCount from './viewer-count';

Expand All @@ -27,6 +27,7 @@ export default [
...cheerVariables,
...cheermoteVariables,
...hypetrainVariables,
...raidVariables,
...rewardVariables,
...streamVariables,
...subVariables,
Expand All @@ -36,7 +37,6 @@ export default [
pollWinningChoiceName,
pollWinningChoiceVotes,
predictionWinningOutcomeName,
raidViewerCounter,
twitchChannelUrl,
viewerCount
];
11 changes: 11 additions & 0 deletions src/backend/variables/builtin/twitch/raid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import raidViewerCount from './raid-viewer-count';
import raidTargetUserDisplayName from './raid-target-user-display-name';
import raidTargetUserId from './raid-target-user-id';
import raidTargetUsername from './raid-target-username';

export default [
raidViewerCount,
raidTargetUserDisplayName,
raidTargetUsername,
raidTargetUserId
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ReplaceVariable } from "../../../../../types/variables";
import { OutputDataType, VariableCategory } from "../../../../../shared/variable-constants";
import { EffectTrigger } from "../../../../../shared/effect-constants";

const triggers = {};
triggers[EffectTrigger.EVENT] = ["twitch:raid-sent-off"];
triggers[EffectTrigger.MANUAL] = true;

const model : ReplaceVariable = {
definition: {
handle: "raidTargetUserDisplayName",
description: "Gets the formatted display name for the raid target",
triggers: triggers,
categories: [VariableCategory.USER],
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (trigger) => {
return trigger.metadata.eventData?.raidTargetUserDisplayName ?? "";
}
};

export default model;
22 changes: 22 additions & 0 deletions src/backend/variables/builtin/twitch/raid/raid-target-user-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ReplaceVariable } from "../../../../../types/variables";
import { OutputDataType, VariableCategory } from "../../../../../shared/variable-constants";
import { EffectTrigger } from "../../../../../shared/effect-constants";

const triggers = {};
triggers[EffectTrigger.EVENT] = ["twitch:raid-sent-off"];
triggers[EffectTrigger.MANUAL] = true;

const model : ReplaceVariable = {
definition: {
handle: "raidTargetUserId",
description: "Gets the user ID for the raid target.",
triggers: triggers,
categories: [VariableCategory.USER],
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: async (trigger) => {
return trigger.metadata.eventData?.raidTargetUserId ?? "";
}
};

export default model;
23 changes: 23 additions & 0 deletions src/backend/variables/builtin/twitch/raid/raid-target-username.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ReplaceVariable, Trigger } from "../../../../../types/variables";
import { OutputDataType, VariableCategory } from "../../../../../shared/variable-constants";

import { EffectTrigger } from "../../../../../shared/effect-constants";

const triggers = {};
triggers[EffectTrigger.EVENT] = ["twitch:raid-sent-off"];
triggers[EffectTrigger.MANUAL] = true;

const model : ReplaceVariable = {
definition: {
handle: "raidTargetUsername",
description: "The associated user (if there is one) for the given trigger",
triggers: triggers,
categories: [VariableCategory.COMMON, VariableCategory.USER],
possibleDataOutput: [OutputDataType.TEXT]
},
evaluator: (trigger: Trigger) => {
return trigger.metadata.eventData?.raidTargetUsername;
}
};

export default model;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ReplaceVariable } from "../../../../types/variables";
import { OutputDataType, VariableCategory } from "../../../../shared/variable-constants";
import { EffectTrigger } from "../../../../shared/effect-constants";
import { ReplaceVariable } from "../../../../../types/variables";
import { OutputDataType, VariableCategory } from "../../../../../shared/variable-constants";
import { EffectTrigger } from "../../../../../shared/effect-constants";

const triggers = {};
triggers[EffectTrigger.EVENT] = ["twitch:raid"];
triggers[EffectTrigger.EVENT] = ["twitch:raid", "twitch:raid-sent-off"];
triggers[EffectTrigger.MANUAL] = true;


Expand All @@ -16,7 +16,7 @@ const model : ReplaceVariable = {
possibleDataOutput: [OutputDataType.NUMBER]
},
evaluator: async (trigger) => {
return trigger.metadata.eventData.viewerCount || 0;
return trigger.metadata.eventData?.viewerCount || 0;
}
};

Expand Down
1 change: 1 addition & 0 deletions src/gui/app/services/settings.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
const events = getDataFromFile("/settings/allowedActivityEvents");
return events == null ? [
"twitch:raid",
"twitch:raid-sent-off",
"twitch:follow",
"twitch:sub",
"twitch:subs-gifted",
Expand Down

0 comments on commit aec4eed

Please sign in to comment.