diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index a6b3df533..9a4175a1e 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -80,14 +80,23 @@ class SlashCommandParser { const excludedFromRegex = ['sendas']; const firstSpace = text.indexOf(' '); const command = firstSpace !== -1 ? text.substring(1, firstSpace) : text.substring(1); - const args = firstSpace !== -1 ? text.substring(firstSpace + 1) : ''; + let args = firstSpace !== -1 ? text.substring(firstSpace + 1) : ''; const argObj = {}; let unnamedArg; if (args.length > 0) { + let match; + + // Match unnamed argument + const unnamedArgPattern = /(?:\w+=(?:"(?:\\.|[^"\\])*"|\S+)\s*)*(.*)/s; + match = unnamedArgPattern.exec(args); + if (match !== null && match[1].length > 0) { + args = args.slice(0, -match[1].length); + unnamedArg = match[1].trim(); + } + // Match named arguments const namedArgPattern = /(\w+)=("(?:\\.|[^"\\])*"|\S+)/g; - let match; while ((match = namedArgPattern.exec(args)) !== null) { const key = match[1]; const value = match[2]; @@ -95,13 +104,6 @@ class SlashCommandParser { argObj[key] = value.replace(/(^")|("$)/g, ''); } - // Match unnamed argument - const unnamedArgPattern = /(?:\w+=(?:"(?:\\.|[^"\\])*"|\S+)\s*)*(.*)/s; - match = unnamedArgPattern.exec(args); - if (match !== null) { - unnamedArg = match[1].trim(); - } - // Excluded commands format in their own function if (!excludedFromRegex.includes(command)) { unnamedArg = getRegexedString(