var vm = require('vm');
var sandbox = require('sandbox');

var js = function(dbot) {
    var dbot = dbot;
    var s = new Sandbox();

    var commands = {
        '~js': function(data, params) {
            var q = data.message.valMatch(/^~js (.*)/, 2);
            s.run(q[1], function(output) {
                dbot.say(data.channel, output.result);
            });
        },

        '~ajs': function(data, params) {
            var q = data.message.valMatch(/^~ajs (.*)/, 2);
            if(data.user == dbot.admin) {
                dbot.say(data.channel, eval(q[1]));
            }
        }
    };

    return {
        'onLoad': function() {
            return commands;
        }
    };
};

exports.fetch = function(dbot) {
    return js(dbot);
};

@@ -22,22 +22,16 @@
 );%0Avar s
-andbox
  = requi
@@ -96,35 +96,8 @@
 bot;
-%0A    var s = new Sandbox();
 %0A%0A  

use sandbox module for running untrusted code because it has a timeout