From 4bd7364a8eccfff3cae94d07c1c28ec0dff319b2 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 27 Jan 2024 13:22:22 -0500 Subject: [PATCH] Change macro substitution order --- public/script.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/script.js b/public/script.js index 97e63c911..984d963fb 100644 --- a/public/script.js +++ b/public/script.js @@ -2163,10 +2163,6 @@ function scrollChatToBottom() { function substituteParams(content, _name1, _name2, _original, _group, _replaceCharacterCard = true) { const environment = {}; - environment.user = _name1 ?? name1; - environment.char = _name2 ?? name2; - environment.group = environment.charIfNotGroup = _group ?? name2; - let substitutedOriginal = false; environment.original = () => { // Only substitute {{original}} on its first occurrence @@ -2185,6 +2181,12 @@ function substituteParams(content, _name1, _name2, _original, _group, _replaceCh environment.mesExamples = fields.mesExamples || ''; } + // Must be substituted last so that they're replaced inside {{description}} + // TODO: evaluate macros recursively so we don't need to rely on substitution order + environment.user = _name1 ?? name1; + environment.char = _name2 ?? name2; + environment.group = environment.charIfNotGroup = _group ?? name2; + return evaluateMacros(content, environment); }