seyfert
Version:
The most advanced framework for discord bots
176 lines (175 loc) • 7.7 kB
TypeScript
import { ApiHandler } from '../api';
import type { Adapter, DisabledCache } from '../cache';
import { Cache } from '../cache';
import type { Command, CommandContext, ContextMenuCommand, ExtendedRC, ExtendedRCLocations, ExtraProps, MenuCommandContext, RegisteredMiddlewares, SubCommand, UsingClient } from '../commands';
import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
import { CommandHandler } from '../commands/handler';
import { ApplicationShorter, ChannelShorter, EmojiShorter, GuildShorter, InteractionShorter, Logger, type MakeRequired, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, ThreadShorter, UsersShorter, WebhookShorter } from '../common';
import { HandleCommand } from '../commands/handle';
import { BanShorter } from '../common/shorters/bans';
import { SoundboardShorter } from '../common/shorters/soundboard';
import { VoiceStateShorter } from '../common/shorters/voiceStates';
import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util';
import type { ComponentCommand, ModalCommand } from '../components';
import { ComponentHandler } from '../components/handler';
import { LangsHandler } from '../langs/handler';
import type { ChatInputCommandInteraction, ComponentInteraction, EntryPointInteraction, MessageCommandInteraction, ModalSubmitInteraction, UserCommandInteraction } from '../structures';
import type { APIInteraction, APIInteractionResponse, LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types';
import type { MessageStructure } from './transformers';
export declare class BaseClient {
rest: ApiHandler;
cache: Cache;
applications: ApplicationShorter;
users: UsersShorter;
channels: ChannelShorter;
guilds: GuildShorter;
messages: MessageShorter;
members: MemberShorter;
webhooks: WebhookShorter;
templates: TemplateShorter;
roles: RoleShorter;
reactions: ReactionShorter;
emojis: EmojiShorter;
threads: ThreadShorter;
bans: BanShorter;
interactions: InteractionShorter;
voiceStates: VoiceStateShorter;
soundboards: SoundboardShorter;
debugger?: Logger;
logger: Logger;
langs: LangsHandler;
commands: CommandHandler;
components: ComponentHandler;
handleCommand: HandleCommand;
private _applicationId?;
private _botId?;
middlewares?: Record<string, MiddlewareContext>;
protected static getBotIdFromToken(token: string): string;
options: BaseClientOptions;
constructor(options?: BaseClientOptions);
get proxy(): import("../api").APIRoutes;
set botId(id: string);
get botId(): string;
set applicationId(id: string);
get applicationId(): string;
setServices({ rest, cache, langs, middlewares, handleCommand }: ServicesOptions): void;
protected execute(..._options: unknown[]): Promise<void>;
start(options?: Pick<DeepPartial<StartOptions>, 'langsDir' | 'commandsDir' | 'connection' | 'token' | 'componentsDir'>): Promise<void>;
protected onPacket(..._packet: unknown[]): Promise<any>;
/**
*
* @param rawBody body of interaction
* @returns
*/
onInteractionRequest(rawBody: APIInteraction): Promise<{
headers: {
'Content-Type'?: string;
};
response: APIInteractionResponse | FormData;
}>;
private shouldUploadCommands;
private syncCachePath;
uploadCommands({ applicationId, cachePath }?: {
applicationId?: string;
cachePath?: string;
}): Promise<void>;
loadCommands(dir?: string): Promise<void>;
loadComponents(dir?: string): Promise<void>;
loadLangs(dir?: string): Promise<void>;
t(locale: string): import("..").__InternalParseLocale<import("../commands").DefaultLocale> & {
get(locale?: string): import("../commands").DefaultLocale;
};
getRC<T extends InternalRuntimeConfigHTTP | InternalRuntimeConfig = InternalRuntimeConfigHTTP | InternalRuntimeConfig>(): Promise<{
debug: boolean;
} & Omit<T, "debug" | "locations"> & {
locations: RCLocations;
}>;
}
export interface BaseClientOptions {
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | EntryPointInteraction<boolean> | When<InferWithPrefix, MessageStructure, never>) => Record<string, unknown>;
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
commands?: {
defaults?: {
onRunError?: (context: MenuCommandContext<any, never> | CommandContext, error: unknown) => unknown;
onPermissionsFail?: Command['onPermissionsFail'];
onBotPermissionsFail?: (context: MenuCommandContext<any, never> | CommandContext, permissions: PermissionStrings) => unknown;
onInternalError?: (client: UsingClient, command: Command | SubCommand | ContextMenuCommand, error?: unknown) => unknown;
onMiddlewaresError?: (context: CommandContext | MenuCommandContext<any, never>, error: string) => unknown;
onOptionsError?: Command['onOptionsError'];
onAfterRun?: (context: CommandContext | MenuCommandContext<any, never>, error: unknown) => unknown;
props?: ExtraProps;
};
};
components?: {
defaults?: {
onRunError?: ComponentCommand['onRunError'];
onInternalError?: ComponentCommand['onInternalError'];
onMiddlewaresError?: ComponentCommand['onMiddlewaresError'];
onAfterRun?: ComponentCommand['onAfterRun'];
};
};
modals?: {
defaults?: {
onRunError?: ModalCommand['onRunError'];
onInternalError?: ModalCommand['onInternalError'];
onMiddlewaresError?: ModalCommand['onMiddlewaresError'];
onAfterRun?: ModalCommand['onAfterRun'];
};
};
allowedMentions?: RESTPostAPIChannelMessageJSONBody['allowed_mentions'];
getRC?(): Awaitable<InternalRuntimeConfig | InternalRuntimeConfigHTTP>;
}
export interface StartOptions {
eventsDir: string;
langsDir: string;
commandsDir: string;
componentsDir: string;
connection: {
intents: number;
};
httpConnection: {
publicKey: string;
port: number;
};
token: string;
}
interface RCLocations extends ExtendedRCLocations {
base: string;
commands?: string;
langs?: string;
events?: string;
components?: string;
}
interface RC extends ExtendedRC {
debug?: boolean;
locations: RCLocations;
token: string;
intents?: number;
applicationId?: string;
port?: number;
publicKey?: string;
}
export type InternalRuntimeConfigHTTP = Omit<MakeRequired<RC, 'publicKey' | 'port' | 'applicationId'>, 'intents' | 'locations'> & {
locations: Omit<RC['locations'], 'events'>;
};
export type RuntimeConfigHTTP = Omit<MakeRequired<RC, 'publicKey' | 'applicationId'>, 'intents' | 'locations'> & {
locations: Omit<RC['locations'], 'events'>;
};
export type InternalRuntimeConfig = MakeRequired<RC, 'intents'>;
export type RuntimeConfig = OmitInsert<InternalRuntimeConfig, 'intents', {
intents?: IntentStrings | number[] | number;
}>;
export interface ServicesOptions {
rest?: ApiHandler;
cache?: {
adapter?: Adapter;
disabledCache?: boolean | DisabledCache | ((cacheType: keyof DisabledCache) => boolean);
};
langs?: {
default?: string;
aliases?: Record<string, LocaleString[]>;
};
middlewares?: Record<string, MiddlewareContext>;
handleCommand?: typeof HandleCommand;
}
export {};