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