Add avatar= to /sendas to allow avatar override

4594353c72c378777f1ff4e1efb17df7b681b546

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +26 -8Ignore whitespace
public/scripts/slash-commands.js+26 -8
@@ -185,9 +185,18 @@ export function initDefaultSlashCommands() {
185 enumProvider: commonEnumProviders.characters('character'),185 enumProvider: commonEnumProviders.characters('character'),
186 forceEnum: false,186 forceEnum: false,
187 }),187 }),
188 new SlashCommandNamedArgument(188 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 }),
191 SlashCommandNamedArgument.fromProps({200 SlashCommandNamedArgument.fromProps({
192 name: 'at',201 name: 'at',
193 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.',202 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) {
3142 const isNeutralCharacter = !chatCharacter && name2 === neutralCharacterName && name === neutralCharacterName;3151 const isNeutralCharacter = !chatCharacter && name2 === neutralCharacterName && name === neutralCharacterName;
31433152
3144 const character = equalsIgnoreCaseAndAccents(chatCharacter.name, name) ? chatCharacter : characters.find(x => equalsIgnoreCaseAndAccents(x.name, name));3153 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) {
3148 // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars3166 // If the targeted character is the currently selected one in a solo chat, we don't need to force any avatars
3149 }3167 }
3150 else if (character && character.avatar !== 'none') {3168 else if (avatarChar && avatarChar.avatar !== 'none') {
3151 force_avatar = getThumbnailUrl('avatar', character.avatar);3169 force_avatar = getThumbnailUrl('avatar', avatarChar.avatar);
3152 original_avatar = character.avatar;3170 original_avatar = avatarChar.avatar;
3153 }3171 }
3154 else {3172 else {
3155 force_avatar = default_avatar;3173 force_avatar = default_avatar;