From 74fbc88d7d73c1afce92b794628e8633a5244b80 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 24 Nov 2023 01:56:43 +0200 Subject: [PATCH] Move macros replacement to script execution time --- public/scripts/extensions/quick-reply/index.js | 18 ++++++++++++------ public/scripts/slash-commands.js | 12 ++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/public/scripts/extensions/quick-reply/index.js b/public/scripts/extensions/quick-reply/index.js index 7bc092f34..5cb219660 100644 --- a/public/scripts/extensions/quick-reply/index.js +++ b/public/scripts/extensions/quick-reply/index.js @@ -229,14 +229,14 @@ async function performQuickReply(prompt, index) { newText = `${prompt} `; } - newText = substituteParams(newText); - // the prompt starts with '/' - execute slash commands natively if (prompt.startsWith('/')) { await executeSlashCommands(newText); return; } + newText = substituteParams(newText); + $("#send_textarea").val(newText); // Set the focus back to the textarea @@ -560,20 +560,26 @@ function saveQROrder() { }); } -async function onMessageReceived() { +async function onMessageReceived(index) { for (let i = 0; i < extension_settings.quickReply.numberOfSlots; i++) { const qr = extension_settings.quickReply.quickReplySlots[i]; if (qr?.autoExecute_botMessage) { - await sendQuickReply(i); + const message = getContext().chat[index]; + if (message?.mes && message?.mes !== '...') { + await sendQuickReply(i); + } } } } -async function onMessageSent() { +async function onMessageSent(index) { for (let i = 0; i < extension_settings.quickReply.numberOfSlots; i++) { const qr = extension_settings.quickReply.quickReplySlots[i]; if (qr?.autoExecute_userMessage) { - await sendQuickReply(i); + const message = getContext().chat[index]; + if (message?.mes && message?.mes !== '...') { + await sendQuickReply(i); + } } } } diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index f11ce59ef..b7744123c 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -86,7 +86,7 @@ class SlashCommandParser { const key = match[1]; const value = match[2]; // Remove the quotes around the value, if any - argObj[key] = substituteParams(value.replace(/(^")|("$)/g, '')); + argObj[key] = value.replace(/(^")|("$)/g, ''); } // Match unnamed argument @@ -1048,10 +1048,14 @@ async function executeSlashCommands(text, unescape = false) { console.debug('Slash command executing:', result); let unnamedArg = result.value || pipeResult; - if (pipeResult && typeof result.args === 'object') { + if (typeof result.args === 'object') { for (const [key, value] of Object.entries(result.args)) { - if (typeof value === 'string' && /{{pipe}}/i.test(value)) { - result.args[key] = value.replace(/{{pipe}}/i, pipeResult); + if (typeof value === 'string') { + if (pipeResult && /{{pipe}}/i.test(value)) { + result.args[key] = value.replace(/{{pipe}}/i, pipeResult); + } + + result.args[key] = substituteParams(value.trim()); } } }