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

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 getCurrentConfigPath = function(configKey) {
var configKey = configKey.split('.');
var defaultConfigPath = dbot.config;
var userConfigPath = dbot.db.config;
defaultConfigPath = dbot.config;
userConfigPath = dbot.db.config;
if(configKey) {
var configKey = configKey.split('.');
for(var i=0;i<configKey.length-1;i++) {
if(_.has(defaultConfigPath, configKey[i])) {
if(!_.has(userConfigPath, configKey[i])) {
@ -20,6 +21,7 @@ var commands = function(dbot) {
return false;
}
}
}
return {
'user': userConfigPath,
@ -210,22 +212,27 @@ var commands = function(dbot) {
'showconfig': function(event) {
var configPathString = event.params[1];
var configKey = _.last(configPathString.split('.'));
var configPath = getCurrentConfigPath(configPathString);
if(configPathString) {
var configKey = _.last(configPathString.split('.'));
if(!_.has(configPath['default'], configKey)) {
event.reply("Config path doesn't exist");
return
return;
}
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])) {
if(_.has(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) {
this.api.post(key + ': ' + text);
}.bind(this));
if(_.has(dbot.modules, 'quotes')) {
}
}.bind(this);
};