From 1673c8846b12e861b8efbd2b44cf1b335fc7a211 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 21 Jan 2013 17:39:21 +0000 Subject: [PATCH] basic dependencies as per [#85] --- modules/poll/config.json | 3 ++- run.js | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) 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);