~qrename command to rename quote categories [Close #345]

This commit is contained in:
reality 2013-04-12 18:03:52 +00:00
parent 11dcaac44c
commit 0098b07670
2 changed files with 36 additions and 0 deletions

View File

@ -270,6 +270,34 @@ var commands = function(dbot) {
}
},
// Rename a quote category
'~qrename': function(event) {
var oldName = event.input[1],
newName = event.input[2],
oldCategory = false,
newCategory = false;
this.db.search('quote_category', { 'name': newName }, function(result) {
newCategory = result;
}, function(err) {
if(!newCategory) {
this.db.search('quote_category', { 'name': oldName }, function(result) {
oldCategory = result;
}, function(err) {
oldCategory.name = newName;
this.db.save('quote_category', oldCategory.id, oldCategory, function(err) {
event.reply(dbot.t('category_renamed', {
'oldName': oldName,
'newName': newName
}));
});
}.bind(this));
} else {
event.reply(dbot.t('newcat_exists', { 'newcat': newName }));
}
}.bind(this));
},
// Link to quote web page
'~link': function(event) {
var key = event.input[1].toLowerCase(),
@ -304,10 +332,12 @@ var commands = function(dbot) {
commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
commands['~qadd'].regex = [/^~qadd ([\d\w-]+[\d\w\s-]*)[ ]?=[ ]?(.+)$/, 3];
commands['~qrename'].regex = [/^~qrename ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~link'].regex = [/^~link ([\d\w\s-]*)/, 2];
commands['~rmconfirm'].access = 'moderator';
commands['~rmdeny'].access = 'moderator';
commands['~qrename'].access = 'moderator';
return commands;
};

View File

@ -129,5 +129,11 @@
},
"web_not_configured": {
"en": "Cannot link to category. Web module is either not loaded or misconfigured."
},
"category_renamed": {
"en": "Category ~{oldName} renamed to ~{newName}."
},
"newcat_exists": {
"en": "Category ~{newcat} already exists. Delete that first or use ~qmerge."
}
}