Use command interface internally

This commit is contained in:
Erik 2023-08-15 17:51:08 +03:00
parent 5e4c6bd7a3
commit 94d1291ffb
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -1,12 +1,12 @@
// eslint-disable-next-line max-classes-per-file
import { EventEmitter } from 'events';
import Command from './classes/Command.js';
import CommandOption from './classes/CommandOption.js';
import { OptionType } from "./interfaces/CommandOption.js";
import IResolver from './interfaces/Resolver.js';
import ExtendedMap from "./util/Map.js";
import Util from "./util/Util.js";
import { ICommand } from '../index.js';
type ArgsResult = {
[key: string]: CommandOption
@ -14,13 +14,13 @@ type ArgsResult = {
type ParseResult = {
args: ArgsResult,
command: Command,
command: ICommand,
subcommand: string | null,
subcommandGroup: string | null
}
type ParserOptions = {
commands: Iterable<Command>,
commands: Iterable<ICommand>,
prefix?: string,
debug?: boolean,
resolver?: IResolver,
@ -29,7 +29,7 @@ type ParserOptions = {
type ParseOptions = {
prefix?: string,
commandFilter?: (cmd: Command) => boolean,
commandFilter?: (cmd: ICommand) => boolean,
guild?: unknown
}
@ -39,7 +39,7 @@ const flagReg = /(?:^| )(?<flag>(?:--[a-z0-9]{3,})|(?:-[a-z]{1,2}))(?:$| )/iu;
class Parser extends EventEmitter {
private commands: ExtendedMap<string, Command>;
private commands: ExtendedMap<string, ICommand>;
private _debug = false;
prefix: string;
resolver?: IResolver;
@ -50,7 +50,7 @@ class Parser extends EventEmitter {
super();
this._debug = debug;
this.commands = new ExtendedMap<string, Command>();
this.commands = new ExtendedMap<string, ICommand>();
for (const command of commands)
this.commands.set(command.name, command);
this.resolver = resolver;
@ -60,7 +60,7 @@ class Parser extends EventEmitter {
}
private matchCommand (name: string): Command | null {
private matchCommand (name: string): ICommand | null {
let command = null;
if (this.commands.has(name))
command = this.commands.get(name);