import type { RestObserver, RestObserverFailPayload, RestObserverRatelimitPayload, RestObserverRequestPayload, RestObserverSuccessPayload } from '../../api/shared'; import type { BaseResource, Cache } from '../../cache'; import type { AnyMiddlewareContext, Command, CommandContext, ContextMenuCommand, EntryPointCommand, EntryPointContext, MenuCommandContext, MiddlewareContext, SubCommand, UsingClient } from '../../commands'; import type { CommandAutocompleteOption } from '../../commands/applications/chat'; import type { HandleableCommand, HandleableCommandInstance } from '../../commands/handler'; import type { Awaitable } from '../../common/types/util'; import type { ComponentCommand, ModalCommand } from '../../components'; import type { ClientEvent, ClientNameEvents, CustomEventsKeys } from '../../events'; import type { GatewayEvents, ResolveEventParams } from '../../events/handler'; import type { AutocompleteInteraction } from '../../structures'; import type { GatewayDispatchPayload, GatewayIntentBits, GatewaySendPayload, LocaleString } from '../../types'; import type { BaseClient, BaseClientOptions } from '../base'; import type { MessageStructure, OptionResolverStructure } from '../transformers'; export interface SeyfertRegistry { } export interface RegisteredPluginShared { } export interface SharedKey { readonly name: Name; readonly __shared?: T; } export type SharedValue = T extends SharedKey ? Value : never; export interface PluginSharedRegistry { get(name: Name): RegisteredPluginShared[Name] | undefined; get(key: SharedKey): T | undefined; unwrap(name: Name): RegisteredPluginShared[Name]; unwrap(key: SharedKey): T; has(name: Name | SharedKey): boolean; } export interface PluginSharedOptions { dispose?: (value: T) => Awaitable; override?: boolean; } export interface PluginLangOptions { readonly prefix: string; } export interface PluginCommandContributionOptions extends PluginContributionOptions { guilds?: readonly string[]; } export interface PluginMiddlewareDenialMetadata { middleware: string; scope: 'global' | 'command'; } export declare enum PluginOrder { Before = "before", After = "after" } export type PluginOrderOpt = PluginOrder.Before | PluginOrder.After | number; export type PluginDiagnosticSeverity = 'info' | 'warn' | 'error'; export type PluginDiagnosticCode = 'missing-optional-requirement' | 'unknown-intent-bits' | 'gateway-send-payload-veto' | 'gateway-dispatch-veto' | 'contribution-override' | 'contribution-removed' | 'command-guild-scope' | 'static-keys-multi-instance' | (string & {}); export type PluginLifecycleStatus = 'registered' | 'setting-up' | 'ready' | 'closing' | 'closed' | 'failed'; export type PluginRequirement = `plugin:${string}`; type SemverVersion = `${number}.${number}.${number}${string}`; export type SemverRange = SemverVersion | `>=${SemverVersion}` | `^${SemverVersion}` | `~${SemverVersion}`; export type PluginRequirementInput = PluginRequirement | { req: PluginRequirement; range?: SemverRange; optional?: boolean; capability?: never; } | { capability: SharedKey; optional?: boolean; req?: never; range?: never; }; export type PluginIntentResolvable = keyof typeof GatewayIntentBits | GatewayIntentBits | number; export type PluginLifecyclePhase = 'resolve' | 'requires' | 'options' | 'register' | 'client' | 'ctx' | 'shared' | 'commands.add' | 'components.add' | 'setup' | 'teardown' | `event:${string}`; export interface PluginDiagnosticMessage { plugin: string; instanceId?: string; index: number; phase: PluginLifecyclePhase | string; severity: PluginDiagnosticSeverity; code?: PluginDiagnosticCode; message: string; data?: Record; } export interface PluginRequirementDiagnostic { kind: 'plugin' | 'capability'; req: PluginRequirement | string; range?: SemverRange; resolvedVersion?: string; optional: boolean; satisfied: boolean; } export interface PluginLoadedMetadata { kind: TKind; total: number; items: readonly TItem[]; plugin: { total: number; sources: Readonly>; }; } export interface PluginUploadCommandsMetadata { applicationId: string; cachePath?: string; commands: number; guildId?: string; reason: 'cache-hit' | 'cache-miss' | 'forced'; scope: 'global' | 'guild'; status: 'skipped' | 'uploaded'; } export interface PluginAutocompletePayload { client: BaseClient; command?: CommandAutocompleteOption; interaction: AutocompleteInteraction; optionsResolver: OptionResolverStructure; } export type PluginAutocompleteNext = () => Awaitable; export type PluginAutocompleteWrapper = (payload: PluginAutocompletePayload, next: PluginAutocompleteNext) => Awaitable; export interface PluginGatewaySendPayload { client: BaseClient; payload: GatewaySendPayload; shardId: number; } export type PluginGatewaySendPayloadWrapper = (payload: PluginGatewaySendPayload) => Awaitable; export interface PluginGatewayDispatchMeta { readonly client: BaseClient; readonly shardId: number; } export type PluginGatewayDispatchNext = (packet?: GatewayDispatchPayload) => Awaitable; export type PluginGatewayDispatchInterceptor = (packet: GatewayDispatchPayload, next: PluginGatewayDispatchNext, meta: PluginGatewayDispatchMeta) => Awaitable; export type PluginRestRequestPayload = RestObserverRequestPayload; export type PluginRestSuccessPayload = RestObserverSuccessPayload; export type PluginRestFailPayload = RestObserverFailPayload; export type PluginRestRatelimitPayload = RestObserverRatelimitPayload; export type PluginRestObserver = RestObserver; export type PluginCacheResourceConstructor = new (cache: Cache, client: UsingClient) => T; export interface PluginCacheResourceOptions { onPacket?(event: GatewayDispatchPayload, cache: Cache): Awaitable; intents?: readonly PluginIntentResolvable[]; } export interface SeyfertPluginHooks { 'plugins:ready': [client: BaseClient]; 'plugins:setupComplete': [client: BaseClient]; 'commands:beforeLoad': [client: BaseClient, dir: string | undefined]; 'commands:afterLoad': [metadata: PluginLoadedMetadata<'commands'>]; 'components:beforeLoad': [client: BaseClient, dir: string | undefined]; 'components:afterLoad': [metadata: PluginLoadedMetadata<'components'>]; 'events:beforeLoad': [client: BaseClient, dir: string | undefined]; 'events:afterLoad': [client: BaseClient, dir: string | undefined]; 'client:close': [client: BaseClient]; } export type PluginHookName = keyof SeyfertPluginHooks & string; export type PluginHookPayload = SeyfertPluginHooks[K] extends readonly unknown[] ? SeyfertPluginHooks[K] : never; type PluginHookPayloadClientView = T extends BaseClient ? T & E : T; type PluginHookPayloadTupleView = T extends readonly [ infer Head, ...infer Tail ] ? [PluginHookPayloadClientView, ...PluginHookPayloadTupleView] : []; export type PluginHookPayloadFor = PluginHookPayloadTupleView, E>; export type PluginHookHandler = (...args: PluginHookPayloadFor) => Awaitable; export type SeyfertPluginOptions = Partial>; export type SeyfertCommandDefaults = NonNullable['defaults']>; export type SeyfertComponentDefaults = NonNullable['defaults']>; export type SeyfertModalDefaults = NonNullable['defaults']>; export type PluginClientMap = { readonly [K in keyof T]: (client: BaseClient & ExtendOf) => T[K]; }; export type PluginContextInteraction = Parameters>[0] | MessageStructure; export type PluginContextMap = { readonly [K in keyof T]: (interaction: PluginContextInteraction, client: BaseClient & ExtendOf & E) => T[K]; }; export type PluginMiddlewareMap = Record; export type AnySeyfertPlugin = SeyfertPlugin; export type PluginExtensionOf = T extends SeyfertPlugin ? E : {}; export type PluginContextOf = T extends SeyfertPlugin ? C : {}; export type PluginMiddlewaresOf = T extends SeyfertPlugin ? (IsOpenPluginMiddlewareMap extends true ? {} : M) : {}; type PluginImportsOf = T extends SeyfertPlugin ? I[number] : never; type PluginClosureDepth = [never, 0, 1, 2, 3, 4, 5]; type PluginClosureOf = [Depth] extends [0] ? T : T | PluginClosureOf, PluginClosureDepth[Depth]>; type PluginTupleClosure = PluginClosureOf; export type ExtendOf = UnionToIntersection>>; export type ContextOf = UnionToIntersection>>; export type MiddlewaresOf = UnionToIntersection>>; export type RegisteredPlugins = SeyfertRegistry extends { plugins: infer T extends readonly AnySeyfertPlugin[]; } ? T : readonly []; export type RegisteredPluginExtension = Materialize>; export type RegisteredPluginContext = Materialize>; export type RegisteredPluginMiddlewares = Materialize>; export type PluginUsingClient = BaseClient & Materialize>; export type PluginContextMapOf = Materialize>; export type PluginMiddlewaresMapOf = Materialize>; type UnionToIntersection = (T extends unknown ? (value: T) => void : never) extends (value: infer R) => void ? R : never; type IsAny = 0 extends 1 & T ? true : false; type IsOpenPluginMiddlewareMap = IsAny extends true ? true : string extends keyof T ? true : false; type Materialize = { [K in keyof T]: T[K]; }; export type HandleableComponent = new () => ComponentCommand; export type HandleableModal = new () => ModalCommand; export type PluginCommandInstance = HandleableCommandInstance; export type PluginComponentInstance = ComponentCommand; export type PluginModalInstance = ModalCommand; export type PluginCommandLoadable = HandleableCommand | PluginCommandInstance; export type PluginComponentLoadable = HandleableComponent | PluginComponentInstance; export type PluginModalLoadable = HandleableModal | PluginModalInstance; export type PluginHandlerKind = 'command' | 'component' | 'modal' | 'event'; export type PluginHandlerConstructor = HandleableCommand | HandleableComponent | HandleableModal; export type PluginHandlerInstance = PluginCommandInstance | PluginComponentInstance | PluginModalInstance; /** Raw event module export: a `createEvent` object, or a class to be normalized into one (e.g. DI containers). */ export type PluginEventLoadable = ClientEvent | object; export interface PluginHandlerValueByKind { command: PluginCommandInstance; component: PluginComponentInstance; modal: PluginModalInstance; event: PluginEventLoadable; } export interface PluginHandlerMetadata { kind: K; } export type PluginHandlerCreator = (constructor: T, next: () => InstanceType, metadata: PluginHandlerMetadata) => InstanceType; export type PluginHandlerTransformer = (instance: PluginHandlerValueByKind[K], metadata: PluginHandlerMetadata) => PluginHandlerValueByKind[K] | void; export interface PluginHandlerOptions { kinds?: readonly PluginHandlerKind[]; order?: PluginOrderOpt; } export type PluginDisposer = () => void; export type PluginEventErrorHandler = (error: unknown, name: string) => unknown; export interface PluginContributionOptions { override?: boolean; } export interface PluginMiddlewareOptions extends PluginContributionOptions { global?: boolean; order?: PluginOrderOpt; } export type PluginCommandObserverContext = CommandContext | MenuCommandContext | EntryPointContext; export type PluginCommandObserverCommand = Command | SubCommand | ContextMenuCommand | EntryPointCommand; export interface PluginCommandObserver { onBeforeOptions?(context: CommandContext): Awaitable; onBeforeMiddlewares?(context: PluginCommandObserverContext): Awaitable; onMiddlewaresError?(context: PluginCommandObserverContext, error: string, metadata: PluginMiddlewareDenialMetadata): Awaitable; onRunError?(context: PluginCommandObserverContext, error: unknown): Awaitable; onAfterRun?(context: PluginCommandObserverContext, error: unknown | undefined): Awaitable; onInternalError?(client: UsingClient, command: PluginCommandObserverCommand, error?: unknown): Awaitable; } export interface SeyfertPluginApi { has(req: PluginRequirement): boolean; events: { on(name: E, handler: (...args: ResolveEventParams) => unknown, opts?: { once?: boolean; order?: PluginOrderOpt; }): PluginDisposer; once(name: E, handler: (...args: ResolveEventParams) => unknown): PluginDisposer; onAny(handler: (name: string, ...args: unknown[]) => unknown, opts?: { order?: PluginOrderOpt; }): PluginDisposer; onError(handler: PluginEventErrorHandler, opts?: { order?: PluginOrderOpt; }): PluginDisposer; }; commands: { add(...commands: PluginCommandLoadable[]): void; add(...args: [...commands: PluginCommandLoadable[], opts: PluginCommandContributionOptions]): void; remove(...names: string[]): void; observe(observer: PluginCommandObserver, opts?: { order?: PluginOrderOpt; }): PluginDisposer; defaults(hooks: Partial, opts?: { suppressDefault?: boolean | readonly (keyof SeyfertCommandDefaults)[]; order?: PluginOrderOpt; }): void; }; rest: { observe(observer: PluginRestObserver, opts?: { order?: PluginOrderOpt; }): PluginDisposer; }; hooks: { on(name: K, handler: PluginHookHandler, opts?: { order?: PluginOrderOpt; }): PluginDisposer; }; handlers: { construct(creator: PluginHandlerCreator, opts?: PluginHandlerOptions): void; transform(transformer: PluginHandlerTransformer, opts?: PluginHandlerOptions): void; }; components: { add(...components: PluginComponentLoadable[]): void; add(...args: [...components: PluginComponentLoadable[], opts: PluginContributionOptions]): void; remove(...customIds: string[]): void; defaults(hooks: Partial, opts?: { suppressDefault?: boolean | readonly (keyof SeyfertComponentDefaults)[]; order?: PluginOrderOpt; }): void; }; modals: { add(...modals: PluginModalLoadable[]): void; add(...args: [...modals: PluginModalLoadable[], opts: PluginContributionOptions]): void; remove(...customIds: string[]): void; defaults(hooks: Partial, opts?: { suppressDefault?: boolean | readonly (keyof SeyfertModalDefaults)[]; order?: PluginOrderOpt; }): void; }; middlewares: { add(name: Name, middleware: M[Name], opts?: PluginMiddlewareOptions): void; add(name: Name extends keyof M & string ? never : Name, middleware: MiddlewareContext, opts?: PluginMiddlewareOptions): void; remove(...names: string[]): void; }; autocomplete: { wrap(wrapper: PluginAutocompleteWrapper, opts?: { order?: PluginOrderOpt; }): void; }; gateway: { addIntents(...intents: PluginIntentResolvable[]): void; wrapSendPayload(wrapper: PluginGatewaySendPayloadWrapper, opts?: { order?: PluginOrderOpt; }): void; onDispatch(interceptor: PluginGatewayDispatchInterceptor, opts?: { order?: PluginOrderOpt; }): PluginDisposer; }; cache: { resource(name: string, resource: PluginCacheResourceConstructor, opts?: PluginCacheResourceOptions): void; }; shared: { set(key: SharedKey, factory: (client: BaseClient & E) => T, opts?: PluginSharedOptions): void; set(name: Name, factory: (client: BaseClient & E) => RegisteredPluginShared[Name], opts?: PluginSharedOptions): void; remove(...names: (string | SharedKey)[]): void; has(name: Name | SharedKey): boolean; }; langs: { contribute(locale: LocaleString | string, values: Record, opts: PluginLangOptions): void; }; reload(): Promise; diagnostics: { warn(message: string, options?: { code?: PluginDiagnosticCode; phase?: PluginLifecyclePhase | string; data?: Record; }): void; }; options: { set(fragment: SeyfertPluginOptions): void; }; } export type SeyfertPluginTeardownApi = Pick & { shared: Pick; }; export type ResolvedPluginList = readonly AnySeyfertPlugin[] & { readonly resolved: readonly AnySeyfertPlugin[]; readonly diagnostics: readonly PluginDiagnostics[]; }; export type SeyfertPluginClient = BaseClient & { plugins: ResolvedPluginList; }; export interface SeyfertPlugin { name: string; instanceId?: string; version?: string; imports?: I; requires?: readonly PluginRequirementInput[]; meta?: unknown; client?: PluginClientMap; ctx?: PluginContextMap; middlewares?: M; globalMiddlewares?: readonly (keyof M & string)[]; options?(current: Readonly): SeyfertPluginOptions; register?(api: SeyfertPluginApi & E>): void; setup?(client: SeyfertPluginClient & ExtendOf & E, api?: SeyfertPluginApi & E>): Awaitable; teardown?(client: SeyfertPluginClient & ExtendOf & E, api?: SeyfertPluginTeardownApi): Awaitable; } export interface PluginDiagnostics { name: string; instanceId?: string; index: number; status: PluginLifecycleStatus; imports: readonly string[]; clientKeys: readonly string[]; ctxKeys: readonly string[]; commands: number; components: number; modals: number; events: readonly string[]; anyEvents: number; eventErrors: number; middlewares: readonly string[]; requirements: readonly PluginRequirementDiagnostic[]; shared: readonly string[]; cacheResources: readonly string[]; langs: readonly string[]; hooks: readonly string[]; restObservers: number; commandObservers: number; autocompleteWrappers: number; gatewayIntents: number; gatewaySendPayloadWrappers: number; gatewayDispatchInterceptors: number; handlerCreators: number; handlerTransformers: number; messages: readonly PluginDiagnosticMessage[]; truncated?: Readonly>; } export {};