One more /ask corruption fix

Closes #2832
This commit is contained in:
Cohee 2024-09-12 09:50:06 +00:00
parent 2379fd5970
commit 4e67cc1bc4

View File

@ -2497,16 +2497,19 @@ async function askCharacter(args, text) {
const prevChId = this_chid;
// Find the character
const chId = characters.findIndex((e) => e.name === name);
const chId = characters.findIndex((e) => e.name === name || e.avatar === name);
if (!characters[chId] || chId === -1) {
toastr.error('Character not found.');
return '';
}
// Sending a message implicitly saves the chat, so this needs to be done before changing the character
// Otherwise, a corruption will occur
await sendMessageAsUser(mesText, '');
// Override character and send a user message
setCharacterId(String(chId));
// TODO: Maybe look up by filename instead of name
const character = characters[chId];
let force_avatar, original_avatar;
@ -2521,8 +2524,6 @@ async function askCharacter(args, text) {
setCharacterName(character.name);
await sendMessageAsUser(mesText, '');
const restoreCharacter = () => {
setCharacterId(prevChId);
setCharacterName(characters[prevChId].name);