Skip to content

Commit

Permalink
fix: sub kind filter
Browse files Browse the repository at this point in the history
  • Loading branch information
zunderscore committed Dec 18, 2024
1 parent 63f2867 commit fdcbb41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
35 changes: 30 additions & 5 deletions src/backend/events/filters/builtin/twitch/sub-kind.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { createPresetFilter } from "../../filter-factory";
import { EventFilter } from "../../../../../types/events";
import { ComparisonType } from "../../../../../shared/filter-constants";

const filter = createPresetFilter({
const filter: EventFilter = {
id: "firebot:sub-kind",
name: "Kind of Sub",
description: "Filter by the kind of sub (resub vs first sub)",
events: [
{ eventSourceId: "twitch", eventId: "sub" }
],
eventMetaKey: "isResub",
comparisonTypes: [ComparisonType.IS],
valueType: "preset",
presetValues: () => [
{
value: "first",
Expand All @@ -17,7 +19,30 @@ const filter = createPresetFilter({
value: "resub",
display: "Resub"
}
]
});
],
getSelectedValueDisplay: (filterSettings) => {
switch (filterSettings.value) {
case "first":
return "First Sub";
case "resub":
return "Resub";
default:
return "[Not set]";
}
},
predicate: (filterSettings, eventData) => {
const { value } = filterSettings;
const { eventMeta } = eventData;

if (value == null) {
return true;
}

const isResub = eventMeta.isResub;
const expectingResub = value === "resub";

return isResub === expectingResub;
}
};

export default filter;
4 changes: 1 addition & 3 deletions src/backend/events/filters/filter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ export function createPresetFilter({

const data = extractPropertyWithPath(eventMeta, getMetaKey(eventMetaKey, eventData, filterSettings));

const output = data === value ||
(data === true && value === "true") ||
(data === false && value === "false");
const output = data === value || data.toString() === value;

return comparisonType === ComparisonType.IS ? output : !output;
}
Expand Down

0 comments on commit fdcbb41

Please sign in to comment.