forked from GitHub/dbot
I must say... I am proud of this... [#131]
This commit is contained in:
parent
3bde9e4930
commit
a0bec5b2f9
37
run.js
37
run.js
@ -178,17 +178,24 @@ DBot.prototype.reloadModules = function() {
|
|||||||
|
|
||||||
// Load the module with any addition objects we can find...
|
// Load the module with any addition objects we can find...
|
||||||
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
_.each([ 'commands', 'pages', 'api' ], function(property) {
|
||||||
|
var propertyObj = {};
|
||||||
try {
|
try {
|
||||||
var propertyKey = require.resolve(moduleDir + property);
|
var propertyKey = require.resolve(moduleDir + property);
|
||||||
if(propertyKey) delete require.cache[propertyKey];
|
if(propertyKey) delete require.cache[propertyKey];
|
||||||
var propertyObj = require(moduleDir + property).fetch(this);
|
propertyObj = require(moduleDir + property).fetch(this);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err.stack);
|
//console.log(err.stack);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_.has(module, property)) module[property] = {};
|
if(!_.has(module, property)) module[property] = {};
|
||||||
_.extend(module[property], propertyObj);
|
_.extend(module[property], propertyObj);
|
||||||
|
_.each(module[property], function(item, itemName) {
|
||||||
|
item.module = name;
|
||||||
|
if(_.has(config, property) && _.has(config[property], itemName)) {
|
||||||
|
_.extend(item, config[property][itemName]);
|
||||||
|
}
|
||||||
|
}, this);
|
||||||
|
_.extend(this[property], module[property]);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
if(module.listener) {
|
if(module.listener) {
|
||||||
@ -205,30 +212,6 @@ DBot.prototype.reloadModules = function() {
|
|||||||
module.onLoad();
|
module.onLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load module commands
|
|
||||||
if(module.commands) {
|
|
||||||
_.extend(this.commands, module.commands);
|
|
||||||
_.each(module.commands, function(command, commandName) {
|
|
||||||
command.module = name;
|
|
||||||
if(_.has(config, 'commands') && _.has(config.commands, commandName)) {
|
|
||||||
_.extend(command, config.commands[commandName]);
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load module web bits
|
|
||||||
if(module.pages) {
|
|
||||||
_.extend(this.pages, module.pages);
|
|
||||||
_.each(module.pages, function(page) {
|
|
||||||
page.module = module;
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load module API
|
|
||||||
if(module.api) {
|
|
||||||
this.api[module.name] = module.api;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the module usage data
|
// Load the module usage data
|
||||||
var usage = {};
|
var usage = {};
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user