This commit is contained in:
Erik 2022-07-29 20:37:34 +03:00
parent cc03b96442
commit 9b95d4ec2b
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
4 changed files with 15 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "commandparser", "name": "commandparser",
"version": "1.0.16", "version": "1.0.17",
"description": "Parser meant to parse commands and their options for discord bots", "description": "Parser meant to parse commands and their options for discord bots",
"main": "build/index.js", "main": "build/index.js",
"author": "Navy.gif", "author": "Navy.gif",

View File

@ -8,8 +8,12 @@ import IResolver from './interfaces/Resolver';
import ExtendedMap from "./util/Map"; import ExtendedMap from "./util/Map";
import Util from "./util/Util"; import Util from "./util/Util";
type ArgsResult = {
[key: string]: CommandOption
}
type ParseResult = { type ParseResult = {
args: object, args: ArgsResult,
command: ICommand, command: ICommand,
subcommand: string | null, subcommand: string | null,
subcommandGroup: string | null subcommandGroup: string | null
@ -68,7 +72,7 @@ class Parser extends EventEmitter {
this.debug(`Matched command ${command.name}`); this.debug(`Matched command ${command.name}`);
const { subcommands, subcommandGroups } = command; const { subcommands, subcommandGroups } = command;
const args: {[key: string]: CommandOption} = {}; const args: ArgsResult = {};
const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null }; const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null };
let group = null, let group = null,
subcommand = null; subcommand = null;
@ -254,4 +258,4 @@ class Parser extends EventEmitter {
} }
export { Parser, ParseError }; export { Parser, ParseError, ArgsResult };

View File

@ -3,8 +3,9 @@ import { ICommand, CommandDefinition } from "../interfaces/Command";
import SubcommandOption from "./SubcommandOption"; import SubcommandOption from "./SubcommandOption";
import SubcommandGroupOption from "./SubcommandGroupOption"; import SubcommandGroupOption from "./SubcommandGroupOption";
import CommandOption from "./CommandOption"; import CommandOption from "./CommandOption";
import { ArgsResult } from "../Parser";
class Command implements ICommand { abstract class Command implements ICommand {
name: string; name: string;
@ -26,6 +27,8 @@ class Command implements ICommand {
} }
abstract execute(message: unknown, args: ArgsResult): Promise<unknown>;
get subcommands(): SubcommandOption[] { get subcommands(): SubcommandOption[] {
return this._subcommands(this.options); return this._subcommands(this.options);
} }

View File

@ -1,6 +1,7 @@
import CommandOption from '../classes/CommandOption'; import CommandOption from '../classes/CommandOption';
import SubcommandGroupOption from '../classes/SubcommandGroupOption'; import SubcommandGroupOption from '../classes/SubcommandGroupOption';
import SubcommandOption from '../classes/SubcommandOption'; import SubcommandOption from '../classes/SubcommandOption';
import { ArgsResult } from '../Parser';
import { CommandOptionDefinition } from './CommandOption'; import { CommandOptionDefinition } from './CommandOption';
@ -18,6 +19,8 @@ interface ICommand {
subcommandGroup(name: string): SubcommandGroupOption | null subcommandGroup(name: string): SubcommandGroupOption | null
execute(message: unknown, args: ArgsResult): Promise<unknown>
} }
type CommandDefinition = { type CommandDefinition = {