const runScript = (line) => { var script = sbox.createScript("exports.main = function() {" + line + "}"); script.on('exit', function(err, output) { console.log('err: ' + err); console.log('output: ' + output); if (!err) { res = output instanceof Object ? JSON.stringify(output) : String(output) if (!client.isMock) { res = res.substring(0, 400); } res = res.replace(/(\r\n|\n|\r)/gm, ' '); res = res.replace(/^"/, ''); res = res.replace(/"$/, ''); res = res.length ? res : 'script returned empty string' if (!~res.indexOf('[OO HILJAA]')) client.say(channel, macroName[0] === '_' ? concat(res, lineArr.join(" ")) : res); } else { res = err.toString(); client.say(channel, res); } }); script.on('timeout', function() { console.log('script timed out'); client.say(channel, 'script timed out'); }); script.run({ arg: lineArr.join(" ") }); }
}, function (callback) { count++; if (count == _stub.conditions.length - 1) continueLoop = false; var script = sandcastle.createScript('exports.main = function() {\n try {\n if (' + _stub.conditions[count].eval + ')\n exit(\'' + _stub.conditions[count].stub + '\')\n else\n exit(false)\n } catch(e) {\n exit(false)\n }\n }'); script.on('exit', function (err, output) { if (output) { continueLoop = false; returnedStub = output; } callback(); }); script.run({ req: assign({}, { baseURL: req.baseURL, body: req.body, cookies: req.cookies, headers: req.headers, hostname: req.hostname, ip: req.ip, ips: req.ips, method: req.method, originalUrl: req.originalUrl, params: req.params, path: req.path, protocol: req.protocol, query: req.query, route: req.route, signedCookies: req.signedCookies, stale: req.stale, subdomains: req.subdomains, xhr: req.xhr }) }); }, function (err) {