showconfig and setconfig for root config options [#145]

This commit is contained in:
reality 2013-01-20 16:35:17 +00:00
parent fedb9335a2
commit a80f00038d
2 changed files with 36 additions and 25 deletions

View File

@ -5,19 +5,21 @@ var fs = require('fs'),
var commands = function(dbot) { var commands = function(dbot) {
var getCurrentConfigPath = function(configKey) { var getCurrentConfigPath = function(configKey) {
var configKey = configKey.split('.'); var defaultConfigPath = dbot.config;
var userConfigPath = dbot.db.config;
defaultConfigPath = dbot.config; if(configKey) {
userConfigPath = dbot.db.config; var configKey = configKey.split('.');
for(var i=0;i<configKey.length-1;i++) { for(var i=0;i<configKey.length-1;i++) {
if(_.has(defaultConfigPath, configKey[i])) { if(_.has(defaultConfigPath, configKey[i])) {
if(!_.has(userConfigPath, configKey[i])) { if(!_.has(userConfigPath, configKey[i])) {
userConfigPath[configKey[i]] = {}; userConfigPath[configKey[i]] = {};
}
userConfigPath = userConfigPath[configKey[i]];
defaultConfigPath = defaultConfigPath[configKey[i]];
} else {
return false;
} }
userConfigPath = userConfigPath[configKey[i]];
defaultConfigPath = defaultConfigPath[configKey[i]];
} else {
return false;
} }
} }
@ -210,22 +212,27 @@ var commands = function(dbot) {
'showconfig': function(event) { 'showconfig': function(event) {
var configPathString = event.params[1]; var configPathString = event.params[1];
var configKey = _.last(configPathString.split('.'));
var configPath = getCurrentConfigPath(configPathString); var configPath = getCurrentConfigPath(configPathString);
if(!_.has(configPath['default'], configKey)) { if(configPathString) {
event.reply("Config path doesn't exist"); var configKey = _.last(configPathString.split('.'));
return
}
if(_.isObject(configPath['default'][configKey])) { if(!_.has(configPath['default'], configKey)) {
event.reply('Config keys in ' + configPathString + ': ' + Object.keys(configPath['default'][configKey])); event.reply("Config path doesn't exist");
} else { return;
var currentOption = configPath['default'][configKey];
if(_.has(configPath['user'][configKey])) {
currentOption = configPath['user'][configKey];
} }
event.reply(configPathString + ': ' + currentOption);
if(_.isObject(configPath['default'][configKey])) {
event.reply('Config keys in ' + configPathString + ': ' + Object.keys(configPath['default'][configKey]));
} else {
var currentOption = configPath['default'][configKey];
if(_.has(configPath['user'], configKey)) {
currentOption = configPath['user'][configKey];
}
event.reply(configKey + ': ' + currentOption);
}
} else {
event.reply('Config keys in root: ' + Object.keys(configPath['default']));
} }
} }
}; };

View File

@ -37,6 +37,10 @@ var dent = function(dbot) {
dbot.api.command.addHook('~qadd', function(key, text) { dbot.api.command.addHook('~qadd', function(key, text) {
this.api.post(key + ': ' + text); this.api.post(key + ': ' + text);
}.bind(this)); }.bind(this));
if(_.has(dbot.modules, 'quotes')) {
}
}.bind(this); }.bind(this);
}; };