From b7a3b6a1397892e03c76c9e0072098bd80b802ac Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 5 Jun 2013 21:00:52 +0000 Subject: [PATCH] save a seperate customconfig so not everything is saved to config.json. create saveconfig internal api function for admin [#489] --- modules/admin/admin.js | 5 +++++ run.js | 11 +++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/admin/admin.js b/modules/admin/admin.js index 25768a9..72a3c03 100644 --- a/modules/admin/admin.js +++ b/modules/admin/admin.js @@ -35,6 +35,11 @@ var admin = function(dbot) { return; } } + }, + + 'saveConfig': function() { + var config = dbot.customConfig; + fs.writeFileSync('config.json', JSON.stringify(config, null, ' ')); } }; }; diff --git a/run.js b/run.js index 48ff6f8..eb72912 100644 --- a/run.js +++ b/run.js @@ -7,7 +7,6 @@ require('./snippets'); var DBot = function() { /*** Load the DB ***/ - if(fs.existsSync('db.json')) { try { this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8')); @@ -25,7 +24,6 @@ var DBot = function() { this.reloadConfig(); /*** Load main strings ***/ - try { this.strings = JSON.parse(fs.readFileSync('strings.json', 'utf-8')); } catch(err) { @@ -65,7 +63,9 @@ DBot.prototype.reloadConfig = function() { } try { - this.config = JSON.parse(fs.readFileSync('config.json', 'utf-8')); + var configFile = fs.readFileSync('config.json', 'utf-8'); + this.config = JSON.parse(configFile); + this.customConfig = JSON.parse(configFile); } catch(err) { console.log('Config file is invalid. Stopping: ' + err); process.exit(); @@ -79,7 +79,10 @@ DBot.prototype.reloadConfig = function() { } // Load missing config directives from sample file - if(!_.has(this.config, 'modules')) this.config.modules = {}; + if(!_.has(this.customConfig, 'modules')) { + this.customConfig.modules = {}; + this.config.modules = {}; + } _.defaults(this.config, defaultConfig); };