diff --git a/modules/poll/config.json b/modules/poll/config.json index b7e55ae..7b0f48b 100644 --- a/modules/poll/config.json +++ b/modules/poll/config.json @@ -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" ] } diff --git a/run.js b/run.js index 7b6cdfc..9b41610 100644 --- a/run.js +++ b/run.js @@ -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);