From 71c0bdb760a971490930c48a5c66c31765ba27be Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 23 Mar 2013 13:24:13 +0000 Subject: [PATCH] all commands but ~qstats and ~rq in quotes use databank [#272] --- modules/quotes/commands.js | 230 +++++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 100 deletions(-) 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