diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 90951cb..c1abaee 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -6,11 +6,30 @@ var _ = require('underscore')._, var commands = function(dbot) { var quotes = dbot.db.quoteArrs; var commands = { - // Alternative syntax to ~q + + /*** Quote Retrieval ***/ + + // Alternative ~q syntax '~': function(event) { commands['~q'].bind(this)(event); }, + // Retrieve quote from a category in the database. + '~q': function(event) { + var name = event.input[1].trim().toLowerCase(); + this.db.read('quote_category', name, function(err, category) { + if(!err) { + var quoteIndex = _.random(0, category.length - 1); + event.reply(name + ': ' + category[quoteIndex]); + } else if(err instanceof NoSuchThingError) { + event.reply(dbot.t('category_not_found', { 'category': name })); + } + }); + }, + + /*** Quote Removal ***/ + + // Show number of quotes in removal cache '~rmstatus': function(event) { var rmCacheCount = this.rmCache.length; if(rmCacheCount < dbot.config.quotes.rmLimit) { @@ -22,6 +41,7 @@ var commands = function(dbot) { } }, + // Confirm removal of quote cache '~rmconfirm': function(event) { var rmCacheCount = this.rmCache.length; this.rmCache.length = 0; @@ -29,99 +49,46 @@ var commands = function(dbot) { { 'count': rmCacheCount })); }, + // Reinstate all quotes in removal cache '~rmdeny': function(event) { var rmCache = this.rmCache; var rmCacheCount = rmCache.length; - for(var i=0;i