substitute scoped macros from ancestors

This commit is contained in:
LenAnderson
2024-03-29 10:03:54 -04:00
parent 84907aebf0
commit 65edba98a6
2 changed files with 5 additions and 2 deletions

View File

@ -18,8 +18,8 @@ export class SlashCommandClosure {
.replace(/{{pipe}}/g, this.scope.pipe)
.replace(/{{var::(\w+?)}}/g, (_, key)=>this.scope.getVariable(key))
;
for (const key of Object.keys(this.scope.macros)) {
text = text.replace(new RegExp(`{{${key}}}`), this.scope.macros[key]);
for (const { key, value } of this.scope.macroList) {
text = text.replace(new RegExp(`{{${key}}}`), value);
}
return text;
}

View File

@ -3,6 +3,9 @@ export class SlashCommandScope {
/**@type {Map<String, Object>}*/ variables = {};
// @ts-ignore
/**@type {Map<String, Object>}*/ macros = {};
get macroList() {
return [...Object.keys(this.macros).map(key=>({ key, value:this.macros[key] })), ...(this.parent?.macroList ?? [])];
}
/**@type {SlashCommandScope}*/ parent;
/**@type {String}*/ #pipe;
get pipe() {