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

Added filter to snippets and finally re-added ~rm back to quotes

This commit is contained in:
Luke Slater 2012-12-04 18:23:43 +00:00
parent a71c047aca
commit e687cbb429
2 changed files with 33 additions and 21 deletions

View File

@ -115,36 +115,34 @@ var quotes = function(dbot) {
} }
}, },
/*'~rm': function(data, params) { '~rm': function(event) {
if(rmAllowed == true || dbot.admin.include(data.user)) { if(rmAllowed == true || dbot.admin.include(event.user)) {
var q = data.message.valMatch(/^~rm ([\d\w\s-]*) (.+)$/, 3); var key = event.input[1].trim().toLowerCase();
if(q) { var quote = event.input[2];
if(quotes.hasOwnProperty(q[1])) {
if(!dbot.db.locks.include(q[1])) { if(quotes.hasOwnProperty(key)) {
var index = quotes[q[1]].indexOf(q[2]); if(!dbot.db.locks.include(key)) {
if(index != -1) { var category = quotes[key];
quotes[q[1]].splice(index, 1); var index = category.indexOf(quote);
if(quotes[q[1]].length === 0) { if(index !== -1) {
delete quotes[q[1]]; category.splice(index, 1);
if(category.length === 0) {
delete quotes[key];
} }
rmAllowed = false; event.reply(dbot.t('removed_from', {'category': key, 'quote': quote}));
dbot.say(data.channel, dbot.t('removed_from', {'category': q[1], 'quote': q[2]}));
} else { } else {
dbot.say(data.channel, dbot.t('q_not_exist_under', {'category': q[1], 'quote': q[2]})); event.reply(dbot.t('q_not_exist_under', {'category': key, 'quote': quote)});
} }
} else { } else {
dbot.say(data.channel, dbot.t('locked_category', {'category': q[1]})); event.reply('locked_category', {'category': key}));
} }
} else { } else {
dbot.say(data.channel, dbot.t('no_quotes', {'category': q[1]})); event.reply(dbot.t('category_not_found'));
} }
} else { } else {
dbot.say(data.channel, dbot.t('syntax_error')); event.reply(dbot.t('rmlast_spam'));
} }
} else { },
dbot.say(data.channel, dbot.t('rmlast_spam'));
}
},*/
'~qcount': function(event) { '~qcount': function(event) {
var input = event.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2); var input = event.message.valMatch(/^~qcount ([\d\w\s-]*)/, 2);
@ -215,11 +213,13 @@ var quotes = function(dbot) {
commands['~'].regex = [/^~([\d\w\s-]*)/, 2]; commands['~'].regex = [/^~([\d\w\s-]*)/, 2];
commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2]; commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2];
commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~qsearch'].regex = [/^~qsearch ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~rm'].regex = [/^~rm ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2]; commands['~rmlast'].regex = [/^~rmlast ([\d\w\s-]*)/, 2];
commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3]; commands['~qadd'].regex = [/^~qadd ([\d\w\s-]+?)[ ]?=[ ]?(.+)$/, 3];
commands['~q'].usage = '~q [category]'; commands['~q'].usage = '~q [category]';
commands['~qsearch'].usage = '~qsearch [category]=[search]'; commands['~qsearch'].usage = '~qsearch [category]=[search]';
commands['~rm'].usage = '~rm [category]=[quote to delete]';
commands['~rmlast'].usage = '~rmlast [category]' commands['~rmlast'].usage = '~rmlast [category]'
commands['~qadd'].usage = '~qadd [category]=[content]'; commands['~qadd'].usage = '~qadd [category]=[content]';

View File

@ -194,6 +194,18 @@ Object.prototype.sort = function(object, scorer) {
return sortArr.sort(function(a, b) { return a[1] - b[1]; }); return sortArr.sort(function(a, b) { return a[1] - b[1]; });
}; };
Object.prototype.filter = function(fun) {
var filtered = [];
for(var key in this) {
if(this.hasOwnProperty(key)) {
if(fun(this[key]) == true) {
filtered.push(this[key]);
}
}
}
return filtered;
}
/*** Integer ***/ /*** Integer ***/
Number.prototype.chanceIn = function(x, y) { Number.prototype.chanceIn = function(x, y) {