Fixed doom function binding bug and transformed js module [#131]

This commit is contained in:
reality 2013-01-14 22:03:58 +00:00
parent 8b7953e906
commit 96792d5008
2 changed files with 7 additions and 10 deletions

View File

@ -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);
};

3
run.js
View File

@ -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);