Fix /ask corruption + add return value

Fixes #2832 and a skill issue
This commit is contained in:
Cohee 2024-09-12 10:19:03 +03:00
parent a88b4232a0
commit 2379fd5970
1 changed files with 8 additions and 4 deletions

View File

@ -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) {