forked from GitHub/dbot
Fixed quotes
This commit is contained in:
parent
b09a962aa0
commit
9001cfefcf
21
run.js
21
run.js
@ -63,20 +63,17 @@ var DBot = function(timers) {
|
|||||||
|
|
||||||
// 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
|
||||||
DBot.prototype.interpolatedQuote = function(key, quoteTree) {
|
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 = [];
|
else if( quoteTree === undefined ) quoteTree = [];
|
||||||
var quoteString = this.db.quoteArrs[key].random();
|
var quoteString = this.db.quoteArrs[key].random();
|
||||||
var quoteRefs;
|
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
|
||||||
while( (quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/)) ) {
|
var thisRef;
|
||||||
quoteRefs = quoteRefs.slice(1);
|
while( quoteRefs && (thisRef = quoteRefs.shift()) !== undefined ) {
|
||||||
for(var i=0;i<quoteRefs.length;i++) {
|
var cleanRef = this.cleanNick(thisRef.replace(/^~~/,'').replace(/~~$/,'').trim());
|
||||||
var cleanRef = this.cleanNick(quoteRefs[i].trim());
|
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
|
||||||
if (this.db.quoteArrs.hasOwnProperty(cleanRef)) {
|
quoteTree.push( key );
|
||||||
quoteTree.push( cleanRef );
|
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
|
||||||
console.log( "Tree: " + quoteTree, "clean: " + cleanRef );
|
quoteTree.pop();
|
||||||
quoteString = quoteString.replace("~~"+cleanRef+"~~", this.interpolatedQuote(cleanRef, quoteTree.slice()));
|
|
||||||
quoteTree.pop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return quoteString;
|
return quoteString;
|
||||||
|
Loading…
Reference in New Issue
Block a user