load config before the module itself

This commit is contained in:
reality 2012-12-18 11:07:39 +00:00
parent f11c227be9
commit 6a28327d5c

26
run.js
View File

@ -150,6 +150,19 @@ DBot.prototype.reloadModules = function() {
delete require.cache[cacheKey];
try {
// Load the module config data
try {
var config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8'))
this.config[name] = config;
for(var i=0;i<config.dbKeys.length;i++) {
if(!this.db.hasOwnProperty(config.dbKeys[i])) {
this.db[config.dbKeys[i]] = {};
}
}
} catch(err) {
// Invalid or no config data
}
// Load the module itself
var rawModule = require(moduleDir + name);
var module = rawModule.fetch(this);
@ -206,19 +219,6 @@ DBot.prototype.reloadModules = function() {
// Invalid or no string info
}
// Load the module config data
try {
var config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8'))
this.config[name] = config;
for(var i=0;i<config.dbKeys.length;i++) {
if(!this.db.hasOwnProperty(config.dbKeys[i])) {
this.db[config.dbKeys[i]] = {};
}
}
} catch(err) {
// Invalid or no config data
}
this.modules.push(module);
} catch(err) {
console.log(this.t('module_load_error', {'moduleName': name}));