Add avatar= to /sendas to allow avatar override

4594353c72c378777f1ff4e1efb17df7b681b546

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +26 -8Showing whitespace changes
public/scripts/slash-commands.js+26 -8
@@ -185,9 +185,18 @@ export function initDefaultSlashCommands() {
185185 enumProvider: commonEnumProviders.characters('character'),
186186 forceEnum: false,
187187 }),
188188 new SlashCommandNamedArgument.fromProps({
189- 'compact', 'Use compact layout', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
189+ name: 'avatar',
190- ),
190+ description: 'Optional character avatar override (Can be either avatar filename or just the character name to pull the avatar from)',
191+ typeList: [ARGUMENT_TYPE.STRING],
192+ enumProvider: commonEnumProviders.characters('character'),
193+ }),
194+ SlashCommandNamedArgument.fromProps({
195+ name: 'compact',
196+ description: 'Use compact layout',
197+ typeList: [ARGUMENT_TYPE.BOOLEAN],
198+ defaultValue: 'false',
199+ }),
191200 SlashCommandNamedArgument.fromProps({
192201 name: 'at',
193202 description: 'position to insert the message (index-based, corresponding to message id). If not set, the message will be inserted at the end of the chat.\nNegative values are accepted and will work similarly to how \'depth\' usually works. For example, -1 will insert the message right before the last message in chat.',
@@ -3142,14 +3151,23 @@ export async function sendMessageAs(args, text) {
31423151 const isNeutralCharacter = !chatCharacter && name2 === neutralCharacterName && name === neutralCharacterName;
31433152
31443153 const character = equalsIgnoreCaseAndAccents(chatCharacter.name, name) ? chatCharacter : characters.find(x => equalsIgnoreCaseAndAccents(x.name, name));
3145- let force_avatar, original_avatar;
31463154
3147- if (chatCharacter === character || isNeutralCharacter) {
3155+ let avatarChar = character;
3156+ if (args.avatar) {
3157+ avatarChar = characters.find(x => x.avatar == args.avatar) ?? characters.find(x => equalsIgnoreCaseAndAccents(x.name, args.avatar));
3158+ if (!avatarChar) {
3159+ toastr.warning(`Character for avatar ${args.avatar} not found`);
3160+ return '';
3161+ }
3162+ }
3163+
3164+ let force_avatar, original_avatar;
3165+ if (chatCharacter === avatarChar || isNeutralCharacter) {
31483166 // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars
31493167 }
31503168 else if (characteravatarChar && characteravatarChar.avatar !== 'none') {
31513169 force_avatar = getThumbnailUrl('avatar', characteravatarChar.avatar);
31523170 original_avatar = characteravatarChar.avatar;
31533171 }
31543172 else {
31553173 force_avatar = default_avatar;