Merge pull request #1808 from LenAnderson/slash-fix-bleed
stop named args from nested commands bleeding into parent
This commit is contained in:
commit
ec826450dc
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue