3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

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 sbox = require('sandbox');
var js = function(dbot) { var js = function(dbot) {
var s = new sbox();
var commands = { var commands = {
// Run JS code sandboxed, return result to channel. // Run JS code sandboxed, return result to channel.
'~js': function(event) { '~js': function(event) {
try { try {
var s = new sbox();
s.run(event.input[1], function(output) { s.run(event.input[1], function(output) {
event.reply(output.result); event.reply(output.result);
}.bind(this)); }.bind(this));
@ -30,16 +29,13 @@ var js = function(dbot) {
}; };
commands['~js'].regex = [/^~js (.*)/, 2]; commands['~js'].regex = [/^~js (.*)/, 2];
commands['~ajs'].regex = [/^~ajs (.*)/, 2]; commands['~ajs'].regex = [/^~ajs (.*)/, 2];
commands['~ajs'].access = 'admin'; commands['~ajs'].access = 'admin';
return { this.name = 'js';
'name': 'js', this.ignorable = true;
'ignorable': true, this.commands = commands;
'commands': commands
};
}; };
exports.fetch = function(dbot) { 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)) { if(_.has(config, property) && _.has(config[property], itemName)) {
_.extend(item, 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); }, this);
_.extend(this[property], module[property]); _.extend(this[property], module[property]);
}, this); }, this);