forked from GitHub/dbot
Transformed dent module, changed module loader to give right scope. [#131]
This commit is contained in:
parent
4b69aee3e9
commit
3bde9e4930
@ -31,7 +31,8 @@ var command = function(dbot) {
|
|||||||
dbot.commands[commandName].disabled !== true) {
|
dbot.commands[commandName].disabled !== true) {
|
||||||
if(this.api.applyRegex(commandName, event)) {
|
if(this.api.applyRegex(commandName, event)) {
|
||||||
try {
|
try {
|
||||||
dbot.commands[commandName](event);
|
var command = dbot.commands[commandName];
|
||||||
|
command.apply(dbot.modules[command.module], [event]);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
if(dbot.config.debugMode == true) {
|
if(dbot.config.debugMode == true) {
|
||||||
event.reply('- Error in ' + commandName + ':');
|
event.reply('- Error in ' + commandName + ':');
|
||||||
|
@ -2,7 +2,10 @@ var request = require('request');
|
|||||||
_ = require('underscore')._;
|
_ = require('underscore')._;
|
||||||
|
|
||||||
var dent = function(dbot) {
|
var dent = function(dbot) {
|
||||||
var api = {
|
this.name = 'dent';
|
||||||
|
this.dbot = dbot;
|
||||||
|
|
||||||
|
this.api = {
|
||||||
'post': function(content) {
|
'post': function(content) {
|
||||||
var username = dbot.config.dent.username,
|
var username = dbot.config.dent.username,
|
||||||
password = dbot.config.dent.password,
|
password = dbot.config.dent.password,
|
||||||
@ -23,21 +26,15 @@ var dent = function(dbot) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var commands = {
|
this.commands = {
|
||||||
'~dent': function(event) {
|
'~dent': function(event) {
|
||||||
api.post(event.input[1]);
|
this.api.post(event.input[1]);
|
||||||
event.reply('Dent posted (probably).');
|
event.reply('Dent posted (probably).');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
commands['~dent'].regex = [/^~dent (.+)$/, 2];
|
this.commands['~dent'].regex = [/^~dent (.+)$/, 2];
|
||||||
|
|
||||||
return {
|
|
||||||
'name': 'dent',
|
|
||||||
'commands': commands,
|
|
||||||
'api': api
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.fetch = function(dbot) {
|
exports.fetch = function(dbot) {
|
||||||
return dent(dbot);
|
return new dent(dbot);
|
||||||
};
|
};
|
||||||
|
8
run.js
8
run.js
@ -187,12 +187,8 @@ DBot.prototype.reloadModules = function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
module[property] = {};
|
if(!_.has(module, property)) module[property] = {};
|
||||||
_.each(propertyObj, function(item, name) {
|
_.extend(module[property], propertyObj);
|
||||||
if(_.isFunction(item)) {
|
|
||||||
module[property][name] = item.bind(module);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if(module.listener) {
|
if(module.listener) {
|
||||||
|
Loading…
Reference in New Issue
Block a user