Skip to content

Commit

Permalink
refactor: improve description missing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Smart committed Dec 5, 2022
1 parent eae688a commit 0a28fab
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Interactions/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export type InteractionResponse =
data: Discord.InteractionCallbackAutocomplete
}

type EnforceDescription<T> = T extends {
type DescriptionMissing<A> = A extends {
type: Exclude<Discord.ApplicationCommandType, 1>
}
? T
: T extends { description: string }
? T
: "description is missing"
? false
: A extends { description: string }
? false
: true

export type InteractionDefinition<R, E> =
| GlobalApplicationCommand<R, E>
Expand All @@ -50,13 +50,15 @@ export const global = <
E,
A extends Discord.CreateGlobalApplicationCommandParams,
>(
command: EnforceDescription<A>,
handle: Effect<R, E, InteractionResponse>,
command: A,
handle: DescriptionMissing<A> extends true
? "command description is missing"
: Effect<R, E, InteractionResponse>,
) =>
new GlobalApplicationCommand<
Exclude<R, Discord.Interaction | Discord.ApplicationCommandDatum>,
E
>(command as any, handle as any)
>(command, handle as any)

export class GuildApplicationCommand<R, E> {
readonly _tag = "GuildApplicationCommand"
Expand All @@ -71,13 +73,15 @@ export const guild = <
E,
A extends Discord.CreateGuildApplicationCommandParams,
>(
command: EnforceDescription<A>,
handle: Effect<R, E, InteractionResponse>,
command: A,
handle: DescriptionMissing<A> extends true
? "command description is missing"
: Effect<R, E, InteractionResponse>,
) =>
new GuildApplicationCommand<
Exclude<R, Discord.Interaction | Discord.ApplicationCommandDatum>,
E
>(command as any, handle as any)
>(command, handle as any)

export class MessageComponent<R, E> {
readonly _tag = "MessageComponent"
Expand Down

0 comments on commit 0a28fab

Please sign in to comment.