Update /sendas to work with findChar
| @@ -252,13 +252,6 @@ export function initDefaultSlashCommands() { | ||
| 252 | 252 | enumProvider: commonEnumProviders.characters('character'), |
| 253 | 253 | }), |
| 254 | 254 | 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({ | |
| 262 | 255 | name: 'compact', |
| 263 | 256 | description: 'Use compact layout', |
| 264 | 257 | typeList: [ARGUMENT_TYPE.BOOLEAN], |
| @@ -3218,14 +3211,14 @@ export function validateArrayArg(arg, name, { allowUndefined = true } = {}) { | ||
| 3218 | 3211 | * Finds a character by name, with optional filtering and precedence for avatars |
| 3219 | 3212 | * @param {object} [options={}] - The options for the search |
| 3220 | 3213 | * @param {string?} [options.name=null] - The name to search for |
| 3221 | 3214 | * @param {boolean} [options.allowAvatar=falsetrue] - Whether to allow searching by avatar |
| 3222 | 3215 | * @param {boolean} [options.insensitive=true] - Whether the search should be case insensitive |
| 3223 | 3216 | * @param {string[]?} [options.filteredByTags=null] - Tags to filter characters by |
| 3224 | 3217 | * @param {boolean} [options.preferCurrentChar=falsetrue] - Whether to prefer the current character(s) |
| 3225 | 3218 | * @param {boolean} [options.quiet=false] - Whether to suppress warnings |
| 3226 | 3219 | * @returns {any?} - The found character or null if not found |
| 3227 | 3220 | */ |
| 3228 | 3221 | export function findChar({ name = null, allowAvatar = falsetrue, insensitive = true, filteredByTags = null, preferCurrentChar = falsetrue, quiet = false } = {}) { |
| 3229 | 3222 | const matches = (char) => (allowAvatar && char.avatar === name) || (insensitive ? equalsIgnoreCaseAndAccents(char.name, name) : char.name === name); |
| 3230 | 3223 | |
| 3231 | 3224 | // Get the current character(s) |
| @@ -3304,19 +3297,18 @@ export async function sendMessageAs(args, text) { | ||
| 3304 | 3297 | const isSystem = bias && !removeMacros(mesText).length; |
| 3305 | 3298 | const compact = isTrueBoolean(args?.compact); |
| 3306 | 3299 | |
| 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 }); | |
| 3311 | 3301 | |
| 3312 | 3302 | const avatarCharacter = args.avatar ? findCharByNamefindChar({ name: args.avatar }) : character; |
| 3313 | 3303 | if (args.avatar && !avatarCharacter) { |
| 3314 | 3304 | toastr.warning(`Character for avatar ${args.avatar} not found`); |
| 3315 | 3305 | return ''; |
| 3316 | 3306 | } |
| 3317 | 3307 | |
| 3308 | + const isNeutralCharacter = !character && name2 === neutralCharacterName && name === neutralCharacterName; | |
| 3309 | + | |
| 3318 | 3310 | let force_avatar, original_avatar; |
| 3319 | 3311 | if (chatCharactercharacter === avatarCharacter || isNeutralCharacter) { |
| 3320 | 3312 | // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars |
| 3321 | 3313 | } |
| 3322 | 3314 | else if (avatarCharacter && avatarCharacter.avatar !== 'none') { |