fix scope for closure arguments

This commit is contained in:
LenAnderson
2024-04-02 09:47:06 -04:00
parent e0e89959b9
commit 965b996dab

View File

@ -18,12 +18,13 @@ export class SlashCommandClosure {
this.scope = new SlashCommandScope(parent); this.scope = new SlashCommandScope(parent);
} }
substituteParams(text) { substituteParams(text, scope = null) {
scope = scope ?? this.scope;
text = substituteParams(text) text = substituteParams(text)
.replace(/{{pipe}}/g, this.scope.pipe) .replace(/{{pipe}}/g, scope.pipe)
.replace(/{{var::(\w+?)}}/g, (_, key)=>this.scope.getVariable(key)) .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); text = text.replace(new RegExp(`{{${key}}}`), value);
} }
return text; return text;
@ -89,7 +90,7 @@ export class SlashCommandClosure {
v = closure; v = closure;
} }
} else { } else {
v = this.substituteParams(v); v = this.substituteParams(v, this.scope.parent);
} }
// unescape value // unescape value
if (typeof v == 'string') { if (typeof v == 'string') {