misc
This commit is contained in:
parent
6686aa1fc1
commit
3e43b568c1
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "commandparser",
|
||||
"version": "1.0.19",
|
||||
"version": "1.0.20",
|
||||
"description": "Parser meant to parse commands and their options for discord bots",
|
||||
"main": "build/index.js",
|
||||
"author": "Navy.gif",
|
||||
|
@ -1,8 +1,8 @@
|
||||
// eslint-disable-next-line max-classes-per-file
|
||||
import { EventEmitter } from 'events';
|
||||
import Command from './classes/Command';
|
||||
import CommandOption from './classes/CommandOption';
|
||||
|
||||
import ICommand from "./interfaces/Command";
|
||||
import { OptionType } from "./interfaces/CommandOption";
|
||||
import IResolver from './interfaces/Resolver';
|
||||
import ExtendedMap from "./util/Map";
|
||||
@ -14,13 +14,13 @@ type ArgsResult = {
|
||||
|
||||
type ParseResult = {
|
||||
args: ArgsResult,
|
||||
command: ICommand,
|
||||
command: Command,
|
||||
subcommand: string | null,
|
||||
subcommandGroup: string | null
|
||||
}
|
||||
|
||||
type ParserOptions = {
|
||||
commands: Iterable<ICommand>,
|
||||
commands: Iterable<Command>,
|
||||
prefix?: string,
|
||||
debug?: boolean,
|
||||
resolver: IResolver<unknown, unknown, unknown, unknown, unknown>
|
||||
@ -32,7 +32,7 @@ const flagReg = /(?:^| )(?<flag>(?:--[a-z0-9]{3,})|(?:-[a-z]{1,2}))(?:$| )/iu;
|
||||
|
||||
class Parser extends EventEmitter {
|
||||
|
||||
private commands: ExtendedMap<string, ICommand>;
|
||||
private commands: ExtendedMap<string, Command>;
|
||||
|
||||
private _debug = false;
|
||||
|
||||
@ -45,7 +45,7 @@ class Parser extends EventEmitter {
|
||||
super();
|
||||
|
||||
this._debug = debug;
|
||||
this.commands = new ExtendedMap<string, ICommand>();
|
||||
this.commands = new ExtendedMap<string, Command>();
|
||||
for (const command of commands) this.commands.set(command.name, command);
|
||||
this.resolver = resolver;
|
||||
|
||||
@ -53,7 +53,7 @@ class Parser extends EventEmitter {
|
||||
|
||||
}
|
||||
|
||||
private matchCommand(name: string): ICommand | null {
|
||||
private matchCommand(name: string): Command | null {
|
||||
let command = null;
|
||||
if (this.commands.has(name)) command = this.commands.get(name);
|
||||
else command = this.commands.find((c) => c.aliases.includes(name));
|
||||
@ -73,7 +73,7 @@ class Parser extends EventEmitter {
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
async parseMessage(message: string, prefix = this.prefix,
|
||||
guild?: unknown, commandFilter?: (command: ICommand) => boolean): Promise<ParseResult | null> {
|
||||
guild?: unknown, commandFilter?: (command: Command) => boolean): Promise<ParseResult | null> {
|
||||
|
||||
if (!message.startsWith(prefix) || !message.length) return null;
|
||||
let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length);
|
||||
|
@ -44,7 +44,7 @@ class CommandOption implements ICommandOption {
|
||||
|
||||
private resolver?: IResolver<unknown, unknown, unknown, unknown, unknown>|undefined = undefined;
|
||||
|
||||
constructor(def: CommandOptionDefinition|ICommandOption) {
|
||||
constructor(def: CommandOptionDefinition|CommandOption|ICommandOption) {
|
||||
|
||||
this.name = def.name;
|
||||
this.aliases = def.aliases || [];
|
||||
|
Loading…
Reference in New Issue
Block a user