From 86d9a80ff8a3f60b13ba7c37ea678329724fcb81 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:34:26 +0300 Subject: [PATCH] Fix restoration of current character after /ask Fixes #2825 --- public/scripts/slash-commands.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 9650263f9..f54f62df3 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2533,22 +2533,23 @@ async function askCharacter(args, text) { lastMessage.force_avatar = force_avatar; lastMessage.original_avatar = original_avatar; } - - // Kill this callback once the event fires - eventSource.removeListener(event_types.CHARACTER_MESSAGE_RENDERED, restoreCharacter); }; - // Run generate and restore previous character on error + // Run generate and restore previous character try { toastr.info(`Asking ${character.name} something...`); await Generate('ask_command'); - } catch { + await saveChatConditional(); + } catch (error) { + console.error('Error running /ask command', error); + } finally { restoreCharacter(); + + if (this_chid !== prevChId) { + toastr.error('It is strongly recommended to reload the page.', 'Something went wrong'); + } } - // Restore previous character once message renders - // Hack for generate - eventSource.on(event_types.CHARACTER_MESSAGE_RENDERED, restoreCharacter); return ''; }