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.
Signed| @@ -4,7 +4,7 @@ import { characters, eventSource, event_types, generateQuietPrompt, generateRaw, | |||
| 4 | import { dragElement, isMobile } from '../../RossAscends-mods.js'; | 4 | import { dragElement, isMobile } from '../../RossAscends-mods.js'; |
| 5 | import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js'; | 5 | import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js'; |
| 6 | import { loadMovingUIState, performFuzzySearch, power_user } from '../../power-user.js'; | 6 | import { loadMovingUIState, performFuzzySearch, power_user } from '../../power-user.js'; |
| 7 | import { onlyUnique, debounce, getCharaFilename, trimToEndSentence, trimToStartSentence, waitUntilCondition, findChar, isFalseBoolean } from '../../utils.js'; | 7 | import { onlyUnique, debounce, getCharaFilename, trimToEndSentence, trimToStartSentence, waitUntilCondition, findChar, isFalseBoolean, includesIgnoreCaseAndAccents } from '../../utils.js'; |
| 8 | import { hideMutedSprites, selected_group } from '../../group-chats.js'; | 8 | import { hideMutedSprites, selected_group } from '../../group-chats.js'; |
| 9 | import { isJsonSchemaSupported } from '../../textgen-settings.js'; | 9 | import { isJsonSchemaSupported } from '../../textgen-settings.js'; |
| 10 | import { debounce_timeout } from '../../constants.js'; | 10 | import { debounce_timeout } from '../../constants.js'; |
| @@ -787,6 +787,30 @@ async function setSpriteSlashCommand({ type }, searchTerm) { | |||
| 787 | } | 787 | } |
| 788 | 788 | ||
| 789 | /** | 789 | /** |
| 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 | /** | ||
| 790 | * Returns the sprite folder name (including override) for a character. | 814 | * Returns the sprite folder name (including override) for a character. |
| 791 | * @param {object} char Character object | 815 | * @param {object} char Character object |
| 792 | * @param {string} char.avatar Avatar filename with extension | 816 | * @param {string} char.avatar Avatar filename with extension |
| @@ -2317,6 +2341,24 @@ export async function init() { | |||
| 2317 | returns: 'The currently set expression label after setting it.', | 2341 | returns: 'The currently set expression label after setting it.', |
| 2318 | })); | 2342 | })); |
| 2319 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 2343 | 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({ | ||
| 2320 | name: 'expression-folder-override', | 2362 | name: 'expression-folder-override', |
| 2321 | aliases: ['spriteoverride', 'costume'], | 2363 | aliases: ['spriteoverride', 'costume'], |
| 2322 | callback: setSpriteFolderCommand, | 2364 | callback: setSpriteFolderCommand, |