diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 71be1e422..dc8ce8ba6 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -12,6 +12,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' import { isFunctionCallingSupported } from '../../openai.js'; import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; +import { findChar } from '../../slash-commands.js'; export { MODULE_NAME }; const MODULE_NAME = 'expressions'; @@ -2105,14 +2106,20 @@ function migrateSettings() { })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'lastsprite', - callback: (_, value) => lastExpression[String(value).trim()] ?? '', + callback: (_, name) => { + if (typeof name !== 'string') throw new Error('name must be a string'); + const char = findChar({ name: name }); + const sprite = lastExpression[char?.name ?? name] ?? ''; + return sprite; + }, returns: 'the last set sprite / expression for the named character.', unnamedArgumentList: [ SlashCommandArgument.fromProps({ - description: 'character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], isRequired: true, enumProvider: commonEnumProviders.characters('character'), + forceEnum: true, }), ], helpString: 'Returns the last set sprite / expression for the named character.', diff --git a/public/scripts/extensions/gallery/index.js b/public/scripts/extensions/gallery/index.js index da617c683..a39634603 100644 --- a/public/scripts/extensions/gallery/index.js +++ b/public/scripts/extensions/gallery/index.js @@ -441,6 +441,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ description: 'character name', typeList: [ARGUMENT_TYPE.STRING], enumProvider: commonEnumProviders.characters('character'), + forceEnum: true, }), SlashCommandNamedArgument.fromProps({ name: 'group', diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 95e8586ec..4be6bca7b 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -210,7 +210,7 @@ export function initDefaultSlashCommands() { ], unnamedArgumentList: [ SlashCommandArgument.fromProps({ - description: 'Character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], enumProvider: commonEnumProviders.characters('character'), forceEnum: false, @@ -700,7 +700,7 @@ export function initDefaultSlashCommands() { aliases: ['addmember', 'memberadd'], unnamedArgumentList: [ SlashCommandArgument.fromProps({ - description: 'character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], isRequired: true, enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [], @@ -2810,26 +2810,23 @@ async function removeGroupMemberCallback(_, arg) { return ''; } -async function addGroupMemberCallback(_, arg) { +async function addGroupMemberCallback(_, name) { if (!selected_group) { toastr.warning('Cannot run /memberadd command outside of a group chat.'); return ''; } - if (!arg) { + if (!name) { console.warn('WARN: No argument provided for /memberadd command'); return ''; } - arg = arg.trim(); - const chid = findCharacterIndex(arg); - - if (chid === -1) { - console.warn(`WARN: No character found for argument ${arg}`); + const character = findChar({ name: name, preferCurrentChar: false }); + if (!character) { + console.warn(`WARN: No character found for argument ${name}`); return ''; } - const character = characters[chid]; const group = groups.find(x => x.id === selected_group); if (!group || !Array.isArray(group.members)) { diff --git a/public/scripts/tags.js b/public/scripts/tags.js index c56e0d1cb..447e01ded 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -26,6 +26,7 @@ import { debounce_timeout } from './constants.js'; import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js'; import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; import { renderTemplateAsync } from './templates.js'; +import { findChar } from './slash-commands.js'; export { TAG_FOLDER_TYPES, @@ -507,7 +508,7 @@ export function getTagKeyForEntityElement(element) { */ export function searchCharByName(charName, { suppressLogging = false } = {}) { const entity = charName - ? (characters.find(x => x.name === charName) || groups.find(x => x.name == charName)) + ? (findChar({ name: charName }) || groups.find(x => equalsIgnoreCaseAndAccents(x.name, charName))) : (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]); const key = getTagKeyForEntity(entity); if (!key) { @@ -1861,8 +1862,9 @@ function registerTagsSlashCommands() { return String(result); }, namedArgumentList: [ - SlashCommandNamedArgument.fromProps({ name: 'name', - description: 'Character name', + SlashCommandNamedArgument.fromProps({ + name: 'name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], defaultValue: '{{char}}', enumProvider: commonEnumProviders.characters(), @@ -1907,7 +1909,7 @@ function registerTagsSlashCommands() { }, namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'name', - description: 'Character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], defaultValue: '{{char}}', enumProvider: commonEnumProviders.characters(), @@ -1950,7 +1952,7 @@ function registerTagsSlashCommands() { namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'name', - description: 'Character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], defaultValue: '{{char}}', enumProvider: commonEnumProviders.characters(), @@ -1993,7 +1995,7 @@ function registerTagsSlashCommands() { namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'name', - description: 'Character name', + description: 'Character name - or unique character identifier (avatar key)', typeList: [ARGUMENT_TYPE.STRING], defaultValue: '{{char}}', enumProvider: commonEnumProviders.characters(),