mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Unregister function for macro registration
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user