Refactor script.runner
This commit is contained in:
parent
93b18cd32c
commit
e191310d99
1 changed files with 8 additions and 7 deletions
|
@ -87,13 +87,14 @@ class script extends utils {
|
|||
return `${random.number()} % ${o.pick(objName)}.length`
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap command(s) in setInterval, setTimeout, loop or run directly
|
||||
* @param {string|string[]} cmds - Command(s) to be executed
|
||||
* @returns {string}
|
||||
*/
|
||||
static runner (cmds) {
|
||||
/**
|
||||
* Wrap command(s) in setInterval, setTimeout, loop or run directly
|
||||
* @param {Object|String} cmds - Command(s) to be executed
|
||||
*/
|
||||
cmds = (Array.isArray(cmds)) ? cmds : [cmds]
|
||||
cmds = cmds.filter(function (i) { return i !== undefined })
|
||||
cmds = cmds.filter((i) => i !== undefined)
|
||||
if (cmds.length) {
|
||||
if (random.chance(50)) {
|
||||
// Wrap each command in try/catch for use in setInterval, setTimeout, repeater
|
||||
|
@ -106,9 +107,9 @@ class script extends utils {
|
|||
let n = random.number(random.number(30))
|
||||
return `for (let i = 0; i < ${n}; i++) { ${utils.script.safely(cmds)} }`
|
||||
}
|
||||
} else {
|
||||
return cmds
|
||||
}
|
||||
|
||||
return utils.script.safely(cmds)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue