One more /ask corruption fix Closes #2832

4e67cc1bc4ffda684adbdfab92ae0172ae4e4f36

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -4Showing whitespace changes
public/scripts/slash-commands.js+5 -4
@@ -2497,16 +2497,19 @@ async function askCharacter(args, text) {
2497 const prevChId = this_chid;2497 const prevChId = this_chid;
24982498
2499 // Find the character2499 // Find the character
2500 const chId = characters.findIndex((e) => e.name === name);2500 const chId = characters.findIndex((e) => e.name === name || e.avatar === name);
2501 if (!characters[chId] || chId === -1) {2501 if (!characters[chId] || chId === -1) {
2502 toastr.error('Character not found.');2502 toastr.error('Character not found.');
2503 return '';2503 return '';
2504 }2504 }
25052505
2506 // Sending a message implicitly saves the chat, so this needs to be done before changing the character
2507 // Otherwise, a corruption will occur
2508 await sendMessageAsUser(mesText, '');
2509
2506 // Override character and send a user message2510 // Override character and send a user message
2507 setCharacterId(String(chId));2511 setCharacterId(String(chId));
25082512
2509 // TODO: Maybe look up by filename instead of name
2510 const character = characters[chId];2513 const character = characters[chId];
2511 let force_avatar, original_avatar;2514 let force_avatar, original_avatar;
25122515
@@ -2521,8 +2524,6 @@ async function askCharacter(args, text) {
25212524
2522 setCharacterName(character.name);2525 setCharacterName(character.name);
25232526
2524 await sendMessageAsUser(mesText, '');
2525
2526 const restoreCharacter = () => {2527 const restoreCharacter = () => {
2527 setCharacterId(prevChId);2528 setCharacterId(prevChId);
2528 setCharacterName(characters[prevChId].name);2529 setCharacterName(characters[prevChId].name);