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