From 96792d50087f425baaa009cdec23672c33d8b88f Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 14 Jan 2013 22:03:58 +0000 Subject: [PATCH] Fixed doom function binding bug and transformed js module [#131] --- modules/js/js.js | 14 +++++--------- run.js | 3 ++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/js/js.js b/modules/js/js.js index 917e0a5..d6094ff 100644 --- a/modules/js/js.js +++ b/modules/js/js.js @@ -8,12 +8,11 @@ var vm = require('vm'); var sbox = require('sandbox'); var js = function(dbot) { - var s = new sbox(); - var commands = { // Run JS code sandboxed, return result to channel. '~js': function(event) { try { + var s = new sbox(); s.run(event.input[1], function(output) { event.reply(output.result); }.bind(this)); @@ -30,16 +29,13 @@ var js = function(dbot) { }; commands['~js'].regex = [/^~js (.*)/, 2]; commands['~ajs'].regex = [/^~ajs (.*)/, 2]; - commands['~ajs'].access = 'admin'; - return { - 'name': 'js', - 'ignorable': true, - 'commands': commands - }; + this.name = 'js'; + this.ignorable = true; + this.commands = commands; }; exports.fetch = function(dbot) { - return js(dbot); + return new js(dbot); }; diff --git a/run.js b/run.js index 17b855d..1141059 100644 --- a/run.js +++ b/run.js @@ -194,7 +194,8 @@ DBot.prototype.reloadModules = function() { if(_.has(config, property) && _.has(config[property], itemName)) { _.extend(item, config[property][itemName]); } - module[property][itemName] = item.bind(module); + module[property][itemName] = _.bind(item, module); + _.extend(module[property][itemName], item); }, this); _.extend(this[property], module[property]); }, this);