From 3bde9e493055168f39e4dd8aea3a564611364699 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 14 Jan 2013 17:45:53 +0000 Subject: [PATCH] Transformed dent module, changed module loader to give right scope. [#131] --- modules/command/command.js | 3 ++- modules/dent/dent.js | 19 ++++++++----------- run.js | 8 ++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/modules/command/command.js b/modules/command/command.js index 4812b4a..60c9477 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -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 + ':'); diff --git a/modules/dent/dent.js b/modules/dent/dent.js index 120b082..81e56f0 100644 --- a/modules/dent/dent.js +++ b/modules/dent/dent.js @@ -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); }; diff --git a/run.js b/run.js index fabfb67..1963790 100644 --- a/run.js +++ b/run.js @@ -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) {