Skip to content

Commit

Permalink
feat(events): add custom variables to filters
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed May 15, 2019
1 parent 39b6983 commit c35e5e3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/bot/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ class Events extends Core {
public async checkFilter(eventId, attributes) {
const filter = (await global.db.engine.findOne('events.filters', { eventId })).filters;
if (typeof filter === 'undefined' || filter.trim().length === 0) { return true; }

// get custom variables
const customVariablesDb = await global.db.engine.find('custom.variables');
const customVariables = {};
for (const cvar of customVariablesDb) {
customVariables[cvar.variableName] = cvar.currentValue;
}

const toEval = `(function evaluation () { return ${filter} })()`;
const context = {
_,
Expand Down Expand Up @@ -467,6 +475,7 @@ class Events extends Core {
$followers: _.get(await global.db.engine.findOne('api.current', { key: 'followers' }), 'value', 0),
$hosts: _.get(await global.db.engine.findOne('api.current', { key: 'hosts' }), 'value', 0),
$subscribers: _.get(await global.db.engine.findOne('api.current', { key: 'subscribers' }), 'value', 0),
...customVariables,
};
let result = false;
try {
Expand Down

0 comments on commit c35e5e3

Please sign in to comment.