From 6209c98c1e423122bf998392c039975efdff2387 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:06:46 +0200 Subject: [PATCH 01/16] modified: src/trigger/test.js --- src/trigger/test.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/trigger/test.js b/src/trigger/test.js index 61c4081..1dd60c1 100644 --- a/src/trigger/test.js +++ b/src/trigger/test.js @@ -1,11 +1,23 @@ +var Sandbox = require("sandbox"); +var s = new Sandbox({ + timeout: 2000 +}); +let sbhead = "\"use strict\";"; +sbhead += Object.getOwnPropertyNames(Math).map(function(v){return "const " + v + "=Math." + v + ";" + (typeof Math[v] == "function" ? v + ".bind(Math);" : "")}).join(""); + module.exports = (lib) => { lib.trigger.add({ name: 'test', - call: /^!test$/i, - level: 0, - active: 0, + call: /^!test (.*)/i, + level: 100, + active: 1, func: (e) => { - + var args = e.message.trim().match(/^!test (.*)/i)[1]; + s.run(sbhead + args, (out) => { + let con = out.console.length > 0 ? " and printed to console: " + out.console : ""; + let text = (out.result + con).replace(/[\r\n\t]/g, " "); + e.reply(e.user.getNick() + " it returned: " + (text.length > 400 ? "f0ck you" : text)); + }); }, desc: 'muh' }); From 9e69dd4e3347b8dd6f21c5b5818cbda694c41a2a Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 03:08:55 +0000 Subject: [PATCH 02/16] Revert "modified: src/trigger/test.js" This reverts commit 6209c98c1e423122bf998392c039975efdff2387 --- src/trigger/test.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/trigger/test.js b/src/trigger/test.js index 1dd60c1..61c4081 100644 --- a/src/trigger/test.js +++ b/src/trigger/test.js @@ -1,23 +1,11 @@ -var Sandbox = require("sandbox"); -var s = new Sandbox({ - timeout: 2000 -}); -let sbhead = "\"use strict\";"; -sbhead += Object.getOwnPropertyNames(Math).map(function(v){return "const " + v + "=Math." + v + ";" + (typeof Math[v] == "function" ? v + ".bind(Math);" : "")}).join(""); - module.exports = (lib) => { lib.trigger.add({ name: 'test', - call: /^!test (.*)/i, - level: 100, - active: 1, + call: /^!test$/i, + level: 0, + active: 0, func: (e) => { - var args = e.message.trim().match(/^!test (.*)/i)[1]; - s.run(sbhead + args, (out) => { - let con = out.console.length > 0 ? " and printed to console: " + out.console : ""; - let text = (out.result + con).replace(/[\r\n\t]/g, " "); - e.reply(e.user.getNick() + " it returned: " + (text.length > 400 ? "f0ck you" : text)); - }); + }, desc: 'muh' }); From 29120061295f3401fad43641ac5e6d4be52dbf97 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:16:37 +0200 Subject: [PATCH 03/16] test --- src/trigger/bot.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/trigger/bot.js diff --git a/src/trigger/bot.js b/src/trigger/bot.js new file mode 100644 index 0000000..9502711 --- /dev/null +++ b/src/trigger/bot.js @@ -0,0 +1,23 @@ +const util = require('util'); +const vm = require('vm'); + +module.exports = (lib) => { + const sandbox = { + bot: lib.bot + }; + + lib.trigger.add({ + name: 'bot debug', + call: /^!bot (.*)/i, + level: 100, + active: 1, + func: (e) => { + var args = e.message.trim().match(/^!bot (.*?)/i)[1]; + const script = new vm.Script(args); + const context = new vm.createContext(sandbox); + script.runInContext(context); + e.reply(util.inspect(sandbox)); + }, + desc: 'bot debug' + }); +}; \ No newline at end of file From 8fb995309ad66454c141c88817c436a644017d10 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:21:35 +0200 Subject: [PATCH 04/16] test --- src/trigger/bot.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index 9502711..be8f66a 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -3,7 +3,8 @@ const vm = require('vm'); module.exports = (lib) => { const sandbox = { - bot: lib.bot + bot: lib.bot, + output: "nothing" }; lib.trigger.add({ @@ -13,10 +14,13 @@ module.exports = (lib) => { active: 1, func: (e) => { var args = e.message.trim().match(/^!bot (.*?)/i)[1]; + e.reply(args); + const script = new vm.Script(args); const context = new vm.createContext(sandbox); + script.runInContext(context); - e.reply(util.inspect(sandbox)); + e.reply(util.inspect(sandbox.output)); }, desc: 'bot debug' }); From 995e9d919672a0c2df6b4ad9371c17010199c549 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:26:24 +0200 Subject: [PATCH 05/16] test --- src/trigger/bot.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index be8f66a..5d11591 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -4,7 +4,8 @@ const vm = require('vm'); module.exports = (lib) => { const sandbox = { bot: lib.bot, - output: "nothing" + output: "nothing", + e: null }; lib.trigger.add({ @@ -13,14 +14,13 @@ module.exports = (lib) => { level: 100, active: 1, func: (e) => { - var args = e.message.trim().match(/^!bot (.*?)/i)[1]; + var args = e.message.match(/^!bot (.*?)/i)[1]; e.reply(args); + sandbox.e = e; - const script = new vm.Script(args); - const context = new vm.createContext(sandbox); + vm.runInNewContext(args, sandbox); - script.runInContext(context); - e.reply(util.inspect(sandbox.output)); + e.reply(util.inspect(sandbox['output'])); }, desc: 'bot debug' }); From a0cf04a326962f9697b3f17e981fc360ada0d3af Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:29:57 +0200 Subject: [PATCH 06/16] test --- src/trigger/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index 5d11591..b0381e5 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -20,7 +20,7 @@ module.exports = (lib) => { vm.runInNewContext(args, sandbox); - e.reply(util.inspect(sandbox['output'])); + console.log(util.inspect(sandbox)); }, desc: 'bot debug' }); From b32d5e8a5c859badbc5679fde0bd053f9f1b5c4c Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:35:11 +0200 Subject: [PATCH 07/16] f0ck it --- src/trigger/bot.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index b0381e5..35c61f9 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -2,7 +2,7 @@ const util = require('util'); const vm = require('vm'); module.exports = (lib) => { - const sandbox = { + var sandbox = { bot: lib.bot, output: "nothing", e: null @@ -10,11 +10,11 @@ module.exports = (lib) => { lib.trigger.add({ name: 'bot debug', - call: /^!bot (.*)/i, + call: /^\!bot (.*)/i, level: 100, active: 1, func: (e) => { - var args = e.message.match(/^!bot (.*?)/i)[1]; + var args = e.message.match(/^\!bot (.*)/i)[1]; e.reply(args); sandbox.e = e; From 015d7e0102b7039b1df59ab7e0dc1a2dd4c116a8 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:37:01 +0200 Subject: [PATCH 08/16] test --- src/trigger/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index 35c61f9..be711a9 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -20,7 +20,7 @@ module.exports = (lib) => { vm.runInNewContext(args, sandbox); - console.log(util.inspect(sandbox)); + e.reply(util.inspect(sandbox.output)); }, desc: 'bot debug' }); From bb993a449a2bdd88bb9c8d07d3fc099518efb5dc Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:38:21 +0200 Subject: [PATCH 09/16] test --- src/trigger/bot.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index be711a9..2b0089a 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -15,10 +15,9 @@ module.exports = (lib) => { active: 1, func: (e) => { var args = e.message.match(/^\!bot (.*)/i)[1]; - e.reply(args); sandbox.e = e; - vm.runInNewContext(args, sandbox); + vm.runInNewContext('this.output = '+args, sandbox); e.reply(util.inspect(sandbox.output)); }, From ede3faae10c440591a5e43b6f814dbb6e9c0cb9d Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:43:52 +0200 Subject: [PATCH 10/16] test --- src/trigger/bot.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index 2b0089a..bf9d614 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -4,7 +4,7 @@ const vm = require('vm'); module.exports = (lib) => { var sandbox = { bot: lib.bot, - output: "nothing", + output: undefined, e: null }; @@ -19,7 +19,9 @@ module.exports = (lib) => { vm.runInNewContext('this.output = '+args, sandbox); - e.reply(util.inspect(sandbox.output)); + var output = util.inspect(sandbox.output); + if(output !== undefined) + e.reply(output); }, desc: 'bot debug' }); From c303a1040d8742934ca5f7a9e1f4f8b6d912ad38 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:45:23 +0200 Subject: [PATCH 11/16] test --- src/trigger/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index bf9d614..29f4c2b 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -20,7 +20,7 @@ module.exports = (lib) => { vm.runInNewContext('this.output = '+args, sandbox); var output = util.inspect(sandbox.output); - if(output !== undefined) + if(typeof(output) !== undefined) e.reply(output); }, desc: 'bot debug' From 680230abc14b62a633ca0a6a8e2e9467e8b6cbd1 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 05:59:05 +0200 Subject: [PATCH 12/16] test --- src/trigger/bot.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index 29f4c2b..d3ebe51 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -1,12 +1,13 @@ -const util = require('util'); -const vm = require('vm'); +//const util = require('util'); +//const vm = require('vm'); +var safeEval = require('safe-eval'); module.exports = (lib) => { - var sandbox = { - bot: lib.bot, - output: undefined, - e: null - }; + //var sandbox = { + // bot: lib.bot, + // output: undefined, + // e: null + //}; lib.trigger.add({ name: 'bot debug', @@ -15,13 +16,18 @@ module.exports = (lib) => { active: 1, func: (e) => { var args = e.message.match(/^\!bot (.*)/i)[1]; - sandbox.e = e; - vm.runInNewContext('this.output = '+args, sandbox); + var context = { + bot: lib.bot, + e: e + } + e.reply( safeEval(args, context) ); - var output = util.inspect(sandbox.output); - if(typeof(output) !== undefined) - e.reply(output); + //sandbox.e = e; + //vm.runInNewContext('this.output = '+args, sandbox); + //var output = util.inspect(sandbox.output); + //if(typeof(output) !== undefined) + // e.reply(output); }, desc: 'bot debug' }); From 12f2f8cbdc9d85b9c01ccfca22fdf0ddd5fa56a2 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 06:00:37 +0200 Subject: [PATCH 13/16] test --- src/trigger/bot.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index d3ebe51..e2dd4ac 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -1,14 +1,6 @@ -//const util = require('util'); -//const vm = require('vm'); var safeEval = require('safe-eval'); module.exports = (lib) => { - //var sandbox = { - // bot: lib.bot, - // output: undefined, - // e: null - //}; - lib.trigger.add({ name: 'bot debug', call: /^\!bot (.*)/i, @@ -16,18 +8,13 @@ module.exports = (lib) => { active: 1, func: (e) => { var args = e.message.match(/^\!bot (.*)/i)[1]; - var context = { bot: lib.bot, e: e } - e.reply( safeEval(args, context) ); - - //sandbox.e = e; - //vm.runInNewContext('this.output = '+args, sandbox); - //var output = util.inspect(sandbox.output); - //if(typeof(output) !== undefined) - // e.reply(output); + var output = safeEval(args, context); + if(typeof(output) != undefined) + e.reply(output); }, desc: 'bot debug' }); From d1c54a6682bbb60dd3ee76b684e73596944675ea Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 06:01:28 +0200 Subject: [PATCH 14/16] grr --- src/trigger/bot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trigger/bot.js b/src/trigger/bot.js index e2dd4ac..e98ff78 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -13,7 +13,7 @@ module.exports = (lib) => { e: e } var output = safeEval(args, context); - if(typeof(output) != undefined) + if(typeof(output) != undefined && output !== 'undefined' && output) e.reply(output); }, desc: 'bot debug' From 697fe17bc6cf3d913beff6c5b2d691966a97b628 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 06:04:23 +0200 Subject: [PATCH 15/16] modified: package.json modified: src/trigger/bot.js --- package.json | 3 ++- src/trigger/bot.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a6a0772..b9b996c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "request": "^2.74.0", "swig": "^1.4.2", "uuid": "^2.0.2", - "ytdl-core": "^0.7.17" + "ytdl-core": "^0.7.17", + "safe-eval": "^0.3.0" }, "repository": { "type": "git", diff --git a/src/trigger/bot.js b/src/trigger/bot.js index e98ff78..3de369d 100644 --- a/src/trigger/bot.js +++ b/src/trigger/bot.js @@ -12,9 +12,14 @@ module.exports = (lib) => { bot: lib.bot, e: e } - var output = safeEval(args, context); - if(typeof(output) != undefined && output !== 'undefined' && output) - e.reply(output); + try { + var output = safeEval(args, context); + if(typeof(output) != undefined && output !== 'undefined' && output) + e.reply(output); + } + catch(blah) { + e.reply('f0ck you!'); + } }, desc: 'bot debug' }); From b67cecbb45fb6034aff6a694e64004ac3c33e9f5 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 29 Oct 2016 06:08:51 +0200 Subject: [PATCH 16/16] muh --- src/trigger/{bot.js => sandbox.js} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename src/trigger/{bot.js => sandbox.js} (74%) diff --git a/src/trigger/bot.js b/src/trigger/sandbox.js similarity index 74% rename from src/trigger/bot.js rename to src/trigger/sandbox.js index 3de369d..65bd43f 100644 --- a/src/trigger/bot.js +++ b/src/trigger/sandbox.js @@ -2,12 +2,12 @@ var safeEval = require('safe-eval'); module.exports = (lib) => { lib.trigger.add({ - name: 'bot debug', - call: /^\!bot (.*)/i, + name: 'sandbox', + call: /^\!js (.*)/i, level: 100, active: 1, func: (e) => { - var args = e.message.match(/^\!bot (.*)/i)[1]; + var args = e.message.match(/^\!js (.*)/i)[1]; var context = { bot: lib.bot, e: e @@ -21,6 +21,6 @@ module.exports = (lib) => { e.reply('f0ck you!'); } }, - desc: 'bot debug' + desc: 'sandbox' }); }; \ No newline at end of file