Do the same for string data [#131]

This commit is contained in:
reality 2013-01-14 18:15:07 +00:00
parent a0bec5b2f9
commit 8542ceb9e9

39
run.js
View File

@ -176,7 +176,7 @@ DBot.prototype.reloadModules = function() {
module.name = name; module.name = name;
this.rawModules.push(rawModule); this.rawModules.push(rawModule);
// Load the module with any addition objects we can find... // Load the module data
_.each([ 'commands', 'pages', 'api' ], function(property) { _.each([ 'commands', 'pages', 'api' ], function(property) {
var propertyObj = {}; var propertyObj = {};
try { try {
@ -184,7 +184,7 @@ DBot.prototype.reloadModules = function() {
if(propertyKey) delete require.cache[propertyKey]; if(propertyKey) delete require.cache[propertyKey];
propertyObj = require(moduleDir + property).fetch(this); propertyObj = require(moduleDir + property).fetch(this);
} catch(err) { } catch(err) {
//console.log(err.stack); console.log('Module error (' + module.name + ') in ' + property + ': ' + err);
} }
if(!_.has(module, property)) module[property] = {}; if(!_.has(module, property)) module[property] = {};
@ -198,43 +198,34 @@ DBot.prototype.reloadModules = function() {
_.extend(this[property], module[property]); _.extend(this[property], module[property]);
}, this); }, this);
// Load the module listener
if(module.listener) { if(module.listener) {
if(!_.isArray(module.on)) { if(!_.isArray(module.on)) {
module.on = [ module.on ]; module.on = [ module.on ];
} }
_.each(module.on, function(on) { _.each(module.on, function(on) {
this.instance.addListener(on, module.name, module.listener); this.instance.addListener(on, module.name, module.listener);
}, this); }, this);
} }
if(module.onLoad) { // Load string data for the module
module.onLoad(); _.each([ 'usage', 'strings' ], function(property) {
} var propertyData = {};
try {
// Load the module usage data propertyData = JSON.parse(fs.readFileSync(moduleDir + property + '.json', 'utf-8'));
var usage = {}; } catch(err) {};
try { _.extend(this[property], propertyData);
usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); }, this);
} catch(err) {
// Invalid or no usage info
}
_.extend(this.usage, usage);
// Load the module string data
var strings = {};
try {
strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8'));
} catch(err) {
// Invalid or no string info
}
_.extend(this.strings, strings);
// Provide toString for module name // Provide toString for module name
module.toString = function() { module.toString = function() {
return this.name; return this.name;
} }
if(module.onLoad) {
module.onLoad();
}
this.modules[module.name] = module; this.modules[module.name] = module;
} catch(err) { } catch(err) {
console.log(this.t('module_load_error', {'moduleName': name})); console.log(this.t('module_load_error', {'moduleName': name}));