From fc390ffc300334c396d9d06b0feaf8fbc6ed2814 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sun, 26 Dec 2021 17:16:32 -0500 Subject: documentation, bug fixes etc --- src/lib/common/util/Arg.ts | 56 ++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 29 deletions(-) (limited to 'src/lib/common/util') diff --git a/src/lib/common/util/Arg.ts b/src/lib/common/util/Arg.ts index 9ce8b54..2577db9 100644 --- a/src/lib/common/util/Arg.ts +++ b/src/lib/common/util/Arg.ts @@ -1,7 +1,10 @@ import { BaseBushArgumentType, BushArgumentTypeCaster, BushSlashMessage, type BushArgumentType } from '#lib'; -import { Argument, type ArgumentTypeCaster, type Flag, type ParsedValuePredicate } from 'discord-akairo'; +import { Argument, type Flag, type ParsedValuePredicate } from 'discord-akairo'; import { type Message } from 'discord.js'; +/** + * A wrapper for the {@link Argument} class that adds custom typings. + */ export class Arg { /** * Casts a phrase to this argument's type. @@ -11,14 +14,9 @@ export class Arg { */ public static async cast(type: T, message: Message | BushSlashMessage, phrase: string): Promise>; public static async cast(type: T, message: Message | BushSlashMessage, phrase: string): Promise; - public static async cast(type: T, message: Message | BushSlashMessage, phrase: string): Promise; + public static async cast(type: AT | ATC, message: Message | BushSlashMessage, phrase: string): Promise; public static async cast(type: ATC | AT, message: Message | BushSlashMessage, phrase: string): Promise { - return Argument.cast( - type as ArgumentTypeCaster | keyof BushArgumentType, - client.commandHandler.resolver, - message as Message, - phrase - ); + return Argument.cast(type as any, client.commandHandler.resolver, message as Message, phrase); } /** @@ -28,7 +26,7 @@ export class Arg { */ public static compose(...types: T[]): ATCATCR; public static compose(...types: T[]): ATCBAT; - public static compose(...types: T[]): ATC; + public static compose(...types: (AT | ATC)[]): ATC; public static compose(...types: (AT | ATC)[]): ATC { return Argument.compose(...(types as any)); } @@ -40,7 +38,7 @@ export class Arg { */ public static composeWithFailure(...types: T[]): ATCATCR; public static composeWithFailure(...types: T[]): ATCBAT; - public static composeWithFailure(...types: T[]): ATC; + public static composeWithFailure(...types: (AT | ATC)[]): ATC; public static composeWithFailure(...types: (AT | ATC)[]): ATC { return Argument.composeWithFailure(...(types as any)); } @@ -60,7 +58,7 @@ export class Arg { */ public static product(...types: T[]): ATCATCR; public static product(...types: T[]): ATCBAT; - public static product(...types: T[]): ATC; + public static product(...types: (AT | ATC)[]): ATC; public static product(...types: (AT | ATC)[]): ATC { return Argument.product(...(types as any)); } @@ -74,7 +72,7 @@ export class Arg { */ public static range(type: T, min: number, max: number, inclusive?: boolean): ATCATCR; public static range(type: T, min: number, max: number, inclusive?: boolean): ATCBAT; - public static range(type: T, min: number, max: number, inclusive?: boolean): ATC; + public static range(type: AT | ATC, min: number, max: number, inclusive?: boolean): ATC; public static range(type: AT | ATC, min: number, max: number, inclusive?: boolean): ATC { return Argument.range(type as any, min, max, inclusive); } @@ -87,7 +85,7 @@ export class Arg { */ public static tagged(type: T, tag?: any): ATCATCR; public static tagged(type: T, tag?: any): ATCBAT; - public static tagged(type: T, tag?: any): ATC; + public static tagged(type: AT | ATC, tag?: any): ATC; public static tagged(type: AT | ATC, tag?: any): ATC { return Argument.tagged(type as any, tag); } @@ -100,7 +98,7 @@ export class Arg { */ public static taggedUnion(...types: T[]): ATCATCR; public static taggedUnion(...types: T[]): ATCBAT; - public static taggedUnion(...types: T[]): ATC; + public static taggedUnion(...types: (AT | ATC)[]): ATC; public static taggedUnion(...types: (AT | ATC)[]): ATC { return Argument.taggedUnion(...(types as any)); } @@ -113,7 +111,7 @@ export class Arg { */ public static taggedWithInput(type: T, tag?: any): ATCATCR; public static taggedWithInput(type: T, tag?: any): ATCBAT; - public static taggedWithInput(type: T, tag?: any): ATC; + public static taggedWithInput(type: AT | ATC, tag?: any): ATC; public static taggedWithInput(type: AT | ATC, tag?: any): ATC { return Argument.taggedWithInput(type as any, tag); } @@ -125,7 +123,7 @@ export class Arg { */ public static union(...types: T[]): ATCATCR; public static union(...types: T[]): ATCBAT; - public static union(...types: T[]): ATC; + public static union(...types: (AT | ATC)[]): ATC; public static union(...types: (AT | ATC)[]): ATC { return Argument.union(...(types as any)); } @@ -138,7 +136,7 @@ export class Arg { */ public static validate(type: T, predicate: ParsedValuePredicate): ATCATCR; public static validate(type: T, predicate: ParsedValuePredicate): ATCBAT; - public static validate(type: T, predicate: ParsedValuePredicate): ATC; + public static validate(type: AT | ATC, predicate: ParsedValuePredicate): ATC; public static validate(type: AT | ATC, predicate: ParsedValuePredicate): ATC { return Argument.validate(type as any, predicate); } @@ -150,39 +148,39 @@ export class Arg { */ public static withInput(type: T): ATC>; public static withInput(type: T): ATCBAT; - public static withInput(type: T): ATC; + public static withInput(type: AT | ATC): ATC; public static withInput(type: AT | ATC): ATC { return Argument.withInput(type as any); } } -type ArgumentTypeCasterReturn = R extends BushArgumentTypeCaster ? S : R; +type BushArgumentTypeCasterReturn = R extends BushArgumentTypeCaster ? S : R; /** ```ts - * = ArgumentTypeCaster + * = BushArgumentTypeCaster * ``` */ type ATC = BushArgumentTypeCaster; /** ```ts - * keyof BaseArgumentType + * keyof BaseBushArgumentType * ``` */ type KBAT = keyof BaseBushArgumentType; /** ```ts - * = ArgumentTypeCasterReturn + * = BushArgumentTypeCasterReturn * ``` */ -type ATCR = ArgumentTypeCasterReturn; +type ATCR = BushArgumentTypeCasterReturn; /** ```ts - * keyof BaseBushArgumentType | string + * BushArgumentType * ``` */ -type AT = BushArgumentTypeCaster | keyof BaseBushArgumentType | string; +type AT = BushArgumentType; /** ```ts - * BaseArgumentType + * BaseBushArgumentType * ``` */ type BAT = BaseBushArgumentType; /** ```ts - * = ArgumentTypeCaster> + * = BushArgumentTypeCaster> * ``` */ -type ATCATCR = BushArgumentTypeCaster>; +type ATCATCR = BushArgumentTypeCaster>; /** ```ts - * = ArgumentTypeCaster + * = BushArgumentTypeCaster * ``` */ type ATCBAT = BushArgumentTypeCaster; -- cgit