UNPKG

seyfert

Version:

The most advanced framework for discord bots

143 lines (142 loc) 6.73 kB
import type { PermissionStrings, SeyfertBaseChoiceableOption, SeyfertBasicOption, SeyfertChoice } from '../..'; import type { Attachment } from '../../builders'; import type { GuildRoleStructure, InteractionGuildMemberStructure, UserStructure } from '../../client/transformers'; import type { AllChannels, AutocompleteInteraction } from '../../structures'; import { type APIApplicationCommandBasicOption, type APIApplicationCommandOption, ApplicationCommandOptionType, ApplicationCommandType, type ApplicationIntegrationType, type InteractionContextType, type LocaleString } from '../../types'; import type { Groups, RegisteredMiddlewares } from '../decorators'; import type { CommandContext } from './chatcontext'; import type { ExtraProps, IgnoreCommand, OnOptionsReturnObject, SeyfertChannelMap, UsingClient } from './shared'; export interface ReturnOptionsTypes { 1: never; 2: never; 3: string; 4: number; 5: boolean; 6: InteractionGuildMemberStructure | UserStructure; 7: AllChannels; 8: GuildRoleStructure; 9: GuildRoleStructure | AllChannels | UserStructure; 10: number; 11: Attachment; } export type AutocompleteCallback = (interaction: AutocompleteInteraction) => any; export type OnAutocompleteErrorCallback = (interaction: AutocompleteInteraction, error: unknown) => any; export type CommandBaseOption = SeyfertBaseChoiceableOption<ApplicationCommandOptionType> | SeyfertBasicOption<ApplicationCommandOptionType>; export type CommandBaseAutocompleteOption = (SeyfertBasicOption<ApplicationCommandOptionType> | SeyfertBaseChoiceableOption<ApplicationCommandOptionType>) & { autocomplete: AutocompleteCallback; onAutocompleteError?: OnAutocompleteErrorCallback; }; export type CommandAutocompleteOption = CommandBaseAutocompleteOption & { name: string; }; export type CommandOptionWithoutName = CommandBaseOption; export type CommandOption = CommandOptionWithoutName & { name: string; }; export type OptionsRecord = Record<string, CommandOptionWithoutName & { type: ApplicationCommandOptionType; }>; type KeysWithoutRequired<T extends OptionsRecord> = { [K in keyof T]-?: NonNullable<T[K]['required']> extends true ? never : K; }[keyof T]; type ContextOptionsAuxInternal<T extends CommandBaseOption & { type: ApplicationCommandOptionType; }> = T['value'] extends (...args: any) => any ? Parameters<Parameters<T['value']>[1]>[0] : NonNullable<T['value']> extends (...args: any) => any ? Parameters<Parameters<NonNullable<T['value']>>[1]>[0] extends never ? T extends { channel_types?: infer C; } ? C extends any[] ? C[number] extends keyof SeyfertChannelMap ? SeyfertChannelMap[C[number]] : never : never : T extends { choices?: infer C; } ? C extends SeyfertChoice<string | number>[] ? C[number]['value'] : never : never : Parameters<Parameters<NonNullable<T['value']>>[1]>[0] : ReturnOptionsTypes[T['type']]; type ContextOptionsAux<T extends OptionsRecord> = { [K in Exclude<keyof T, KeysWithoutRequired<T>>]: ContextOptionsAuxInternal<T[K]>; } & { [K in KeysWithoutRequired<T>]?: ContextOptionsAuxInternal<T[K]>; }; export type ContextOptions<T extends OptionsRecord> = ContextOptionsAux<T>; export declare class BaseCommand { middlewares: (keyof RegisteredMiddlewares)[]; __filePath?: string; __t?: { name: string | undefined; description: string | undefined; }; __autoload?: true; guildId?: string[]; name: string; type: number; nsfw?: boolean; description: string; defaultMemberPermissions?: bigint; integrationTypes: ApplicationIntegrationType[]; contexts: InteractionContextType[]; botPermissions?: bigint; name_localizations?: Partial<Record<LocaleString, string>>; description_localizations?: Partial<Record<LocaleString, string>>; options?: CommandOption[] | SubCommand[]; ignore?: IgnoreCommand; aliases?: string[]; props: ExtraProps; toJSON(): { name: BaseCommand["name"]; type: BaseCommand["type"]; nsfw: BaseCommand["nsfw"]; description: BaseCommand["description"]; name_localizations: BaseCommand["name_localizations"]; description_localizations: BaseCommand["description_localizations"]; guild_id: BaseCommand["guildId"]; default_member_permissions: string; contexts: BaseCommand["contexts"]; integration_types: BaseCommand["integrationTypes"]; }; reload(): Promise<void>; run?(context: CommandContext): any; onAfterRun?(context: CommandContext, error: unknown | undefined): any; onRunError?(context: CommandContext, error: unknown): any; onOptionsError?(context: CommandContext, metadata: OnOptionsReturnObject): any; onMiddlewaresError?(context: CommandContext, error: string): any; onBotPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any; onPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any; onInternalError?(client: UsingClient, command: Command | SubCommand, error?: unknown): any; } export declare class Command extends BaseCommand { type: ApplicationCommandType; groups?: Parameters<typeof Groups>[0]; groupsAliases?: Record<string, string>; __tGroups?: Record<string, { name: string | undefined; description: string | undefined; defaultDescription: string; }>; toJSON(): { options: APIApplicationCommandOption[]; name: BaseCommand["name"]; type: BaseCommand["type"]; nsfw: BaseCommand["nsfw"]; description: BaseCommand["description"]; name_localizations: BaseCommand["name_localizations"]; description_localizations: BaseCommand["description_localizations"]; guild_id: BaseCommand["guildId"]; default_member_permissions: string; contexts: BaseCommand["contexts"]; integration_types: BaseCommand["integrationTypes"]; }; } export declare abstract class SubCommand extends BaseCommand { type: ApplicationCommandOptionType; group?: string; options?: CommandOption[]; toJSON(): { options: APIApplicationCommandBasicOption[]; name: BaseCommand["name"]; type: BaseCommand["type"]; nsfw: BaseCommand["nsfw"]; description: BaseCommand["description"]; name_localizations: BaseCommand["name_localizations"]; description_localizations: BaseCommand["description_localizations"]; guild_id: BaseCommand["guildId"]; default_member_permissions: string; contexts: BaseCommand["contexts"]; integration_types: BaseCommand["integrationTypes"]; }; abstract run(context: CommandContext): any; } export {};