From 6666fff0c23e3c75156cb342c7a802b000901e99 Mon Sep 17 00:00:00 2001 From: Sean Hatfield <seanhatfield5@gmail.com> Date: Tue, 6 Aug 2024 10:27:36 -0700 Subject: [PATCH] Support multiple preset prompts in single message (#2036) support multiple preset prompts in single message --- server/utils/chats/index.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js index 2068d3511..dd0f6076f 100644 --- a/server/utils/chats/index.js +++ b/server/utils/chats/index.js @@ -14,17 +14,6 @@ async function grepCommand(message, user = null) { const userPresets = await SlashCommandPresets.getUserPresets(user?.id); const availableCommands = Object.keys(VALID_COMMANDS); - // Check if the message starts with any preset command - const foundPreset = userPresets.find((p) => message.startsWith(p.command)); - if (!!foundPreset) { - // Replace the preset command with the corresponding prompt - const updatedMessage = message.replace( - foundPreset.command, - foundPreset.prompt - ); - return updatedMessage; - } - // Check if the message starts with any built-in command for (let i = 0; i < availableCommands.length; i++) { const cmd = availableCommands[i]; @@ -34,7 +23,15 @@ async function grepCommand(message, user = null) { } } - return message; + // Replace all preset commands with their corresponding prompts + // Allows multiple commands in one message + let updatedMessage = message; + for (const preset of userPresets) { + const regex = new RegExp(preset.command, "g"); + updatedMessage = updatedMessage.replace(regex, preset.prompt); + } + + return updatedMessage; } async function chatWithWorkspace( -- GitLab