From 2379fd59706c52f6d652607f022995d14a7da28a Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:19:03 +0300 Subject: [PATCH] Fix /ask corruption + add return value Fixes #2832 and a skill issue --- public/scripts/slash-commands.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index f54f62df3..1ee4ab86c 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -428,6 +428,7 @@ export function initDefaultSlashCommands() { SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'ask', callback: askCharacter, + returns: 'the generated text', namedArgumentList: [ SlashCommandNamedArgument.fromProps({ name: 'name', @@ -2535,22 +2536,25 @@ async function askCharacter(args, text) { } }; + let askResult = ''; + // Run generate and restore previous character try { toastr.info(`Asking ${character.name} something...`); - await Generate('ask_command'); - await saveChatConditional(); + askResult = await Generate('ask_command'); } catch (error) { console.error('Error running /ask command', error); } finally { restoreCharacter(); - if (this_chid !== prevChId) { + if (this_chid === prevChId) { + await saveChatConditional(); + } else { toastr.error('It is strongly recommended to reload the page.', 'Something went wrong'); } } - return ''; + return askResult; } async function hideMessageCallback(_, arg) {