mirror of
https://github.com/reality/dbot.git
synced 2024-11-24 04:49:25 +01:00
set some config options not allowed to be changes [#145]
This commit is contained in:
parent
0a2b81c0d6
commit
2f05cba960
@ -4,6 +4,8 @@ var fs = require('fs'),
|
|||||||
exec = require('child_process').exec;
|
exec = require('child_process').exec;
|
||||||
|
|
||||||
var commands = function(dbot) {
|
var commands = function(dbot) {
|
||||||
|
var noChangeConfig = [ 'servers', 'name', 'moduleNames' ];
|
||||||
|
|
||||||
var getCurrentConfigPath = function(configKey) {
|
var getCurrentConfigPath = function(configKey) {
|
||||||
var defaultConfigPath = dbot.config;
|
var defaultConfigPath = dbot.config;
|
||||||
var userConfigPath = dbot.db.config;
|
var userConfigPath = dbot.db.config;
|
||||||
@ -183,31 +185,35 @@ var commands = function(dbot) {
|
|||||||
var configKey = _.last(configPathString.split('.'));
|
var configKey = _.last(configPathString.split('.'));
|
||||||
var newOption = event.params[2];
|
var newOption = event.params[2];
|
||||||
|
|
||||||
var configPath = getCurrentConfigPath(configPathString);
|
if(!_.include(noChangeConfig, configKey)) {
|
||||||
var currentOption;
|
var configPath = getCurrentConfigPath(configPathString);
|
||||||
if(_.has(configPath['user'], configKey)) {
|
var currentOption;
|
||||||
currentOption = configPath['user'][configKey];
|
if(_.has(configPath['user'], configKey)) {
|
||||||
} else if(_.has(configPath['default'], configKey)) {
|
currentOption = configPath['user'][configKey];
|
||||||
currentOption = configPath['default'][configKey];
|
} else if(_.has(configPath['default'], configKey)) {
|
||||||
|
currentOption = configPath['default'][configKey];
|
||||||
|
} else {
|
||||||
|
event.reply("Config key doesn't exist bro");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to boolean type if config item boolean
|
||||||
|
if(_.isBoolean(currentOption)) {
|
||||||
|
newOption = (newOption == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_.isArray(currentOption)) {
|
||||||
|
event.reply("Config option is an array. Try 'pushconfig'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Same for numbers and that I assume
|
||||||
|
|
||||||
|
event.reply(configPathString + ": " + currentOption + " -> " + newOption);
|
||||||
|
configPath['user'][configKey] = newOption;
|
||||||
|
dbot.reloadModules();
|
||||||
} else {
|
} else {
|
||||||
event.reply("Config key doesn't exist bro");
|
event.reply("This config option cannot be altered while the bot is running.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to boolean type if config item boolean
|
|
||||||
if(_.isBoolean(currentOption)) {
|
|
||||||
newOption = (newOption == "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_.isArray(currentOption)) {
|
|
||||||
event.reply("Config option is an array. Try 'pushconfig'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Same for numbers and that I assume
|
|
||||||
|
|
||||||
event.reply(configPathString + ": " + currentOption + " -> " + newOption);
|
|
||||||
configPath['user'][configKey] = newOption;
|
|
||||||
dbot.reloadModules();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
'showconfig': function(event) {
|
'showconfig': function(event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user