mirror of
https://github.com/reality/dbot.git
synced 2024-12-25 20:22:39 +01:00
quote parameters
This commit is contained in:
parent
63039f4e2c
commit
77cc1ddafd
@ -4,7 +4,7 @@ var quotes = function(dbot) {
|
|||||||
var rmAllowed = true;
|
var rmAllowed = true;
|
||||||
|
|
||||||
// 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, params) {
|
||||||
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
|
if(quoteTree !== undefined && quoteTree.indexOf(key) != -1) {
|
||||||
return '';
|
return '';
|
||||||
} else if(quoteTree === undefined) {
|
} else if(quoteTree === undefined) {
|
||||||
@ -12,6 +12,8 @@ var quotes = function(dbot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var quoteString = quotes[key].random();
|
var quoteString = quotes[key].random();
|
||||||
|
|
||||||
|
// Parse quote interpolations
|
||||||
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
|
var quoteRefs = quoteString.match(/~~([\d\w\s-]*)~~/g);
|
||||||
var thisRef;
|
var thisRef;
|
||||||
|
|
||||||
@ -25,6 +27,16 @@ var quotes = function(dbot) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse quote parameters
|
||||||
|
var paramRefs = quoteString.match(/~~\$([1-9])~~/g);
|
||||||
|
var thisParam;
|
||||||
|
|
||||||
|
while(paramRefs && (thisParam = paramRefs.shift()) !== undefined) {
|
||||||
|
if(thisParam < params.length) {
|
||||||
|
quoteString = quoteString.replace("~~$" + + "~~", params[thisParam]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return quoteString;
|
return quoteString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user