Skip to content

Commit

Permalink
fix(cvars): force sender to be object (#2340)
Browse files Browse the repository at this point in the history
Fixes #2330
  • Loading branch information
sogehige committed Jun 27, 2019
1 parent 16a551e commit 709b201
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion public/pages/registry/customVariables/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@
url(url: string, opts?: { method: 'POST' | 'GET', headers: object, data: object}): Promise<{ data: object, status: number, statusText: string}>
*
* Available variables
_, _current, users, sender (only in custom commands, keyword), param (only in custom command)
_, _current, users, param (only in custom command)
sender?: { // (only in custom commands, keyword)
username: string,
userId: string,
}
random: {
online: {
viewer: string,
Expand Down
9 changes: 8 additions & 1 deletion src/bot/customvariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CustomVariables {
socket.on('test.script', async (opts, cb) => {
let returnedValue
try {
returnedValue = await this.runScript(opts.evalValue, { _current: opts.currentValue, sender: 'TestUser' })
returnedValue = await this.runScript(opts.evalValue, { _current: opts.currentValue, sender: { username: 'testuser', userId: '0' }})
} catch (e) {
cb(e.stack, null)
}
Expand Down Expand Up @@ -101,6 +101,13 @@ class CustomVariables {
let sender = !_.isNil(opts.sender) ? opts.sender : null
let param = !_.isNil(opts.param) ? opts.param : null

if (typeof sender === 'string') {
sender = {
username: sender,
userId: await global.users.getIdByName(sender)
}
}

// we need to check +1 variables, as they are part of commentary
const containUsers = !_.isNil(script.match(/users/g)) && script.match(/users/g).length > 1
const containRandom = !_.isNil(script.replace(/Math\.random|_\.random/g, '').match(/random/g));
Expand Down

0 comments on commit 709b201

Please sign in to comment.