From a2ea1b8c33aa86c3b0c934e0fc1f5ca2dc624eeb Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 20 Jan 2013 14:45:58 +0000 Subject: [PATCH] Load module config options from db store [#145] --- run.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/run.js b/run.js index 0528cfc..2faff6e 100644 --- a/run.js +++ b/run.js @@ -34,6 +34,9 @@ var DBot = function(timers) { if(!this.db) { // If it wasn't empty this.db = JSON.parse(rawDB); } + if(!_.has(this.db, 'config')) { + this.db.config = {}; + } } catch(err) { console.log('Syntax error in db.json. Stopping: ' + err); process.exit(); @@ -157,12 +160,19 @@ DBot.prototype.reloadModules = function() { try { // Load the module config data var config = {}; + + if(_.has(this.db.config, name)) { + config = this.db.config; + } + try { - config = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8')); + var defaultConfig = JSON.parse(fs.readFileSync(moduleDir + 'config.json', 'utf-8')); + config = _.defaults(config, defaultConfig); } catch(err) { // Invalid or no config data } + // Load module config this.config[name] = config; _.each(config.dbKeys, function(dbKey) { if(!_.has(this.db, dbKey)) { @@ -170,6 +180,8 @@ 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);