3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-23 20:39:25 +01:00

change module loading so there's only one loop through the moduels

This commit is contained in:
Luke Slater 2012-04-15 20:42:23 +01:00
parent 7680e515a8
commit 0ecca6ae98

22
run.js
View File

@ -39,6 +39,9 @@ var DBot = function(timers) {
if(!this.db.hasOwnProperty("locks")) {
this.db.locks = [];
}
if(!this.db.hasOwnProperty("ignores")) {
this.db.locks = {};
}
// Load the strings file
this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));
@ -97,6 +100,7 @@ DBot.prototype.reloadModules = function() {
this.rawModules = [];
this.modules = [];
this.commands = {};
this.commandMap = {}; // Map of which commands belong to which modules
this.timers.clearTimers();
this.save();
@ -111,20 +115,15 @@ DBot.prototype.reloadModules = function() {
delete require.cache[path];
require('./snippets');
this.instance.removeListeners();
this.moduleNames.each(function(name) {
var cacheKey = require.resolve('./modules/' + name);
delete require.cache[cacheKey];
try {
this.rawModules.push(require('./modules/' + name));
} catch(err) {
console.log(this.strings[this.language].module_load_error.format({'moduleName': name}));
}
}.bind(this));
this.instance.removeListeners();
this.modules = this.rawModules.collect(function(rawModule) {
var rawModule = require('./modules/' + name);
var module = rawModule.fetch(this);
this.rawModules.push(rawModule);
if(module.listener) {
this.instance.addListener(module.on, module.listener);
@ -139,7 +138,10 @@ DBot.prototype.reloadModules = function() {
}
}
return module;
this.modules.push(module);
} catch(err) {
console.log(this.strings[this.language].module_load_error.format({'moduleName': name}));
}
}.bind(this));
};