added list method and separated complicated types

This commit is contained in:
mmacierzanka committed 2021-09-08 19:33:08 +02:00
1 parent 07de442c01
commit fd2b6537de
2 files changed
+22 -11

No files matched your search

+12 -10
View File
@@ -1,9 +1,8 @@
import { Interaction, Message } from "discord.js";
import { BaseCommand } from "./BaseCommand.js";
import { ChatCommand } from "./ChatCommand.js";
import { MessageCommand } from "./MessageCommand.js";
import { CommandType } from "./types/BaseCommand.js";
import { CommandInteractionData } from "./types/commands.js";
import { Command, CommandInteractionData, CommandList } from "./types/commands.js";
export class CommandManager {
private readonly _commands: BaseCommand[] = [];
@@ -17,17 +16,20 @@ export class CommandManager {
public add(command: BaseCommand): void {}
public get<T extends CommandType>(
q: string,
t?: T
): (T extends "CHAT" ? ChatCommand : T extends "MESSAGE" ? MessageCommand : T extends "USER" ? MessageCommand : BaseCommand) | null {
public get<T extends CommandType>(q: string, t?: T): Command<T> | null {
return null;
}
public list<T extends CommandType>(
filter?: T
): T extends "CHAT" ? ChatCommand[] : T extends "MESSAGE" ? MessageCommand[] : T extends "USER" ? MessageCommand[] : BaseCommand[] {
return [];
public list<T extends CommandType>(filter?: T): CommandList<T> {
switch (filter) {
case "CHAT":
return Object.freeze([...this._commands.filter((c) => c.type === "CHAT")]) as CommandList<T>;
case "USER":
case "MESSAGE":
return Object.freeze([...this._commands.filter((c) => c.type === "MESSAGE" || c.type === "USER")]) as CommandList<T>;
default:
return Object.freeze([...this._commands]) as CommandList<T>;
}
}
public fetch<T extends Interaction | Message>(i: T): CommandInteractionData<T extends Interaction ? BaseCommand : ChatCommand> | null {
+10 -1
View File
@@ -3,8 +3,17 @@ import { ChatCommand } from "../ChatCommand.js";
import { MessageCommand } from "../MessageCommand.js";
import { UserCommand } from "../UserCommand.js";
import { InputParameter } from "../../structures/Parameter.js";
import { CommandType } from "./BaseCommand.js";
export type CommandStructure<T> = T extends "MESSAGE" ? MessageCommand : T extends "USER" ? UserCommand : T extends "CHAT" ? ChatCommand : BaseCommand;
export type Command<T extends CommandType | "BASE"> = T extends "CHAT" ? ChatCommand : T extends "MESSAGE" ? MessageCommand : T extends "USER" ? MessageCommand : BaseCommand;
export type CommandList<T extends CommandType | "BASE"> = T extends "CHAT"
? readonly ChatCommand[]
: T extends "MESSAGE"
? readonly MessageCommand[]
: T extends "USER"
? readonly MessageCommand[]
: readonly BaseCommand[];
export type CommandResolvable = BaseCommand | ChatCommand | MessageCommand | UserCommand;