recursively call showconfig [#489]

This commit is contained in:
reality 2013-06-04 00:06:41 +00:00
parent 4a7fcd57b3
commit a25620bf9e
3 changed files with 22 additions and 49 deletions

View File

@ -9,11 +9,6 @@ var fs = require('fs'),
var admin = function(dbot) { var admin = function(dbot) {
this.internalAPI = { this.internalAPI = {
'getCurrentConfig': function(configKey, callback) { 'getCurrentConfig': function(configKey, callback) {
if(configKey) {
this.db.read('config', configKey, function(err, cRecord) {
if(cRecord) {
callback(cRecord.value)
} else {
var configPath = dbot.config; var configPath = dbot.config;
configKey = configKey.split('.'); configKey = configKey.split('.');
@ -21,40 +16,14 @@ var admin = function(dbot) {
if(_.has(configPath, configKey[i])) { if(_.has(configPath, configKey[i])) {
configPath = configPath[configKey[i]]; configPath = configPath[configKey[i]];
} else { } else {
callback(null); configPath = null;
break; break;
} }
} }
process.nextTick(function() {
callback(configPath); callback(configPath);
});
} }
});
} else {
callback(dbot.config);
}
}.bind(this)
}; };
this.onLoad = function() {
/*var configMap = dbot.config;
this.db.scan('config', function(config) {
if(config) {
var currentPath = configMap,
key = config.key.split('.'),
value = config.value;
for(var i=0;i<key.length-1;i++) {
if(_.has(currentPath, key[i])) {
currentPath = currentPath[key[i]];
}
}
currentPath[key[i]] = value;
}
}, function(err) { });*/
}.bind(this);
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {

View File

@ -191,7 +191,7 @@ var commands = function(dbot) {
dbot.reloadModules(); dbot.reloadModules();
}); });
} else { } else {
event.reply(dbot.t("no_config_key")); event.reply(dbot.t("no_config_key", {'path': configPath}));
} }
}.bind(this)); }.bind(this));
} else { } else {
@ -249,9 +249,13 @@ var commands = function(dbot) {
})); }));
} }
} else { } else {
event.reply(dbot.t("no_config_key")); event.reply(dbot.t("no_config_key", {'path': configPath}));
configPath = configPath.split('.');
configPath.pop();
event.params[1] = configPath.join('.');
this.commands['showconfig'](event);
} }
}); }.bind(this));
} else { } else {
event.reply(dbot.t("config_keys_location", { event.reply(dbot.t("config_keys_location", {

View File

@ -141,9 +141,9 @@
"de": "Konnte {module} nicht laden. Siehe 'status {module}'." "de": "Konnte {module} nicht laden. Siehe 'status {module}'."
}, },
"no_config_key": { "no_config_key": {
"en": "Config key doesn't exist bro", "en": "{path} doesn't exist bro",
"cy": "Nid yw allwedd cyfluniad yn bodoli, fy mrawd", "cy": "{path} cyfluniad yn bodoli, fy mrawd",
"de": "Einstellung existiert nicht, Bruder" "de": "{path} existiert nicht, Bruder"
}, },
"config_array": { "config_array": {
"en": "Config option is an array. Try '{alternate}'.", "en": "Config option is an array. Try '{alternate}'.",