Still fighting /ask corruptions #2832

6a3b226da2846b5ee3d98a3b5b28f8bf26200c84

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

1 files changed, +7 -3Ignore whitespace
public/scripts/slash-commands.js+7 -3
@@ -2525,6 +2525,10 @@ async function askCharacter(args, text) {
2525 setCharacterName(character.name);2525 setCharacterName(character.name);
25262526
2527 const restoreCharacter = () => {2527 const restoreCharacter = () => {
2528 if (String(this_chid) !== String(chId)) {
2529 return;
2530 }
2531
2528 setCharacterId(prevChId);2532 setCharacterId(prevChId);
2529 setCharacterName(characters[prevChId].name);2533 setCharacterName(characters[prevChId].name);
25302534
@@ -2541,14 +2545,14 @@ async function askCharacter(args, text) {
25412545
2542 // Run generate and restore previous character2546 // Run generate and restore previous character
2543 try {2547 try {
2548 eventSource.once(event_types.MESSAGE_RECEIVED, restoreCharacter);
2544 toastr.info(`Asking ${character.name} something...`);2549 toastr.info(`Asking ${character.name} something...`);
2545 askResult = await Generate('ask_command');2550 askResult = await Generate('ask_command');
2546 } catch (error) {2551 } catch (error) {
2552 restoreCharacter();
2547 console.error('Error running /ask command', error);2553 console.error('Error running /ask command', error);
2548 } finally {2554 } finally {
2549 restoreCharacter();2555 if (String(this_chid) === String(prevChId)) {
2550
2551 if (this_chid === prevChId) {
2552 await saveChatConditional();2556 await saveChatConditional();
2553 } else {2557 } else {
2554 toastr.error('It is strongly recommended to reload the page.', 'Something went wrong');2558 toastr.error('It is strongly recommended to reload the page.', 'Something went wrong');