mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
substitute scoped macros from ancestors
This commit is contained in:
@ -18,8 +18,8 @@ export class SlashCommandClosure {
|
|||||||
.replace(/{{pipe}}/g, this.scope.pipe)
|
.replace(/{{pipe}}/g, this.scope.pipe)
|
||||||
.replace(/{{var::(\w+?)}}/g, (_, key)=>this.scope.getVariable(key))
|
.replace(/{{var::(\w+?)}}/g, (_, key)=>this.scope.getVariable(key))
|
||||||
;
|
;
|
||||||
for (const key of Object.keys(this.scope.macros)) {
|
for (const { key, value } of this.scope.macroList) {
|
||||||
text = text.replace(new RegExp(`{{${key}}}`), this.scope.macros[key]);
|
text = text.replace(new RegExp(`{{${key}}}`), value);
|
||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ export class SlashCommandScope {
|
|||||||
/**@type {Map<String, Object>}*/ variables = {};
|
/**@type {Map<String, Object>}*/ variables = {};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
/**@type {Map<String, Object>}*/ macros = {};
|
/**@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 {SlashCommandScope}*/ parent;
|
||||||
/**@type {String}*/ #pipe;
|
/**@type {String}*/ #pipe;
|
||||||
get pipe() {
|
get pipe() {
|
||||||
|
Reference in New Issue
Block a user