Skip to content

Commit

Permalink
Merge branch 'v5' into v5-fix-quote-searchdate
Browse files Browse the repository at this point in the history
  • Loading branch information
CKY- authored Dec 20, 2024
2 parents 118cbff + 9c1d50b commit c54b16a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 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;
8 changes: 3 additions & 5 deletions src/backend/events/filters/filter-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ export function createPresetFilter({
comparisonTypes.push(ComparisonType.IS_NOT);
}

const valueDisplay = getSelectedValueDisplay ?? (async (filterSettings, $injector: auto.IInjectorService) => {
return (await $injector.invoke(presetValues, {}, {}))
const valueDisplay = getSelectedValueDisplay ?? (async (filterSettings, filterType: any, $injector: auto.IInjectorService) => {
return (await $injector.invoke(filterType.getPresetValues, {}, {}))
.find(pv => pv.value === filterSettings.value)?.display ?? "[Not Set]";
});

Expand All @@ -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
7 changes: 7 additions & 0 deletions src/gui/app/directives/controls/dynamic-parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@
ctrl.metadata.value = ctrl.metadata.options[0];
}
}

// If it is a boolean and no default is supplied, set to false
if (ctrl.metadata.type === "boolean") {
if (ctrl.metadata.default == null) {
ctrl.metadata.value = false;
}
}
}

console.log(ctrl.metadata);
Expand Down
3 changes: 2 additions & 1 deletion src/gui/app/directives/filters/filterDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
resolve("[Not Set]");
} else {
const value = await $injector.invoke($ctrl.filterType.getSelectedValueDisplay, {}, {
filterSettings: $ctrl.filter
filterSettings: $ctrl.filter,
filterType: $ctrl.filterType
});
resolve(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@

const eventSource = await backendCommunicator.fireEventAsync("getEventSource", event);
if (eventSource.manualMetadata) {
$ctrl.metadata = Object.keys(eventSource.manualMetadata).map(mmd => {
$ctrl.metadata = Object.keys(eventSource.manualMetadata).map((mmd) => {
const meta = eventSource.manualMetadata[mmd];
const dataType = meta == null ? "string" : meta.type || typeof meta;
const data = {
key: mmd,
title: getTitle(mmd),
type: dataType,
value: dataType !== "enum" ? meta : undefined,
options: meta?.options || {}
};

Expand Down

0 comments on commit c54b16a

Please sign in to comment.