forked from GitHub/dbot
change module loading so there's only one loop through the moduels
This commit is contained in:
parent
7680e515a8
commit
0ecca6ae98
46
run.js
46
run.js
@ -39,6 +39,9 @@ var DBot = function(timers) {
|
|||||||
if(!this.db.hasOwnProperty("locks")) {
|
if(!this.db.hasOwnProperty("locks")) {
|
||||||
this.db.locks = [];
|
this.db.locks = [];
|
||||||
}
|
}
|
||||||
|
if(!this.db.hasOwnProperty("ignores")) {
|
||||||
|
this.db.locks = {};
|
||||||
|
}
|
||||||
|
|
||||||
// Load the strings file
|
// Load the strings file
|
||||||
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
|
||||||
@ -97,6 +100,7 @@ DBot.prototype.reloadModules = function() {
|
|||||||
this.rawModules = [];
|
this.rawModules = [];
|
||||||
this.modules = [];
|
this.modules = [];
|
||||||
this.commands = {};
|
this.commands = {};
|
||||||
|
this.commandMap = {}; // Map of which commands belong to which modules
|
||||||
this.timers.clearTimers();
|
this.timers.clearTimers();
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
@ -111,36 +115,34 @@ DBot.prototype.reloadModules = function() {
|
|||||||
delete require.cache[path];
|
delete require.cache[path];
|
||||||
require('./snippets');
|
require('./snippets');
|
||||||
|
|
||||||
|
this.instance.removeListeners();
|
||||||
|
|
||||||
this.moduleNames.each(function(name) {
|
this.moduleNames.each(function(name) {
|
||||||
var cacheKey = require.resolve('./modules/' + name);
|
var cacheKey = require.resolve('./modules/' + name);
|
||||||
delete require.cache[cacheKey];
|
delete require.cache[cacheKey];
|
||||||
try {
|
try {
|
||||||
this.rawModules.push(require('./modules/' + name));
|
var rawModule = require('./modules/' + name);
|
||||||
|
var module = rawModule.fetch(this);
|
||||||
|
this.rawModules.push(rawModule);
|
||||||
|
|
||||||
|
if(module.listener) {
|
||||||
|
this.instance.addListener(module.on, module.listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(module.onLoad) {
|
||||||
|
var newCommands = module.onLoad();
|
||||||
|
for(key in newCommands) {
|
||||||
|
if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) {
|
||||||
|
this.commands[key] = newCommands[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.modules.push(module);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(this.strings[this.language].module_load_error.format({'moduleName': name}));
|
console.log(this.strings[this.language].module_load_error.format({'moduleName': name}));
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.instance.removeListeners();
|
|
||||||
|
|
||||||
this.modules = this.rawModules.collect(function(rawModule) {
|
|
||||||
var module = rawModule.fetch(this);
|
|
||||||
|
|
||||||
if(module.listener) {
|
|
||||||
this.instance.addListener(module.on, module.listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(module.onLoad) {
|
|
||||||
var newCommands = module.onLoad();
|
|
||||||
for(key in newCommands) {
|
|
||||||
if(newCommands.hasOwnProperty(key) && Object.prototype.isFunction(newCommands[key])) {
|
|
||||||
this.commands[key] = newCommands[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return module;
|
|
||||||
}.bind(this));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DBot.prototype.cleanNick = function(key) {
|
DBot.prototype.cleanNick = function(key) {
|
||||||
|
Loading…
Reference in New Issue
Block a user