diff --git a/simplecommands/plugin.json b/simplecommands/plugin.json index a928308..559aea3 100644 --- a/simplecommands/plugin.json +++ b/simplecommands/plugin.json @@ -3,7 +3,7 @@ "name": "simplecommands", "description": "Official Simplistic Commands API for Squeebot 3", "tags": ["handler", "commands", "api"], - "version": "1.1.3", + "version": "1.1.4", "dependencies": ["control?", "permissions?"], "npmDependencies": [] } diff --git a/simplecommands/plugin.ts b/simplecommands/plugin.ts index 9c1df8a..7279b7b 100644 --- a/simplecommands/plugin.ts +++ b/simplecommands/plugin.ts @@ -223,7 +223,7 @@ class SqueebotCommandsAPIPlugin extends Plugin { // Start executing for (const spec of permitted) { - const argv: any[] = separate.slice(1); + const argv: any[] = this.splitArguments(text).slice(1); if (spec.plugin === this.name) { argv.unshift(plugins); } @@ -469,6 +469,69 @@ class SqueebotCommandsAPIPlugin extends Plugin { ); } + private splitArguments(str: string): string[] { + const strArray = str.split(''); + const strARGS: string[] = []; + let strARGC = 0; + let strChar = ''; + let isString = false; + let escape = false; + let escaped = false; + + function addToArgs(append: string): void { + if (!strARGS[strARGC]) { + strARGS[strARGC] = ''; + } + strARGS[strARGC] += append; + } + + for (strChar in strArray) { + if (escaped) { + escaped = false; + } + if (escape) { + escape = false; + escaped = true; + } + switch (strArray[strChar]) { + case '\\': + if (!escaped) { + escape = true; + } else { + addToArgs('\\'); + } + break; + case '"': + if (!escaped) { + if (!isString) { + isString = true; + } else { + isString = false; + } + } else { + addToArgs('"'); + } + break; + case ' ': + if (!isString) { + strARGC++; + } else if (isString) { + if (escaped) { + addToArgs('\\'); + } + addToArgs(' '); + } + break; + default: + if (escaped) { + addToArgs('\\'); + } + addToArgs(strArray[strChar]); + } + } + return strARGS; + } + initialize(): void { this.registerCommand({ plugin: this.name, diff --git a/squeebot.repo.json b/squeebot.repo.json index e1d1333..443944f 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -15,7 +15,7 @@ }, { "name": "simplecommands", - "version": "1.1.3" + "version": "1.1.4" }, { "name": "xprotocol",