3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 16:09:27 +01:00

save a seperate customconfig so not everything is saved to config.json. create saveconfig internal api function for admin [#489]

This commit is contained in:
reality 2013-06-05 21:00:52 +00:00
parent eafc2dbee1
commit b7a3b6a139
2 changed files with 12 additions and 4 deletions

View File

@ -35,6 +35,11 @@ var admin = function(dbot) {
return;
}
}
},
'saveConfig': function() {
var config = dbot.customConfig;
fs.writeFileSync('config.json', JSON.stringify(config, null, ' '));
}
};
};

11
run.js
View File

@ -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);
};