Add format variable to get timed effect command

This commit is contained in:
Cohee 2024-06-24 01:20:39 +03:00
parent 80496db482
commit 14879af678

View File

@ -527,6 +527,21 @@ class WorldInfoTimedEffects {
this.#checkTimedEffectOfType('cooldown', this.#buffer['cooldown'], this.#onCooldownEndedCallback.bind(this)); this.#checkTimedEffectOfType('cooldown', this.#buffer['cooldown'], this.#onCooldownEndedCallback.bind(this));
} }
/**
* Gets raw timed effect metadatum for a WI entry.
* @param {TimedEffectType} type Type of timed effect
* @param {WIScanEntry} entry WI entry
* @returns {WITimedEffect} Timed effect for the entry
*/
getEffectMetadata(type, entry) {
if (!this.isValidEffectType(type)) {
return null;
}
const key = this.#getEntryKey(entry);
return chat_metadata.timedWorldInfo[type][key];
}
/** /**
* Sets a timed effect for a WI entry. * Sets a timed effect for a WI entry.
* @param {TimedEffectType} type Type of timed effect * @param {TimedEffectType} type Type of timed effect
@ -1039,10 +1054,13 @@ function registerWorldInfoSlashCommands() {
return ''; return '';
} }
timedEffects.checkTimedEffects(); const data = timedEffects.getEffectMetadata(effect, entry);
const isActive = timedEffects.isEffectActive(effect, entry);
timedEffects.cleanUp(); if (String(args.format).trim().toLowerCase() === ARGUMENT_TYPE.NUMBER) {
return String(isActive); return String(data ? (data.end - chat.length) : 0);
}
return String(!!data);
} }
async function setTimedEffectCallback(args, value) { async function setTimedEffectCallback(args, value) {
@ -1407,8 +1425,23 @@ function registerWorldInfoSlashCommands() {
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'wi-get-timed-effect', name: 'wi-get-timed-effect',
callback: getTimedEffectCallback, callback: getTimedEffectCallback,
helpString: 'Get the current state of the timed effect for the record with the UID from the specified book.', helpString: `
returns: 'true/false - state of the effect', <div>
Get the current state of the timed effect for the record with the UID from the specified book.
</div>
<div>
<strong>Example:</strong>
<ul>
<li>
<code>/wi-get-timed-effect file=chatLore format=bool effect=sticky 123</code> - returns true or false if the effect is active or not
</li>
<li>
<code>/wi-get-timed-effect file=chatLore format=number effect=sticky 123</code> - returns the remaining duration of the effect, or 0 if inactive
</li>
</ul>
</div>
`,
returns: 'state of the effect',
namedArgumentList: [ namedArgumentList: [
SlashCommandNamedArgument.fromProps({ SlashCommandNamedArgument.fromProps({
name: 'file', name: 'file',
@ -1424,6 +1457,14 @@ function registerWorldInfoSlashCommands() {
isRequired: true, isRequired: true,
enumProvider: localEnumProviders.timedEffects, enumProvider: localEnumProviders.timedEffects,
}), }),
SlashCommandNamedArgument.fromProps({
name: 'format',
description: 'output format',
isRequired: false,
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: ARGUMENT_TYPE.BOOLEAN,
enumList: [ARGUMENT_TYPE.BOOLEAN, ARGUMENT_TYPE.NUMBER],
}),
], ],
unnamedArgumentList: [ unnamedArgumentList: [
SlashCommandArgument.fromProps({ SlashCommandArgument.fromProps({