cleaned interpolatedquote so it fits with the coding style

This commit is contained in:
Luke Slater 2012-03-15 12:52:47 +00:00
parent 7a5a25134e
commit 05fc0418d3

View File

@ -5,19 +5,27 @@ var quotes = function(dbot) {
// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it
var interpolatedQuote = function(key, quoteTree) {
if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) { console.log('nrll'); return ''; }
else if( quoteTree === undefined ) quoteTree = [];
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
console.log('nrll');
return '';
} else if(quoteTree === undefined) {
quoteTree = [];
}
var quoteString = quotes[key].random();
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
var thisRef;
while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) {
while(quoteRefs && (thisRef = quoteRefs.shift()) !== undefined) {
var cleanRef = dbot.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
if (quotes.hasOwnProperty(cleanRef)) {
quoteTree.push( key );
quoteString = quoteString.replace("~~"+cleanRef+"~~", interpolatedQuote(cleanRef, quoteTree.slice()));
quoteTree.push(key);
quoteString = quoteString.replace("~~" + cleanRef + "~~",
interpolatedQuote(cleanRef, quoteTree.slice()));
quoteTree.pop();
}
}
return quoteString;
};