Fix restoration of current character after /ask

Fixes #2825
This commit is contained in:
Cohee 2024-09-11 19:34:26 +03:00
parent 9e522b0330
commit 86d9a80ff8
1 changed files with 9 additions and 8 deletions

View File

@ -2533,22 +2533,23 @@ async function askCharacter(args, text) {
lastMessage.force_avatar = force_avatar; lastMessage.force_avatar = force_avatar;
lastMessage.original_avatar = original_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 { try {
toastr.info(`Asking ${character.name} something...`); toastr.info(`Asking ${character.name} something...`);
await Generate('ask_command'); await Generate('ask_command');
} catch { await saveChatConditional();
} catch (error) {
console.error('Error running /ask command', error);
} finally {
restoreCharacter(); 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 ''; return '';
} }