Skip to content

Commit

Permalink
fix(plugins): remove filter advanced mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Oct 6, 2022
1 parent 4c5157c commit 9b7ae4b
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/plugins/nodes/filter.ts
@@ -1,27 +1,10 @@
import { itemsToEvalPart } from '@sogebot/ui-helpers/queryFilter';
import { VM } from 'vm2';

import type { Node } from '~/../d.ts/src/plugins';
import { error } from '~/helpers/log';

export default async function(pluginId: string, currentNode: Node<string>, parameters: Record<string, any>, variables: Record<string, any>, userstate: { userName: string; userId: string; } | null) {
const advancedMode = JSON.parse(currentNode.data.data).advancedMode ?? false;

let script = null;

if (advancedMode) {
script = currentNode.data.value;
} else {
const filter = currentNode.data.value
? JSON.parse(currentNode.data.value) : null;
if (filter && filter.items.length > 0) {
script = itemsToEvalPart(filter.items, filter.operator);
}
}

if (!script) {
return false;
}
const script = currentNode.data.value;
try {
const sandbox = {
sender: userstate ? {
Expand All @@ -32,7 +15,8 @@ export default async function(pluginId: string, currentNode: Node<string>, param
...variables,
};
const vm = new VM({ sandbox });
const result = vm.run(`(function () { return ${script} })`)();

const result = vm.run(`(function () { ${script} })`)();
return !!result;
} catch (e) {
error(`PLUGINS#${pluginId}: ${(e as Error).stack}`);
Expand Down

0 comments on commit 9b7ae4b

Please sign in to comment.