mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-10 00:50:11 +01:00
Unregister function for macro registration
This commit is contained in:
parent
cf56bfb6a9
commit
b8295ac8f5
@ -7800,6 +7800,7 @@ window['SillyTavern'].getContext = function () {
|
||||
*/
|
||||
registerHelper: () => { },
|
||||
registerMacro: MacrosParser.registerMacro.bind(MacrosParser),
|
||||
unregisterMacro: MacrosParser.unregisterMacro.bind(MacrosParser),
|
||||
registedDebugFunction: registerDebugFunction,
|
||||
/**
|
||||
* @deprecated Use renderExtensionTemplateAsync instead.
|
||||
|
@ -58,6 +58,30 @@ export class MacrosParser {
|
||||
this.#macros.set(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a global macro with the given key
|
||||
*
|
||||
* @param {string} key Macro name (key)
|
||||
*/
|
||||
static unregisterMacro(key) {
|
||||
if (typeof key !== 'string') {
|
||||
throw new Error('Macro key must be a string');
|
||||
}
|
||||
|
||||
// Allowing surrounding whitespace would just create more confusion...
|
||||
key = key.trim();
|
||||
|
||||
if (!key) {
|
||||
throw new Error('Macro key must not be empty or whitespace only');
|
||||
}
|
||||
|
||||
const deleted = this.#macros.delete(key);
|
||||
|
||||
if (!deleted) {
|
||||
console.warn(`Macro ${key} was not registered`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the env object with macro values from the current context.
|
||||
* @param {EnvObject} env Env object for the current evaluation context
|
||||
|
Loading…
x
Reference in New Issue
Block a user