UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

135 lines (134 loc) 11.5 kB
import { EventSpewer, EventSubscription } from 'detritus-utils'; import { ShardClient } from './client'; import { ClusterClient, ClusterClientOptions, ClusterClientRunOptions } from './clusterclient'; import { ClusterProcessChild } from './cluster/processchild'; import { BaseCollection, BaseSet } from './collections'; import { CommandClient } from './commandclient'; import { ClientEvents } from './constants'; import { GatewayClientEvents } from './gateway/clientevents'; import { ApplicationCommand, InteractionDataApplicationCommand, InteractionDataApplicationCommandOption, InteractionDataApplicationCommandResolved } from './structures'; import { CommandRatelimit, CommandRatelimitOptions, CommandRatelimiter } from './commandratelimit'; import { CommandCallbackRun, ParsedArgs, ParsedErrors, InteractionCommand, InteractionCommandEvents, InteractionCommandOption, InteractionCommandOptions, InteractionContext } from './interaction'; export interface InteractionCommandClientOptions extends ClusterClientOptions { checkCommands?: boolean; ratelimit?: CommandRatelimitOptions; ratelimits?: Array<CommandRatelimitOptions>; ratelimiter?: CommandRatelimiter; strictCommandCheck?: boolean; useClusterClient?: boolean; onCommandCheck?: InteractionCommandClientCommandCheck; onCommandCancel?: InteractionCommandClientCommandCancel; onInteractionCheck?: InteractionCommandClientInteractionCheck; onInteractionCancel?: InteractionCommandClientInteractionCancel; } export declare type InteractionCommandClientCommandCheck = (context: InteractionContext, command: InteractionCommand) => Promise<boolean> | boolean; export declare type InteractionCommandClientCommandCancel = (context: InteractionContext, command: InteractionCommand) => Promise<any> | any; export declare type InteractionCommandClientInteractionCheck = (context: InteractionContext) => Promise<boolean> | boolean; export declare type InteractionCommandClientInteractionCancel = (context: InteractionContext) => Promise<any> | any; export interface InteractionCommandClientAddOptions extends InteractionCommandOptions { _class?: any; } export interface InteractionCommandClientRunOptions extends ClusterClientRunOptions { directories?: Array<string>; } /** * Interaction Command Client, hooks onto a ClusterClient or ShardClient to provide easier command handling * Flow is `onInteractionCheck` -> `onCommandCheck` * @category Clients */ export declare class InteractionCommandClient extends EventSpewer { readonly _clientSubscriptions: Array<EventSubscription>; checkCommands: boolean; client: ClusterClient | ShardClient; commands: BaseSet<InteractionCommand<ParsedArgs>>; commandsById: BaseCollection<string, BaseSet<InteractionCommand<ParsedArgs>>>; directories: BaseCollection<string, { subdirectories: boolean; }>; ran: boolean; ratelimits: Array<CommandRatelimit>; ratelimiter: CommandRatelimiter; strictCommandCheck: boolean; onCommandCheck?(context: InteractionContext, command: InteractionCommand): Promise<boolean> | boolean; onCommandCancel?(context: InteractionContext, command: InteractionCommand): Promise<any> | any; onInteractionCheck?(context: InteractionContext): Promise<boolean> | boolean; onInteractionCancel?(context: InteractionContext): Promise<any> | any; constructor(token: ClusterClient | CommandClient | ShardClient | string, options?: InteractionCommandClientOptions); get canUpload(): boolean; get manager(): ClusterProcessChild | null; get rest(): import("detritus-client-rest").Client | import("./rest").RestClient; add(options: InteractionCommand | InteractionCommandClientAddOptions, run?: CommandCallbackRun): this; addMultiple(commands?: Array<InteractionCommand | InteractionCommandOptions>): this; addMultipleIn(directory: string, options?: { isAbsolute?: boolean; subdirectories?: boolean; }): Promise<this>; clear(): void; clearSubscriptions(): void; resetCommands(): Promise<void>; checkApplicationCommands(guildId?: string): Promise<boolean>; checkAndUploadCommands(force?: boolean): Promise<void>; createApplicationCommandsFromRaw(data: Array<any>): BaseCollection<string, ApplicationCommand>; fetchApplicationCommands(guildId?: string): Promise<BaseCollection<string, ApplicationCommand>>; uploadApplicationCommands(guildId?: string): Promise<BaseCollection<string, ApplicationCommand>>; validateCommands(commands: BaseCollection<string, ApplicationCommand>): boolean; validateCommandsFromRaw(data: Array<any>): boolean; parseArgs(context: InteractionContext, data: InteractionDataApplicationCommand): Promise<[ParsedArgs, ParsedErrors | null]>; parseArgsFromContextMenu(data: InteractionDataApplicationCommand): Promise<[ParsedArgs, null]>; parseArgsFromOptions(context: InteractionContext, commandOptions?: BaseCollection<string, InteractionCommandOption>, options?: BaseCollection<string, InteractionDataApplicationCommandOption>, resolved?: InteractionDataApplicationCommandResolved): Promise<[ParsedArgs, ParsedErrors | null]>; parseDefaultArgsFromOptions(context: InteractionContext, commandOptions: BaseCollection<string, InteractionCommandOption>, args?: ParsedArgs, errors?: ParsedErrors): Promise<boolean>; setSubscriptions(): void; kill(): void; run(options?: InteractionCommandClientRunOptions): Promise<ClusterClient | ShardClient>; handleInteractionCreate(event: GatewayClientEvents.InteractionCreate): Promise<void>; handle(name: ClientEvents.INTERACTION_CREATE, event: GatewayClientEvents.InteractionCreate): Promise<void>; on(event: string | symbol, listener: (...args: any[]) => void): this; on(event: ClientEvents.COMMAND_ERROR, listener: (payload: InteractionCommandEvents.CommandError) => any): this; on(event: 'commandError', listener: (payload: InteractionCommandEvents.CommandError) => any): this; on(event: ClientEvents.COMMAND_FAIL, listener: (payload: InteractionCommandEvents.CommandFail) => any): this; on(event: 'commandFail', listener: (payload: InteractionCommandEvents.CommandFail) => any): this; on(event: ClientEvents.COMMAND_PERMISSIONS_FAIL_CLIENT, listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): this; on(event: 'commandPermissionsFailClient', listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): this; on(event: ClientEvents.COMMAND_PERMISSIONS_FAIL, listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): this; on(event: 'commandPermissionsFail', listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): this; on(event: ClientEvents.COMMAND_RAN, listener: (payload: InteractionCommandEvents.CommandRan) => any): this; on(event: 'commandRan', listener: (payload: InteractionCommandEvents.CommandRan) => any): this; on(event: ClientEvents.COMMAND_RATELIMIT, listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): this; on(event: 'commandRatelimit', listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): this; on(event: ClientEvents.COMMAND_RUN_ERROR, listener: (payload: InteractionCommandEvents.CommandRunError) => any): this; on(event: 'commandRunError', listener: (payload: InteractionCommandEvents.CommandRunError) => any): this; on(event: ClientEvents.KILLED, listener: () => any): this; once(event: string | symbol, listener: (...args: any[]) => void): this; once(event: ClientEvents.COMMAND_ERROR, listener: (payload: InteractionCommandEvents.CommandError) => any): this; once(event: 'commandError', listener: (payload: InteractionCommandEvents.CommandError) => any): this; once(event: ClientEvents.COMMAND_FAIL, listener: (payload: InteractionCommandEvents.CommandFail) => any): this; once(event: 'commandFail', listener: (payload: InteractionCommandEvents.CommandFail) => any): this; once(event: ClientEvents.COMMAND_PERMISSIONS_FAIL_CLIENT, listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): this; once(event: 'commandPermissionsFailClient', listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): this; once(event: ClientEvents.COMMAND_PERMISSIONS_FAIL, listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): this; once(event: 'commandPermissionsFail', listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): this; once(event: ClientEvents.COMMAND_RAN, listener: (payload: InteractionCommandEvents.CommandRan) => any): this; once(event: 'commandRan', listener: (payload: InteractionCommandEvents.CommandRan) => any): this; once(event: ClientEvents.COMMAND_RATELIMIT, listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): this; once(event: 'commandRatelimit', listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): this; once(event: ClientEvents.COMMAND_RUN_ERROR, listener: (payload: InteractionCommandEvents.CommandRunError) => any): this; once(event: 'commandRunError', listener: (payload: InteractionCommandEvents.CommandRunError) => any): this; once(event: ClientEvents.KILLED, listener: () => any): this; subscribe(event: string | symbol, listener: (...args: any[]) => void): EventSubscription; subscribe(event: ClientEvents.COMMAND_ERROR, listener: (payload: InteractionCommandEvents.CommandError) => any): EventSubscription; subscribe(event: 'commandError', listener: (payload: InteractionCommandEvents.CommandError) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_FAIL, listener: (payload: InteractionCommandEvents.CommandFail) => any): EventSubscription; subscribe(event: 'commandFail', listener: (payload: InteractionCommandEvents.CommandFail) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_PERMISSIONS_FAIL_CLIENT, listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): EventSubscription; subscribe(event: 'commandPermissionsFailClient', listener: (payload: InteractionCommandEvents.CommandPermissionsFailClient) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_PERMISSIONS_FAIL, listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): EventSubscription; subscribe(event: 'commandPermissionsFail', listener: (payload: InteractionCommandEvents.CommandPermissionsFail) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_RAN, listener: (payload: InteractionCommandEvents.CommandRan) => any): EventSubscription; subscribe(event: 'commandRan', listener: (payload: InteractionCommandEvents.CommandRan) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_RATELIMIT, listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): EventSubscription; subscribe(event: 'commandRatelimit', listener: (payload: InteractionCommandEvents.CommandRatelimit) => any): EventSubscription; subscribe(event: ClientEvents.COMMAND_RUN_ERROR, listener: (payload: InteractionCommandEvents.CommandRunError) => any): EventSubscription; subscribe(event: 'commandRunError', listener: (payload: InteractionCommandEvents.CommandRunError) => any): EventSubscription; subscribe(event: ClientEvents.KILLED, listener: () => any): EventSubscription; subscribe(event: 'killed', listener: () => any): EventSubscription; }