Transformed dent module, changed module loader to give right scope. [#131]

This commit is contained in:
reality 2013-01-14 17:45:53 +00:00
parent 4b69aee3e9
commit 3bde9e4930
3 changed files with 12 additions and 18 deletions

View File

@ -31,7 +31,8 @@ var command = function(dbot) {
dbot.commands[commandName].disabled !== true) {
if(this.api.applyRegex(commandName, event)) {
try {
dbot.commands[commandName](event);
var command = dbot.commands[commandName];
command.apply(dbot.modules[command.module], [event]);
} catch(err) {
if(dbot.config.debugMode == true) {
event.reply('- Error in ' + commandName + ':');

View File

@ -2,7 +2,10 @@ var request = require('request');
_ = require('underscore')._;
var dent = function(dbot) {
var api = {
this.name = 'dent';
this.dbot = dbot;
this.api = {
'post': function(content) {
var username = dbot.config.dent.username,
password = dbot.config.dent.password,
@ -23,21 +26,15 @@ var dent = function(dbot) {
}
};
var commands = {
this.commands = {
'~dent': function(event) {
api.post(event.input[1]);
this.api.post(event.input[1]);
event.reply('Dent posted (probably).');
}
};
commands['~dent'].regex = [/^~dent (.+)$/, 2];
return {
'name': 'dent',
'commands': commands,
'api': api
};
this.commands['~dent'].regex = [/^~dent (.+)$/, 2];
};
exports.fetch = function(dbot) {
return dent(dbot);
return new dent(dbot);
};

8
run.js
View File

@ -187,12 +187,8 @@ DBot.prototype.reloadModules = function() {
return;
}
module[property] = {};
_.each(propertyObj, function(item, name) {
if(_.isFunction(item)) {
module[property][name] = item.bind(module);
}
}, this);
if(!_.has(module, property)) module[property] = {};
_.extend(module[property], propertyObj);
}, this);
if(module.listener) {