/** * Module Name: JS * Description: Allows users to run sandboxed JS code, printing the result in * the channel. Also allows admins to run un-sandboxed Javascript code with * access to the DepressionBot instance memory. */ var VM = require('vm2').VM; var js = function(dbot) { var commands = { // Run JS code sandboxed, return result to channel. '~js': function(event) { try { var s = new VM({timeout: 1000, sandbox: {}}); event.reply(s.run(event.input[1])); } catch(err) { event.reply(err); } }, // Run JS code un-sandboxed, with access to DBot memory (admin-only). '~ajs': function(event) { var callback = function() { var args = Array.prototype.slice.call(arguments); for(var i=0;i