From 25d26b55863390c350e8c3c8ae48057e6b010a6b Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 13 Aug 2015 14:36:22 +0000 Subject: [PATCH] quote interpolation recursion --- modules/quotes/quotes.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/modules/quotes/quotes.js b/modules/quotes/quotes.js index 459d163..4b7b2a7 100644 --- a/modules/quotes/quotes.js +++ b/modules/quotes/quotes.js @@ -11,10 +11,9 @@ var quotes = function(dbot) { this.internalAPI = { // Parse quote interpolations 'interpolatedQuote': function(server, channel, username, key, quote, callback) { - console.log(quote); var quoteRefs = quote.match(/~~([\d\w\s-]*)~~/g); if(quoteRefs) { - var ref = this.internalAPI.cleanRef(quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim()); + var ref = quoteRefs[0].replace(/^~~/,'').replace(/~~$/,'').trim(); if(ref === '-nicks-') { if(_.has(dbot.instance.connections[server].channels, channel)) { var nicks = @@ -30,27 +29,19 @@ var quotes = function(dbot) { username, key, quote, callback); } else { this.api.getQuote(ref, function(interQuote) { - if(!interQuote || ref == key) { + if(!interQuote) { interQuote = ''; } quote = quote.replace('~~' + ref + '~~', interQuote); this.internalAPI.interpolatedQuote(server, channel, username, key, quote, callback); - }.bind(this)); + }.bind(this), true); } } else { callback(quote); } }.bind(this), - 'cleanRef': function(key) { - key = key.toLowerCase(); - while(key.slice(-1) == '_') { - key = key.substring(0, key.length-1); - } - return key; - }, - 'resetRemoveTimer': function(event, key, quote) { this.rmAllowed = false; setTimeout(function() { @@ -107,10 +98,17 @@ var quotes = function(dbot) { }, - 'getQuote': function(key, callback) { + 'getQuote': function(key, callback, removeRefs) { this.api.getQuoteCategory(key, function(category) { if(category) { var quotes = category.quotes; + + if(removeRefs) { + quotes = _.filter(quotes, function(q) { + return !q.match('~~'+key+'~~'); + }); + } + var index = _.random(0, quotes.length - 1); callback(quotes[index]); } else { @@ -120,7 +118,6 @@ var quotes = function(dbot) { }, 'getInterpolatedQuote': function(server, channel, username, key, callback) { - console.log(key); key = key.trim().toLowerCase(), this.api.getQuote(key, function(quote) {