use nBot command argument parser for now

This commit is contained in:
Evert Prants 2021-10-19 19:58:21 +03:00
parent 49b0660f95
commit 1c98747c62
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 66 additions and 3 deletions

View File

@ -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": []
}

View File

@ -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,

View File

@ -15,7 +15,7 @@
},
{
"name": "simplecommands",
"version": "1.1.3"
"version": "1.1.4"
},
{
"name": "xprotocol",