stop named args from nested commands bleeding into parent

This commit is contained in:
LenAnderson
2024-02-09 22:49:38 +00:00
parent 867c42cb6d
commit cab6f90519

View File

@ -80,14 +80,23 @@ class SlashCommandParser {
const excludedFromRegex = ['sendas']; const excludedFromRegex = ['sendas'];
const firstSpace = text.indexOf(' '); const firstSpace = text.indexOf(' ');
const command = firstSpace !== -1 ? text.substring(1, firstSpace) : text.substring(1); 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 = {}; const argObj = {};
let unnamedArg; let unnamedArg;
if (args.length > 0) { 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 // Match named arguments
const namedArgPattern = /(\w+)=("(?:\\.|[^"\\])*"|\S+)/g; const namedArgPattern = /(\w+)=("(?:\\.|[^"\\])*"|\S+)/g;
let match;
while ((match = namedArgPattern.exec(args)) !== null) { while ((match = namedArgPattern.exec(args)) !== null) {
const key = match[1]; const key = match[1];
const value = match[2]; const value = match[2];
@ -95,13 +104,6 @@ class SlashCommandParser {
argObj[key] = value.replace(/(^")|("$)/g, ''); 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 // Excluded commands format in their own function
if (!excludedFromRegex.includes(command)) { if (!excludedFromRegex.includes(command)) {
unnamedArg = getRegexedString( unnamedArg = getRegexedString(