basic dependencies as per [#85]

This commit is contained in:
reality 2013-01-21 17:39:21 +00:00
parent 5485c39684
commit 1673c8846b
2 changed files with 18 additions and 4 deletions

View File

@ -1,5 +1,6 @@
{
"help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md",
"dbKeys": [ "polls" ],
"ignorable": true
"ignorable": true,
"dependencies": [ "users", "command" ]
}

19
run.js
View File

@ -178,7 +178,22 @@ DBot.prototype.reloadModules = function() {
// Invalid or no config data
}
// Load module config
// Shit out if dependencies not met
if(_.has(config, 'dependencies')) {
var unmetDependencies = _.reduce(config.dependencies, function(memo, dependency) {
if(!_.include(moduleNames, dependency)) {
memo.push(dependency);
}
return memo;
}, [], this);
if(unmetDependencies.length != 0) {
throw new Error("Dependencies not met: " + unmetDependencies);
return;
}
}
// Generate missing DB keys
this.config[name] = config;
_.each(config.dbKeys, function(dbKey) {
if(!_.has(this.db, dbKey)) {
@ -186,8 +201,6 @@ DBot.prototype.reloadModules = function() {
}
}, this);
// Override module config with any stored in the DB
// Load the module itself
var rawModule = require(moduleDir + name);
var module = rawModule.fetch(this);