From 061b7c6922c9530101566888c14c021c5b3fc5d8 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 20 Feb 2024 02:09:01 +0200 Subject: [PATCH] Don't try to execute script commands if the message doesn't start with slash --- public/script.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/public/script.js b/public/script.js index b9df03842..3087922b8 100644 --- a/public/script.js +++ b/public/script.js @@ -2270,12 +2270,21 @@ export async function generateQuietPrompt(quiet_prompt, quietToLoud, skipWIAN, q return generateFinished; } +/** + * Executes slash commands and returns the new text and whether the generation was interrupted. + * @param {string} message Text to be sent + * @returns {Promise} Whether the message sending was interrupted + */ async function processCommands(message) { + if (!message || !message.trim().startsWith('/')) { + return false; + } + const previousText = String($('#send_textarea').val()); const result = await executeSlashCommands(message); if (!result || typeof result !== 'object') { - return null; + return false; } const currentText = String($('#send_textarea').val()); @@ -2878,7 +2887,7 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu let message_already_generated = isImpersonate ? `${name1}: ` : `${name2}: `; if (!(dryRun || type == 'regenerate' || type == 'swipe' || type == 'quiet')) { - const interruptedByCommand = await processCommands($('#send_textarea').val()); + const interruptedByCommand = await processCommands(String($('#send_textarea').val())); if (interruptedByCommand) { //$("#send_textarea").val('').trigger('input');