var _ = require('underscore')._; var commands = function(dbot) { var quotes = dbot.db.quoteArrs; var commands = { // Alternative syntax to ~q '~': function(event) { commands['~q'].bind(this)(event); }, '~rmstatus': function(event) { var rmCacheCount = this.rmCache.length; if(rmCacheCount < dbot.config.quotes.rmLimit) { event.reply(dbot.t('quote_cache_auto_remove', { 'count': rmCacheCount })); } else { event.reply(dbot.t('quote_cache_manual_remove', { 'count': rmCacheCount })); } }, '~rmconfirm': function(event) { var rmCacheCount = this.rmCache.length; this.rmCache.length = 0; event.reply(dbot.t('quote_cache_cleared', { 'count': rmCacheCount })); }, '~rmdeny': function(event) { var rmCache = this.rmCache; var rmCacheCount = rmCache.length; for(var i=0;i 0) { var category = _.keys(quotes)[_.random(0, _.size(quotes) -1)]; event.reply(category + ': ' + this.internalAPI.interpolatedQuote(event.server, event.channel.name, category)); } else { event.reply(dbot.t('no_results')); } }, '~link': function(event) { var key = event.input[1].toLowerCase(); if(_.has(quotes, key)) { if(_.has(dbot.config, 'web') && _.has(dbot.config.web, 'webHost') && _.has(dbot.config.web, 'webPort')) { event.reply(dbot.t('quote_link', { 'category': key, 'url': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) })); } else { event.reply(dbot.t('web_not_configured')); } } else { event.reply(dbot.t('category_not_found', { 'category': key })); } }, }; commands['~'].regex = [/^~([\d\w\s-]*)/, 2]; commands['~q'].regex = [/^~q ([\d\w\s-]*)/, 2]; 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['~qadd'].regex = [/^~qadd ([\d\w-]+[\d\w\s-]*)[ ]?=[ ]?(.+)$/, 3]; commands['~link'].regex = [/^~link ([\d\w\s-]*)/, 2]; commands['~rmconfirm'].access = 'moderator'; commands['~rmdeny'].access = 'moderator'; return commands; }; exports.fetch = function(dbot) { return commands(dbot); };