Feat - Add expression-set-fallback slash command (#5551) * Feat - Add expression-set-fallback slash command * Fix ESLint * Fix - Use proper name convention for slash command method * Fix - Change misleading expression-set-fallback help string label * Fix - Use normal description for expression label argument * Update - Make expression-set-fallback case unsensitive Also fixed array creation by removing the spread syntax and added warning.

3a9c10d68053cf86989224554a67627affa23197

Leandro Jofré <leandrotomasjofre@gmail.com>

Signed
1 files changed, +43 -1Ignore whitespace
public/scripts/extensions/expressions/index.js+43 -1
@@ -4,7 +4,7 @@ import { characters, eventSource, event_types, generateQuietPrompt, generateRaw,
44import { dragElement, isMobile } from '../../RossAscends-mods.js';
55import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js';
66import { loadMovingUIState, performFuzzySearch, power_user } from '../../power-user.js';
77import { onlyUnique, debounce, getCharaFilename, trimToEndSentence, trimToStartSentence, waitUntilCondition, findChar, isFalseBoolean, includesIgnoreCaseAndAccents } from '../../utils.js';
88import { hideMutedSprites, selected_group } from '../../group-chats.js';
99import { isJsonSchemaSupported } from '../../textgen-settings.js';
1010import { debounce_timeout } from '../../constants.js';
@@ -787,6 +787,30 @@ async function setSpriteSlashCommand({ type }, searchTerm) {
787787}
788788
789789/**
790+ * @param {string} expressionName - Label of the expression to set as fallback
791+ */
792+function setFallBackExpressionSlashCommand(args, expressionName) {
793+ expressionName = expressionName.trim().toLowerCase();
794+
795+ const select = /** @type {HTMLSelectElement} */(document.getElementById('expression_fallback'));
796+ const fallbackExpressions = Array
797+ .from(select?.options || [])
798+ .map(option => option.value)
799+ .filter(expression => expression?.length > 0);
800+
801+ const expressionMatch = fallbackExpressions.find(expression => includesIgnoreCaseAndAccents(expression, expressionName));
802+
803+ if (!expressionMatch) {
804+ toastr.warning(t`No expression found for search term ${expressionName}`, t`Set Fallback Expression`);
805+ return '';
806+ }
807+
808+ $(select).val(expressionMatch).trigger('change');
809+
810+ return expressionMatch;
811+}
812+
813+/**
790814 * Returns the sprite folder name (including override) for a character.
791815 * @param {object} char Character object
792816 * @param {string} char.avatar Avatar filename with extension
@@ -2317,6 +2341,24 @@ export async function init() {
23172341 returns: 'The currently set expression label after setting it.',
23182342 }));
23192343 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
2344+ name: 'expression-set-fallback',
2345+ callback: setFallBackExpressionSlashCommand,
2346+ unnamedArgumentList: [
2347+ SlashCommandArgument.fromProps({
2348+ description: 'expression label to set',
2349+ typeList: [ARGUMENT_TYPE.STRING],
2350+ isRequired: true,
2351+ enumProvider: () => [
2352+ new SlashCommandEnumValue('#none', 'Sets the fallback expression to no image'),
2353+ new SlashCommandEnumValue('#emoji', 'Sets the fallback expression to emojis'),
2354+ ...localEnumProviders.expressions(),
2355+ ],
2356+ }),
2357+ ],
2358+ helpString: 'Force sets the expression fallback for all characters.',
2359+ returns: 'The currently set expression label after setting it.',
2360+ }));
2361+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
23202362 name: 'expression-folder-override',
23212363 aliases: ['spriteoverride', 'costume'],
23222364 callback: setSpriteFolderCommand,