Update more commands for new char find - Update /member-add to utilize new char find functionality - Update /tag-add, /tag-remove, /tag-exists and /tag-list to utilize new char find functionality . Update /lastsprite to utilize new char find functionality
| @@ -12,6 +12,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | |||
| 12 | import { isFunctionCallingSupported } from '../../openai.js'; | 12 | import { isFunctionCallingSupported } from '../../openai.js'; |
| 13 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; | 13 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; |
| 14 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; | 14 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 15 | import { findChar } from '../../slash-commands.js'; | ||
| 15 | export { MODULE_NAME }; | 16 | export { MODULE_NAME }; |
| 16 | 17 | ||
| 17 | const MODULE_NAME = 'expressions'; | 18 | const MODULE_NAME = 'expressions'; |
| @@ -2105,14 +2106,20 @@ function migrateSettings() { | |||
| 2105 | })); | 2106 | })); |
| 2106 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 2107 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 2107 | name: 'lastsprite', | 2108 | name: 'lastsprite', |
| 2108 | callback: (_, value) => lastExpression[String(value).trim()] ?? '', | 2109 | callback: (_, name) => { |
| 2110 | if (typeof name !== 'string') throw new Error('name must be a string'); | ||
| 2111 | const char = findChar({ name: name }); | ||
| 2112 | const sprite = lastExpression[char?.name ?? name] ?? ''; | ||
| 2113 | return sprite; | ||
| 2114 | }, | ||
| 2109 | returns: 'the last set sprite / expression for the named character.', | 2115 | returns: 'the last set sprite / expression for the named character.', |
| 2110 | unnamedArgumentList: [ | 2116 | unnamedArgumentList: [ |
| 2111 | SlashCommandArgument.fromProps({ | 2117 | SlashCommandArgument.fromProps({ |
| 2112 | description: 'character name', | 2118 | description: 'Character name - or unique character identifier (avatar key)', |
| 2113 | typeList: [ARGUMENT_TYPE.STRING], | 2119 | typeList: [ARGUMENT_TYPE.STRING], |
| 2114 | isRequired: true, | 2120 | isRequired: true, |
| 2115 | enumProvider: commonEnumProviders.characters('character'), | 2121 | enumProvider: commonEnumProviders.characters('character'), |
| 2122 | forceEnum: true, | ||
| 2116 | }), | 2123 | }), |
| 2117 | ], | 2124 | ], |
| 2118 | helpString: 'Returns the last set sprite / expression for the named character.', | 2125 | helpString: 'Returns the last set sprite / expression for the named character.', |
| @@ -441,6 +441,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | |||
| 441 | description: 'character name', | 441 | description: 'character name', |
| 442 | typeList: [ARGUMENT_TYPE.STRING], | 442 | typeList: [ARGUMENT_TYPE.STRING], |
| 443 | enumProvider: commonEnumProviders.characters('character'), | 443 | enumProvider: commonEnumProviders.characters('character'), |
| 444 | forceEnum: true, | ||
| 444 | }), | 445 | }), |
| 445 | SlashCommandNamedArgument.fromProps({ | 446 | SlashCommandNamedArgument.fromProps({ |
| 446 | name: 'group', | 447 | name: 'group', |
| @@ -210,7 +210,7 @@ export function initDefaultSlashCommands() { | |||
| 210 | ], | 210 | ], |
| 211 | unnamedArgumentList: [ | 211 | unnamedArgumentList: [ |
| 212 | SlashCommandArgument.fromProps({ | 212 | SlashCommandArgument.fromProps({ |
| 213 | description: 'Character name', | 213 | description: 'Character name - or unique character identifier (avatar key)', |
| 214 | typeList: [ARGUMENT_TYPE.STRING], | 214 | typeList: [ARGUMENT_TYPE.STRING], |
| 215 | enumProvider: commonEnumProviders.characters('character'), | 215 | enumProvider: commonEnumProviders.characters('character'), |
| 216 | forceEnum: false, | 216 | forceEnum: false, |
| @@ -700,7 +700,7 @@ export function initDefaultSlashCommands() { | |||
| 700 | aliases: ['addmember', 'memberadd'], | 700 | aliases: ['addmember', 'memberadd'], |
| 701 | unnamedArgumentList: [ | 701 | unnamedArgumentList: [ |
| 702 | SlashCommandArgument.fromProps({ | 702 | SlashCommandArgument.fromProps({ |
| 703 | description: 'character name', | 703 | description: 'Character name - or unique character identifier (avatar key)', |
| 704 | typeList: [ARGUMENT_TYPE.STRING], | 704 | typeList: [ARGUMENT_TYPE.STRING], |
| 705 | isRequired: true, | 705 | isRequired: true, |
| 706 | enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [], | 706 | enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [], |
| @@ -2810,26 +2810,23 @@ async function removeGroupMemberCallback(_, arg) { | |||
| 2810 | return ''; | 2810 | return ''; |
| 2811 | } | 2811 | } |
| 2812 | 2812 | ||
| 2813 | async function addGroupMemberCallback(_, arg) { | 2813 | async function addGroupMemberCallback(_, name) { |
| 2814 | if (!selected_group) { | 2814 | if (!selected_group) { |
| 2815 | toastr.warning('Cannot run /memberadd command outside of a group chat.'); | 2815 | toastr.warning('Cannot run /memberadd command outside of a group chat.'); |
| 2816 | return ''; | 2816 | return ''; |
| 2817 | } | 2817 | } |
| 2818 | 2818 | ||
| 2819 | if (!arg) { | 2819 | if (!name) { |
| 2820 | console.warn('WARN: No argument provided for /memberadd command'); | 2820 | console.warn('WARN: No argument provided for /memberadd command'); |
| 2821 | return ''; | 2821 | return ''; |
| 2822 | } | 2822 | } |
| 2823 | 2823 | ||
| 2824 | arg = arg.trim(); | 2824 | const character = findChar({ name: name, preferCurrentChar: false }); |
| 2825 | const chid = findCharacterIndex(arg); | 2825 | if (!character) { |
| 2826 | 2826 | console.warn(`WARN: No character found for argument ${name}`); | |
| 2827 | if (chid === -1) { | ||
| 2828 | console.warn(`WARN: No character found for argument ${arg}`); | ||
| 2829 | return ''; | 2827 | return ''; |
| 2830 | } | 2828 | } |
| 2831 | 2829 | ||
| 2832 | const character = characters[chid]; | ||
| 2833 | const group = groups.find(x => x.id === selected_group); | 2830 | const group = groups.find(x => x.id === selected_group); |
| 2834 | 2831 | ||
| 2835 | if (!group || !Array.isArray(group.members)) { | 2832 | if (!group || !Array.isArray(group.members)) { |
| @@ -26,6 +26,7 @@ import { debounce_timeout } from './constants.js'; | |||
| 26 | import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js'; | 26 | import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js'; |
| 27 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; | 27 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 28 | import { renderTemplateAsync } from './templates.js'; | 28 | import { renderTemplateAsync } from './templates.js'; |
| 29 | import { findChar } from './slash-commands.js'; | ||
| 29 | 30 | ||
| 30 | export { | 31 | export { |
| 31 | TAG_FOLDER_TYPES, | 32 | TAG_FOLDER_TYPES, |
| @@ -507,7 +508,7 @@ export function getTagKeyForEntityElement(element) { | |||
| 507 | */ | 508 | */ |
| 508 | export function searchCharByName(charName, { suppressLogging = false } = {}) { | 509 | export function searchCharByName(charName, { suppressLogging = false } = {}) { |
| 509 | const entity = charName | 510 | const entity = charName |
| 510 | ? (characters.find(x => x.name === charName) || groups.find(x => x.name == charName)) | 511 | ? (findChar({ name: charName }) || groups.find(x => equalsIgnoreCaseAndAccents(x.name, charName))) |
| 511 | : (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]); | 512 | : (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]); |
| 512 | const key = getTagKeyForEntity(entity); | 513 | const key = getTagKeyForEntity(entity); |
| 513 | if (!key) { | 514 | if (!key) { |
| @@ -1861,8 +1862,9 @@ function registerTagsSlashCommands() { | |||
| 1861 | return String(result); | 1862 | return String(result); |
| 1862 | }, | 1863 | }, |
| 1863 | namedArgumentList: [ | 1864 | namedArgumentList: [ |
| 1864 | SlashCommandNamedArgument.fromProps({ name: 'name', | 1865 | SlashCommandNamedArgument.fromProps({ |
| 1865 | description: 'Character name', | 1866 | name: 'name', |
| 1867 | description: 'Character name - or unique character identifier (avatar key)', | ||
| 1866 | typeList: [ARGUMENT_TYPE.STRING], | 1868 | typeList: [ARGUMENT_TYPE.STRING], |
| 1867 | defaultValue: '{{char}}', | 1869 | defaultValue: '{{char}}', |
| 1868 | enumProvider: commonEnumProviders.characters(), | 1870 | enumProvider: commonEnumProviders.characters(), |
| @@ -1907,7 +1909,7 @@ function registerTagsSlashCommands() { | |||
| 1907 | }, | 1909 | }, |
| 1908 | namedArgumentList: [ | 1910 | namedArgumentList: [ |
| 1909 | SlashCommandNamedArgument.fromProps({ name: 'name', | 1911 | SlashCommandNamedArgument.fromProps({ name: 'name', |
| 1910 | description: 'Character name', | 1912 | description: 'Character name - or unique character identifier (avatar key)', |
| 1911 | typeList: [ARGUMENT_TYPE.STRING], | 1913 | typeList: [ARGUMENT_TYPE.STRING], |
| 1912 | defaultValue: '{{char}}', | 1914 | defaultValue: '{{char}}', |
| 1913 | enumProvider: commonEnumProviders.characters(), | 1915 | enumProvider: commonEnumProviders.characters(), |
| @@ -1950,7 +1952,7 @@ function registerTagsSlashCommands() { | |||
| 1950 | namedArgumentList: [ | 1952 | namedArgumentList: [ |
| 1951 | SlashCommandNamedArgument.fromProps({ | 1953 | SlashCommandNamedArgument.fromProps({ |
| 1952 | name: 'name', | 1954 | name: 'name', |
| 1953 | description: 'Character name', | 1955 | description: 'Character name - or unique character identifier (avatar key)', |
| 1954 | typeList: [ARGUMENT_TYPE.STRING], | 1956 | typeList: [ARGUMENT_TYPE.STRING], |
| 1955 | defaultValue: '{{char}}', | 1957 | defaultValue: '{{char}}', |
| 1956 | enumProvider: commonEnumProviders.characters(), | 1958 | enumProvider: commonEnumProviders.characters(), |
| @@ -1993,7 +1995,7 @@ function registerTagsSlashCommands() { | |||
| 1993 | namedArgumentList: [ | 1995 | namedArgumentList: [ |
| 1994 | SlashCommandNamedArgument.fromProps({ | 1996 | SlashCommandNamedArgument.fromProps({ |
| 1995 | name: 'name', | 1997 | name: 'name', |
| 1996 | description: 'Character name', | 1998 | description: 'Character name - or unique character identifier (avatar key)', |
| 1997 | typeList: [ARGUMENT_TYPE.STRING], | 1999 | typeList: [ARGUMENT_TYPE.STRING], |
| 1998 | defaultValue: '{{char}}', | 2000 | defaultValue: '{{char}}', |
| 1999 | enumProvider: commonEnumProviders.characters(), | 2001 | enumProvider: commonEnumProviders.characters(), |