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) {
24972497 const prevChId = this_chid;
24982498
24992499 // Find the character
25002500 const chId = characters.findIndex((e) => e.name === name || e.avatar === name);
25012501 if (!characters[chId] || chId === -1) {
25022502 toastr.error('Character not found.');
25032503 return '';
25042504 }
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+
25062510 // Override character and send a user message
25072511 setCharacterId(String(chId));
25082512
2509- // TODO: Maybe look up by filename instead of name
25102513 const character = characters[chId];
25112514 let force_avatar, original_avatar;
25122515
@@ -2521,8 +2524,6 @@ async function askCharacter(args, text) {
25212524
25222525 setCharacterName(character.name);
25232526
2524- await sendMessageAsUser(mesText, '');
2525-
25262527 const restoreCharacter = () => {
25272528 setCharacterId(prevChId);
25282529 setCharacterName(characters[prevChId].name);