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