3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 20:22:39 +01:00

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