From b24bd63cd0ba0ece0bf17ba2c2420e193ad2d7b8 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 21 Jan 2013 00:05:42 +0000 Subject: [PATCH] load root config changes [#145] --- run.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/run.js b/run.js index 69fe227..7b6cdfc 100644 --- a/run.js +++ b/run.js @@ -5,24 +5,8 @@ var fs = require('fs'), require('./snippets'); var DBot = function(timers) { - // Load config - try { - this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); - } catch(err) { - console.log('Config file is invalid. Stopping'); - process.exit(); - } - - try { - var defaultConfig = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8')); - } catch(err) { - console.log('Error loading sample config. Bugger off this should not even be edited. Stopping.'); - process.exit(); - } - - // Load missing config directives from sample file - _.defaults(this.config, defaultConfig); - + + // Load DB var rawDB; try { var rawDB = fs.readFileSync('db.json', 'utf-8'); @@ -42,6 +26,25 @@ var DBot = function(timers) { process.exit(); } + // Load config + this.config = this.db.config; + try { + _.defaults(this.config, JSON.parse(fs.readFileSync('config.json', 'utf-8'))); + } catch(err) { + console.log('Config file is invalid. Stopping'); + process.exit(); + } + + try { + var defaultConfig = JSON.parse(fs.readFileSync('config.json.sample', 'utf-8')); + } catch(err) { + console.log('Error loading sample config. Bugger off this should not even be edited. Stopping.'); + process.exit(); + } + + // Load missing config directives from sample file + _.defaults(this.config, defaultConfig); + // Load Strings file try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); @@ -122,6 +125,9 @@ DBot.prototype.reloadModules = function() { this.commandMap = {}; // Map of which commands belong to which modules this.usage = {}; this.timers.clearTimers(); + + // Load config changes + _.extend(this.config, this.db.config); try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8'));