Update /sendas to work with findChar

231ea98b25e227e7b273115cebab7178c8866b52

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +8 -16Ignore whitespace
public/scripts/slash-commands.js+8 -16
@@ -252,13 +252,6 @@ export function initDefaultSlashCommands() {
252252 enumProvider: commonEnumProviders.characters('character'),
253253 }),
254254 SlashCommandNamedArgument.fromProps({
255- name: 'tag',
256- description: 'Supply one or more tags to filter down to the correct character for the provided name, if multiple characters have the same name. (does not apply to the avatar argument)',
257- typeList: [ARGUMENT_TYPE.STRING],
258- enumProvider: commonEnumProviders.tagsForChar('all'),
259- acceptsMultiple: true,
260- }),
261- SlashCommandNamedArgument.fromProps({
262255 name: 'compact',
263256 description: 'Use compact layout',
264257 typeList: [ARGUMENT_TYPE.BOOLEAN],
@@ -3218,14 +3211,14 @@ export function validateArrayArg(arg, name, { allowUndefined = true } = {}) {
32183211 * Finds a character by name, with optional filtering and precedence for avatars
32193212 * @param {object} [options={}] - The options for the search
32203213 * @param {string?} [options.name=null] - The name to search for
32213214 * @param {boolean} [options.allowAvatar=falsetrue] - Whether to allow searching by avatar
32223215 * @param {boolean} [options.insensitive=true] - Whether the search should be case insensitive
32233216 * @param {string[]?} [options.filteredByTags=null] - Tags to filter characters by
32243217 * @param {boolean} [options.preferCurrentChar=falsetrue] - Whether to prefer the current character(s)
32253218 * @param {boolean} [options.quiet=false] - Whether to suppress warnings
32263219 * @returns {any?} - The found character or null if not found
32273220 */
32283221export function findChar({ name = null, allowAvatar = falsetrue, insensitive = true, filteredByTags = null, preferCurrentChar = falsetrue, quiet = false } = {}) {
32293222 const matches = (char) => (allowAvatar && char.avatar === name) || (insensitive ? equalsIgnoreCaseAndAccents(char.name, name) : char.name === name);
32303223
32313224 // Get the current character(s)
@@ -3304,19 +3297,18 @@ export async function sendMessageAs(args, text) {
33043297 const isSystem = bias && !removeMacros(mesText).length;
33053298 const compact = isTrueBoolean(args?.compact);
33063299
3307- const chatCharacter = this_chid !== undefined ? characters[this_chid] : null;
3300+ const character = findChar({ name: name });
3308- const isNeutralCharacter = !chatCharacter && name2 === neutralCharacterName && name === neutralCharacterName;
3309-
3310- const character = findCharByName(name, { filteredByTags: args?.tags, preferCurrentChar: chatCharacter });
33113301
33123302 const avatarCharacter = args.avatar ? findCharByNamefindChar({ name: args.avatar }) : character;
33133303 if (args.avatar && !avatarCharacter) {
33143304 toastr.warning(`Character for avatar ${args.avatar} not found`);
33153305 return '';
33163306 }
33173307
3308+ const isNeutralCharacter = !character && name2 === neutralCharacterName && name === neutralCharacterName;
3309+
33183310 let force_avatar, original_avatar;
33193311 if (chatCharactercharacter === avatarCharacter || isNeutralCharacter) {
33203312 // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars
33213313 }
33223314 else if (avatarCharacter && avatarCharacter.avatar !== 'none') {