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,10 +5,11 @@ 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])) {
@ -20,6 +21,7 @@ var commands = function(dbot) {
return false; return false;
} }
} }
}
return { return {
'user': userConfigPath, 'user': userConfigPath,
@ -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(configPathString) {
var configKey = _.last(configPathString.split('.'));
if(!_.has(configPath['default'], configKey)) { if(!_.has(configPath['default'], configKey)) {
event.reply("Config path doesn't exist"); event.reply("Config path doesn't exist");
return return;
} }
if(_.isObject(configPath['default'][configKey])) { if(_.isObject(configPath['default'][configKey])) {
event.reply('Config keys in ' + configPathString + ': ' + Object.keys(configPath['default'][configKey])); event.reply('Config keys in ' + configPathString + ': ' + Object.keys(configPath['default'][configKey]));
} else { } else {
var currentOption = configPath['default'][configKey]; var currentOption = configPath['default'][configKey];
if(_.has(configPath['user'][configKey])) { if(_.has(configPath['user'], configKey)) {
currentOption = configPath['user'][configKey]; currentOption = configPath['user'][configKey];
} }
event.reply(configPathString + ': ' + currentOption); 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);
}; };