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

edcf52e3a8ece77bb845b85d20465b3a8dccfb0f

Wolfsblvt <wolfsblvt@gmail.com>

4 files changed, +25 -18Ignore whitespace
public/scripts/extensions/expressions/index.js+9 -2
@@ -12,6 +12,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
1212import { isFunctionCallingSupported } from '../../openai.js';
1313import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
1414import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
15+import { findChar } from '../../slash-commands.js';
1516export { MODULE_NAME };
1617
1718const MODULE_NAME = 'expressions';
@@ -2105,14 +2106,20 @@ function migrateSettings() {
21052106 }));
21062107 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
21072108 name: 'lastsprite',
21082109 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+ },
21092115 returns: 'the last set sprite / expression for the named character.',
21102116 unnamedArgumentList: [
21112117 SlashCommandArgument.fromProps({
21122118 description: 'characterCharacter name - or unique character identifier (avatar key)',
21132119 typeList: [ARGUMENT_TYPE.STRING],
21142120 isRequired: true,
21152121 enumProvider: commonEnumProviders.characters('character'),
2122+ forceEnum: true,
21162123 }),
21172124 ],
21182125 helpString: 'Returns the last set sprite / expression for the named character.',
public/scripts/extensions/gallery/index.js+1 -0
@@ -441,6 +441,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
441441 description: 'character name',
442442 typeList: [ARGUMENT_TYPE.STRING],
443443 enumProvider: commonEnumProviders.characters('character'),
444+ forceEnum: true,
444445 }),
445446 SlashCommandNamedArgument.fromProps({
446447 name: 'group',
public/scripts/slash-commands.js+7 -10
@@ -210,7 +210,7 @@ export function initDefaultSlashCommands() {
210210 ],
211211 unnamedArgumentList: [
212212 SlashCommandArgument.fromProps({
213213 description: 'Character name - or unique character identifier (avatar key)',
214214 typeList: [ARGUMENT_TYPE.STRING],
215215 enumProvider: commonEnumProviders.characters('character'),
216216 forceEnum: false,
@@ -700,7 +700,7 @@ export function initDefaultSlashCommands() {
700700 aliases: ['addmember', 'memberadd'],
701701 unnamedArgumentList: [
702702 SlashCommandArgument.fromProps({
703703 description: 'characterCharacter name - or unique character identifier (avatar key)',
704704 typeList: [ARGUMENT_TYPE.STRING],
705705 isRequired: true,
706706 enumProvider: () => selected_group ? commonEnumProviders.characters('character')() : [],
@@ -2810,26 +2810,23 @@ async function removeGroupMemberCallback(_, arg) {
28102810 return '';
28112811}
28122812
28132813async function addGroupMemberCallback(_, argname) {
28142814 if (!selected_group) {
28152815 toastr.warning('Cannot run /memberadd command outside of a group chat.');
28162816 return '';
28172817 }
28182818
28192819 if (!argname) {
28202820 console.warn('WARN: No argument provided for /memberadd command');
28212821 return '';
28222822 }
28232823
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}`);
28292827 return '';
28302828 }
28312829
2832- const character = characters[chid];
28332830 const group = groups.find(x => x.id === selected_group);
28342831
28352832 if (!group || !Array.isArray(group.members)) {
public/scripts/tags.js+8 -6
@@ -26,6 +26,7 @@ import { debounce_timeout } from './constants.js';
2626import { INTERACTABLE_CONTROL_CLASS } from './keyboard.js';
2727import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
2828import { renderTemplateAsync } from './templates.js';
29+import { findChar } from './slash-commands.js';
2930
3031export {
3132 TAG_FOLDER_TYPES,
@@ -507,7 +508,7 @@ export function getTagKeyForEntityElement(element) {
507508 */
508509export function searchCharByName(charName, { suppressLogging = false } = {}) {
509510 const entity = charName
510511 ? (characters.findfindChar(x =>{ x.name ===: charName }) || groups.find(x => equalsIgnoreCaseAndAccents(x.name ==, charName)))
511512 : (selected_group ? groups.find(x => x.id == selected_group) : characters[this_chid]);
512513 const key = getTagKeyForEntity(entity);
513514 if (!key) {
@@ -1861,8 +1862,9 @@ function registerTagsSlashCommands() {
18611862 return String(result);
18621863 },
18631864 namedArgumentList: [
18641865 SlashCommandNamedArgument.fromProps({ name: 'name',
18651866 descriptionname: 'Character name',
1867+ description: 'Character name - or unique character identifier (avatar key)',
18661868 typeList: [ARGUMENT_TYPE.STRING],
18671869 defaultValue: '{{char}}',
18681870 enumProvider: commonEnumProviders.characters(),
@@ -1907,7 +1909,7 @@ function registerTagsSlashCommands() {
19071909 },
19081910 namedArgumentList: [
19091911 SlashCommandNamedArgument.fromProps({ name: 'name',
19101912 description: 'Character name - or unique character identifier (avatar key)',
19111913 typeList: [ARGUMENT_TYPE.STRING],
19121914 defaultValue: '{{char}}',
19131915 enumProvider: commonEnumProviders.characters(),
@@ -1950,7 +1952,7 @@ function registerTagsSlashCommands() {
19501952 namedArgumentList: [
19511953 SlashCommandNamedArgument.fromProps({
19521954 name: 'name',
19531955 description: 'Character name - or unique character identifier (avatar key)',
19541956 typeList: [ARGUMENT_TYPE.STRING],
19551957 defaultValue: '{{char}}',
19561958 enumProvider: commonEnumProviders.characters(),
@@ -1993,7 +1995,7 @@ function registerTagsSlashCommands() {
19931995 namedArgumentList: [
19941996 SlashCommandNamedArgument.fromProps({
19951997 name: 'name',
19961998 description: 'Character name - or unique character identifier (avatar key)',
19971999 typeList: [ARGUMENT_TYPE.STRING],
19982000 defaultValue: '{{char}}',
19992001 enumProvider: commonEnumProviders.characters(),