diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 661c9c641..fe8408b06 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -154,7 +154,7 @@ parser.addCommand('sysgen', generateSystemMessage, [], ' parser.addCommand('ask', askCharacter, [], '(prompt) – asks a specified character card a prompt', true, true); parser.addCommand('delname', deleteMessagesByNameCallback, ['cancel'], '(name) – deletes all messages attributed to a specified name', true, true); parser.addCommand('send', sendUserMessageCallback, [], '(text) – adds a user message to the chat log without triggering a generation', true, true); -parser.addCommand('trigger', triggerGenerationCallback, [], ' – triggers a message generation. If in group, can trigger a message for the specified group member index or name.', true, true); +parser.addCommand('trigger', triggerGenerationCallback, [], ' await=true/false – triggers a message generation. If in group, can trigger a message for the specified group member index or name. If await=true named argument passed, the command will await for the triggered generation before continuing.', true, true); parser.addCommand('hide', hideMessageCallback, [], '(message index or range) – hides a chat message from the prompt', true, true); parser.addCommand('unhide', unhideMessageCallback, [], '(message index or range) – unhides a message from the prompt', true, true); parser.addCommand('disable', disableGroupMemberCallback, [], '(member index or name) – disables a group member from being drafted for replies', true, true); @@ -1029,8 +1029,9 @@ async function addGroupMemberCallback(_, arg) { return character.name; } -async function triggerGenerationCallback(_, arg) { - setTimeout(async () => { +async function triggerGenerationCallback(args, value) { + const shouldAwait = isTrueBoolean(args?.await); + const outerPromise = new Promise((outerResolve) => setTimeout(async () => { try { await waitUntilCondition(() => !is_send_press && !is_group_generating, 10000, 100); } catch { @@ -1044,16 +1045,21 @@ async function triggerGenerationCallback(_, arg) { let chid = undefined; - if (selected_group && arg) { - chid = findGroupMemberId(arg); + if (selected_group && value) { + chid = findGroupMemberId(value); if (chid === undefined) { - console.warn(`WARN: No group member found for argument ${arg}`); + console.warn(`WARN: No group member found for argument ${value}`); } } - setTimeout(() => Generate('normal', { force_chid: chid }), 100); - }, 1); + outerResolve(new Promise(innerResolve => setTimeout(() => innerResolve(Generate('normal', { force_chid: chid })), 100))); + }, 1)); + + if (shouldAwait) { + const innerPromise = await outerPromise; + await innerPromise; + } return ''; }