From 965b996dab9ea64a8f825d0179b3e7b97445d023 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Tue, 2 Apr 2024 09:47:06 -0400 Subject: [PATCH] fix scope for closure arguments --- public/scripts/slash-commands/SlashCommandClosure.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/scripts/slash-commands/SlashCommandClosure.js b/public/scripts/slash-commands/SlashCommandClosure.js index 5d96a51fb..a86153c44 100644 --- a/public/scripts/slash-commands/SlashCommandClosure.js +++ b/public/scripts/slash-commands/SlashCommandClosure.js @@ -18,12 +18,13 @@ export class SlashCommandClosure { this.scope = new SlashCommandScope(parent); } - substituteParams(text) { + substituteParams(text, scope = null) { + scope = scope ?? this.scope; text = substituteParams(text) - .replace(/{{pipe}}/g, this.scope.pipe) - .replace(/{{var::(\w+?)}}/g, (_, key)=>this.scope.getVariable(key)) + .replace(/{{pipe}}/g, scope.pipe) + .replace(/{{var::(\w+?)}}/g, (_, key)=>scope.getVariable(key)) ; - for (const { key, value } of this.scope.macroList) { + for (const { key, value } of scope.macroList) { text = text.replace(new RegExp(`{{${key}}}`), value); } return text; @@ -89,7 +90,7 @@ export class SlashCommandClosure { v = closure; } } else { - v = this.substituteParams(v); + v = this.substituteParams(v, this.scope.parent); } // unescape value if (typeof v == 'string') {