diff --git a/package.json b/package.json index 71ec53e..6a73baa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandparser", - "version": "1.0.16", + "version": "1.0.17", "description": "Parser meant to parse commands and their options for discord bots", "main": "build/index.js", "author": "Navy.gif", diff --git a/src/Parser.ts b/src/Parser.ts index f3bc88e..106fcec 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -8,8 +8,12 @@ import IResolver from './interfaces/Resolver'; import ExtendedMap from "./util/Map"; import Util from "./util/Util"; +type ArgsResult = { + [key: string]: CommandOption +} + type ParseResult = { - args: object, + args: ArgsResult, command: ICommand, subcommand: string | null, subcommandGroup: string | null @@ -68,7 +72,7 @@ class Parser extends EventEmitter { this.debug(`Matched command ${command.name}`); const { subcommands, subcommandGroups } = command; - const args: {[key: string]: CommandOption} = {}; + const args: ArgsResult = {}; const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null }; let group = null, subcommand = null; @@ -254,4 +258,4 @@ class Parser extends EventEmitter { } -export { Parser, ParseError }; \ No newline at end of file +export { Parser, ParseError, ArgsResult }; \ No newline at end of file diff --git a/src/classes/Command.ts b/src/classes/Command.ts index bd960e4..98b6354 100644 --- a/src/classes/Command.ts +++ b/src/classes/Command.ts @@ -3,8 +3,9 @@ import { ICommand, CommandDefinition } from "../interfaces/Command"; import SubcommandOption from "./SubcommandOption"; import SubcommandGroupOption from "./SubcommandGroupOption"; import CommandOption from "./CommandOption"; +import { ArgsResult } from "../Parser"; -class Command implements ICommand { +abstract class Command implements ICommand { name: string; @@ -26,6 +27,8 @@ class Command implements ICommand { } + abstract execute(message: unknown, args: ArgsResult): Promise; + get subcommands(): SubcommandOption[] { return this._subcommands(this.options); } diff --git a/src/interfaces/Command.ts b/src/interfaces/Command.ts index 0c0cd9a..7e8c8ae 100644 --- a/src/interfaces/Command.ts +++ b/src/interfaces/Command.ts @@ -1,6 +1,7 @@ import CommandOption from '../classes/CommandOption'; import SubcommandGroupOption from '../classes/SubcommandGroupOption'; import SubcommandOption from '../classes/SubcommandOption'; +import { ArgsResult } from '../Parser'; import { CommandOptionDefinition } from './CommandOption'; @@ -18,6 +19,8 @@ interface ICommand { subcommandGroup(name: string): SubcommandGroupOption | null + execute(message: unknown, args: ArgsResult): Promise + } type CommandDefinition = {