Fixed quotes

This commit is contained in:
Daniel Evans 2012-03-13 16:06:19 +00:00
parent b09a962aa0
commit 9001cfefcf

15
run.js
View File

@ -63,22 +63,19 @@ var DBot = function(timers) {
// Retrieve a random quote from a given category, interpolating any quote references (~~QUOTE CATEGORY~~) within it
DBot.prototype.interpolatedQuote = function(key, quoteTree) {
if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) return '';
if( quoteTree !== undefined && quoteTree.indexOf( key ) != -1 ) { console.log('nrll'); return ''; }
else if( quoteTree === undefined ) quoteTree = [];
var quoteString = this.db.quoteArrs[key].random();
var quoteRefs;
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) {
quoteRefs = quoteRefs.slice(1);
for(var i=0;i<quoteRefs.length;i++) {
var cleanRef = this.cleanNick(quoteRefs[i].trim());
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
var thisRef;
while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) {
var cleanRef = this.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
quoteTree.push( cleanRef );
console.log( "Tree: " + quoteTree, "clean: " + cleanRef );
quoteTree.push( key );
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
quoteTree.pop();
}
}
}
return quoteString;
};