@seedcord/gateway 0.1.0-next.3 → 0.1.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,22 +1,31 @@
1
1
  import { AnyCustomId, AutocompletableNames, BaseReplySender, ChoiceValueOf, EntryFor, FocusedField, GateFitsWith, HasComponentDefs, MatchArms, ModalLike, PageCursor, SingleParams, SlashOptions as SlashOptions$1 } from "@seedcord/core/internal";
2
- import { AutocompleteOptions, BaseHandler, BuilderComponent, CoreBase, DispatchContext, Gate, GateContextBase, GateNoticeOptions, GuildPermissionsContext, Notice, PageView, PermissionScope, RepliableHandler as RepliableHandler$1, RequiredOf, SelectMenuKind, SlashOptionRegistry } from "@seedcord/core";
2
+ import { AutocompleteOptions, BaseHandler, BuilderComponent, CoreBase, DispatchContext, Gate, GateContextBase, GateNoticeOptions, GuildPermissionsContext, Initializeable, Notice, PageView, PermissionScope, RepliableHandler as RepliableHandler$1, RequiredOf, SelectMenuKind, SlashOptionRegistry } from "@seedcord/core";
3
3
  import { Logger } from "@seedcord/logger";
4
4
  import { ActionRowBuilder, ButtonBuilder, ContextMenuCommandBuilder, SlashCommandBuilder } from "@discordjs/builders";
5
5
  import { APIInteractionGuildMember, APIMessageComponentEmoji, APIModalInteractionResponseCallbackData, AnySelectMenuInteraction, ApplicationCommand, ApplicationCommandOptionChoiceData, ApplicationCommandType, ApplicationEmoji, AutocompleteInteraction, BooleanCache, ButtonInteraction, ButtonStyle, CacheType, CacheTypeReducer, ChannelSelectMenuInteraction, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Collection, CommandInteractionOption, ContextMenuCommandInteraction, Events, Guild, GuildEmoji, GuildMember, Interaction, MentionableSelectMenuInteraction, Message, MessageContextMenuCommandInteraction, ModalSubmitInteraction, Role, RoleSelectMenuInteraction, Snowflake, StringSelectMenuInteraction, TextChannel, TextChannelResolvable, User, UserContextMenuCommandInteraction, UserSelectMenuInteraction } from "discord.js";
6
6
  import { UUID } from "node:crypto";
7
- import { EventMap, NoEvents, TypedEventEmitter } from "@seedcord/event-emitter";
8
7
  import { APIMessageTopLevelComponent } from "discord-api-types/v10";
9
- import { CoordinatedShutdown, CoordinatedStartup, ShutdownPhase, StartupPhase, StartupPhase as StartupPhase$1 } from "@seedcord/core/node";
8
+ import { REST } from "@discordjs/rest";
9
+ import { CoordinatedShutdown, CoordinatedStartup, Pluggable, PluginCapabilities } from "@seedcord/core/node/internal";
10
10
  import { SeedcordBrand, SeedcordInstance } from "@seedcord/types/internal";
11
- import { BotConfig, Config, DeferOpts, EmojiMap, HmrAware, HmrUpdateEvent, IRateLimiter, ReplyResponse, SendOpts, Tail, V2Component } from "@seedcord/types";
11
+ import { TypedEventEmitter } from "@seedcord/event-emitter";
12
+ import { BotConfig, Config, DeferOpts, EmojiMap, HealthCheckOption, HmrAware, HmrUpdateEvent, IRateLimiter, ReplyResponse, SendOpts, V2Component } from "@seedcord/types";
12
13
  export * from "@seedcord/errors";
13
14
  export * from "@seedcord/core";
14
15
  export * from "@seedcord/logger";
15
- export * from "@seedcord/event-emitter";
16
16
  export * from "@seedcord/utils";
17
17
  export * from "@seedcord/rate-limiter";
18
+ export * from "@seedcord/event-emitter";
18
19
  export type * from "@seedcord/types";
19
20
 
21
+ //#region src/plugin-capabilities.d.ts
22
+ declare module '@seedcord/core' {
23
+ interface PluginCapabilityTypes {
24
+ client: Client;
25
+ rest: REST;
26
+ }
27
+ }
28
+ //#endregion
20
29
  //#region src/bot/utilities/miscellaneous/contextMenuLeaves.d.ts
21
30
  /** The registered context-menu command names, split by kind, deduplicated. @internal */
22
31
  interface ContextMenuLeaves {
@@ -56,93 +65,13 @@ interface GatewayBotConfig extends BotConfig {
56
65
  */
57
66
  interface GatewayConfig extends Config {
58
67
  bot: GatewayBotConfig;
59
- }
60
- //#endregion
61
- //#region src/interfaces/Plugin.d.ts
62
- interface Initializeable {
63
- init(): Promise<void>;
64
- }
65
- /**
66
- * Base class for Seedcord plugins
67
- *
68
- * Extend this class to create plugins that integrate with the Seedcord lifecycle.
69
- * Plugins have access to the core instance and must implement initialization logic.
70
- */
71
- declare abstract class Plugin<TPluginEvents extends EventMap<TPluginEvents> = NoEvents> extends TypedEventEmitter<TPluginEvents> implements Initializeable, HmrAware {
72
- protected pluggable: Core;
73
- abstract logger: Logger;
74
- name: string;
75
- constructor(pluggable: Core);
76
- /** @virtual */
77
- abstract init(): Promise<void>;
68
+ /** The gateway websocket requires a persistent process, so `'server'` is the only value. */
69
+ runtime?: 'server';
78
70
  /**
79
- * Reloads plugin state on an HMR update. The base implementation is a no-op, override it in your plugin.
80
- * @virtual
71
+ * The health-check server. `false` disables it, `true` or omit for the defaults, an object
72
+ * configures it.
81
73
  */
82
- onHmr(_event: HmrUpdateEvent): Promise<void>;
83
- /**
84
- * Registers critical file patterns that should trigger a full restart when changed in Dev HMR.
85
- * @param patterns - Glob patterns relative to the project root
86
- */
87
- protected registerCriticalFiles(patterns: string[]): void;
88
- /** @internal */
89
- removeListener<TEventKey extends Extract<keyof TPluginEvents, string | symbol>>(event: TEventKey, listener: (...args: TPluginEvents[TEventKey]) => void): this;
90
- /** @internal */
91
- removeAllListeners(event?: Extract<keyof TPluginEvents, string | symbol>): this;
92
- }
93
- /**
94
- * Constructor type for plugins that can accept extra arguments after Core.
95
- *
96
- * @internal
97
- */
98
- type PluginCtor<TPlugin extends Plugin = Plugin> = new (core: Core, ...args: any[]) => TPlugin;
99
- /**
100
- * Extracts the argument types for a plugin constructor, excluding the Core parameter.
101
- *
102
- * @internal
103
- */
104
- type PluginArgs<Ctor extends PluginCtor> = Tail<ConstructorParameters<Ctor>>;
105
- /**
106
- * Base class for objects that can have plugins attached.
107
- *
108
- * Provides plugin attachment capabilities and lifecycle management. Plugins are attached during
109
- * configuration and initialized during startup. Not constructed directly, the host is a {@link Seedcord}.
110
- */
111
- declare class Pluggable<TPluggableEvents extends EventMap<TPluggableEvents> = NoEvents> extends TypedEventEmitter<TPluggableEvents> {
112
- protected isInitialized: boolean;
113
- protected readonly shutdown: CoordinatedShutdown;
114
- protected readonly startup: CoordinatedStartup;
115
- protected readonly plugins: Plugin[];
116
- private static readonly PLUGIN_INIT_TIMEOUT_MS;
117
- constructor(shutdown: CoordinatedShutdown, startup: CoordinatedStartup);
118
- /** @internal */
119
- protected init(): Promise<this>;
120
- /**
121
- * Attaches a plugin to this instance
122
- *
123
- * Plugins provide external functionality and are initialized during the specified startup phase.
124
- * The plugin instance becomes available as a property in `core` wherever it's available.
125
- *
126
- * Make sure to augment the {@link Core} interface with the plugin type to ensure TypeScript recognizes it and provides intellisense.
127
- *
128
- * @typeParam Key - The property name for accessing the plugin
129
- * @typeParam Ctor - The plugin constructor type
130
- * @param key - Property name to access the plugin instance
131
- * @param Plugin - Plugin constructor class
132
- * @param startupPhase - When during startup to initialize this plugin ({@link StartupPhase})
133
- * @param args - Additional arguments to pass to the plugin constructor
134
- * @returns This instance with the plugin attached as a typed property
135
- * @throws A **SeedcordError** When called after initialization or if key already exists
136
- * @example
137
- * ```typescript
138
- * seedcord.attach('db', Mongo, StartupPhase.Configuration, { uri: 'mongodb://...', name: 'seedcord', dir: ... })
139
- * ```
140
- */
141
- attach<Key extends string, Ctor extends PluginCtor>(this: this, key: Key, Plugin: Ctor, startupPhase: StartupPhase$1, ...args: PluginArgs<Ctor>): this & Record<Key, InstanceType<Ctor>>;
142
- /** @internal */
143
- removeListener<TEventKey extends Extract<keyof TPluggableEvents, string | symbol>>(event: TEventKey, listener: (...args: TPluggableEvents[TEventKey]) => void): this;
144
- /** @internal */
145
- removeAllListeners(event?: Extract<keyof TPluggableEvents, string | symbol>): this;
74
+ healthCheck?: HealthCheckOption;
146
75
  }
147
76
  //#endregion
148
77
  //#region src/subscribers/types/Subscriptions.d.ts
@@ -237,11 +166,9 @@ type SubscriptionTuples = { [K in SubscriptionKey]: [AllSubscriptions[K]] };
237
166
  * Registers and dispatches subscribers. Subscribers load from the configured directories and run
238
167
  * on a programmatic or framework-event publish. Accessed via `core.bus`. Do not construct it directly.
239
168
  */
240
- declare class Bus extends Plugin<SubscriptionTuples> {
169
+ declare class Bus extends TypedEventEmitter<SubscriptionTuples> implements Initializeable, HmrAware {
241
170
  protected core: Core;
242
171
  readonly logger: Logger;
243
- /** @internal */
244
- readonly name = "Subscribers";
245
172
  private isInitialized;
246
173
  private readonly subscribersMap;
247
174
  private readonly executedOnceHandlers;
@@ -317,7 +244,6 @@ interface DeployResult {
317
244
  declare class CommandRegistry implements Initializeable, HmrAware {
318
245
  private readonly core;
319
246
  private readonly onDeployed?;
320
- readonly name = "Commands";
321
247
  private readonly logger;
322
248
  private isInitialised;
323
249
  readonly globalCommands: (SlashCommandBuilder | ContextMenuCommandBuilder)[];
@@ -389,11 +315,9 @@ interface BotEvents {
389
315
  ready: [];
390
316
  }
391
317
  /**
392
- * Discord bot implementation that manages client and controllers
393
- *
394
- * Don't instantiate this class directly. Use `core.bot` instead.
318
+ * The Discord client and its controllers. Access it through `core.bot`.
395
319
  */
396
- declare class Bot extends Plugin<BotEvents> {
320
+ declare class Bot extends TypedEventEmitter<BotEvents> implements Initializeable, HmrAware {
397
321
  readonly botToken: string;
398
322
  /** @internal */
399
323
  readonly logger: Logger;
@@ -401,39 +325,25 @@ declare class Bot extends Plugin<BotEvents> {
401
325
  private readonly _client;
402
326
  private readonly interactions?;
403
327
  private readonly events?;
404
- readonly commands?: CommandRegistry;
405
328
  private readonly emojiInjector;
329
+ readonly commands?: CommandRegistry;
406
330
  readonly emojis: InjectedEmojiMap;
407
331
  readonly mentions: InjectedMentionMap;
408
- /** @internal For use in dev mode */
332
+ /** @internal */
409
333
  onHmr(event: HmrUpdateEvent): Promise<void>;
410
334
  /** @internal */
411
335
  constructor(core: Core);
412
- /**
413
- * Initializes Discord client and all controllers
414
- * @internal
415
- */
336
+ private registerShutdownTasks;
337
+ private stopAccepting;
338
+ private drain;
339
+ /** @internal */
416
340
  init(): Promise<void>;
417
- /**
418
- * Stops the bot and cleans up connections
419
- * @internal
420
- */
341
+ /** @internal */
421
342
  stop(): Promise<void>;
422
- /**
423
- * Logs the bot into Discord using the configured token
424
- */
425
343
  private login;
426
- /**
427
- * Logs out and destroys the Discord client connection
428
- */
429
344
  private logout;
430
345
  get client(): Client;
431
- /**
432
- * Emits a Discord event with its argument tuple. The overloads enforce the key/args correlation
433
- * at compile time only; at runtime this forwards straight to the underlying EventEmitter.
434
- *
435
- * @internal
436
- */
346
+ /** @internal */
437
347
  emit<TKey extends keyof ClientEvents>(event: 'any:event', name: TKey, ...args: ClientEvents[TKey]): boolean;
438
348
  /** @internal */
439
349
  emit<TEventKey extends keyof BotEvents>(event: TEventKey, ...args: BotEvents[TEventKey]): boolean;
@@ -2138,10 +2048,8 @@ declare function WebhookUrl(envKey: string): <HandlerCtor extends Constructor<We
2138
2048
  //#endregion
2139
2049
  //#region src/Seedcord.d.ts
2140
2050
  /**
2141
- * Main Seedcord bot framework class
2142
- *
2143
- * Primary entry point for creating Discord bots with Seedcord.
2144
- * Manages component lifecycle and provides plugin support.
2051
+ * The gateway bot host. Opens a discord.js gateway session, discovers handlers, and runs
2052
+ * coordinated startup and shutdown. Attach plugins with `attach()`.
2145
2053
  */
2146
2054
  declare class Seedcord extends Pluggable implements Core {
2147
2055
  readonly config: GatewayConfig;
@@ -2151,8 +2059,7 @@ declare class Seedcord extends Pluggable implements Core {
2151
2059
  readonly augmentTarget = "@seedcord/gateway";
2152
2060
  /** @internal */
2153
2061
  readonly version: string;
2154
- private static isInstantiated;
2155
- private readonly healthCheck;
2062
+ private readonly healthCheck?;
2156
2063
  private readonly hmrManager;
2157
2064
  /** @see {@link CoordinatedShutdown} */
2158
2065
  readonly shutdown: CoordinatedShutdown;
@@ -2165,20 +2072,19 @@ declare class Seedcord extends Pluggable implements Core {
2165
2072
  /** @see {@link IRateLimiter} */
2166
2073
  readonly rateLimiter: IRateLimiter;
2167
2074
  /**
2168
- * Creates a new Seedcord instance
2169
- *
2170
2075
  * @param config - Bot configuration including paths and Discord client options
2171
2076
  * @throws A **SeedcordError** When attempting to create multiple instances (singleton)
2172
2077
  */
2173
2078
  constructor(config: GatewayConfig);
2174
2079
  /** The bot's discord username, populated after login. */
2175
2080
  get username(): string | undefined;
2176
- private static reset;
2081
+ protected pluginCapabilities(): PluginCapabilities;
2082
+ protected static reset(): void;
2177
2083
  private registerStartupTasks;
2178
2084
  /**
2179
2085
  * Starts the bot and runs all initialization tasks
2180
2086
  *
2181
- * @returns This Seedcord instance when fully initialized
2087
+ * @returns This Seedcord instance when initialized
2182
2088
  */
2183
2089
  start(): Promise<this>;
2184
2090
  private registerHmrAwareModules;
@@ -2188,5 +2094,5 @@ declare class Seedcord extends Pluggable implements Core {
2188
2094
  /** Package version */
2189
2095
  declare const version: string;
2190
2096
  //#endregion
2191
- export { ArraySource, AssignRoleNoticeOverrides, AutocompleteHandler, type BotEvents, ButtonHandler, type CheckPermissionOptions, CommandMentions, type ConfirmOptions, ContextMenuHandler, type Core, CursorSource, type DefaultConfirmOptions, Emojis, type EventGateContext, EventHandler, EventMiddleware, type EventSpec, type EventsConfig, type FaultSource, FetchUserOptions, type GateContext, Gated, type GatewayBotConfig, type GatewayConfig, HasPermsToAssignOptions, IgnoreBots, type Initializeable, type InjectedEmojiMap, type InjectedMentionMap, type InteractionGateContext, InteractionHandler, InteractionMiddleware, Middleware, type MiddlewareOptions, MiddlewareType, ModalHandler, Nsfw, Paginator, type PaginatorControls, type PermissionErrorNoticeOverrides, Pluggable, Plugin, type PluginArgs, type PluginCtor, RegisterEvent, type RegisterEventOptions, RepliableHandler, type Repliables, Seedcord, SelectMenuHandler, ShutdownPhase, SlashHandler, type SlashOptions, StartupPhase, Subscribe, type SubscribeOptions, Subscriber, type SubscriptionData, type SubscriptionKey, type Subscriptions, type ValidEventTypes, type ValidInteractionTypes, type ValidNonInteractionKeys, type WebhookFile, WebhookLog, type WebhookReport, WebhookUrl, checkBotPermissions, checkPermissions, fetchGuildMember, fetchManyGuildMembers, fetchManyUsers, fetchRole, fetchText, fetchUser, getBotRole, getConfirmation, hasPermsToAssign, updateMemberRoles, version };
2097
+ export { ArraySource, AssignRoleNoticeOverrides, AutocompleteHandler, type BotEvents, ButtonHandler, type CheckPermissionOptions, CommandMentions, type ConfirmOptions, ContextMenuHandler, type Core, CursorSource, type DefaultConfirmOptions, Emojis, type EventGateContext, EventHandler, EventMiddleware, type EventSpec, type EventsConfig, type FaultSource, FetchUserOptions, type GateContext, Gated, type GatewayBotConfig, type GatewayConfig, HasPermsToAssignOptions, IgnoreBots, type InjectedEmojiMap, type InjectedMentionMap, type InteractionGateContext, InteractionHandler, InteractionMiddleware, Middleware, type MiddlewareOptions, MiddlewareType, ModalHandler, Nsfw, Paginator, type PaginatorControls, type PermissionErrorNoticeOverrides, RegisterEvent, type RegisterEventOptions, RepliableHandler, type Repliables, Seedcord, SelectMenuHandler, SlashHandler, type SlashOptions, Subscribe, type SubscribeOptions, Subscriber, type SubscriptionData, type SubscriptionKey, type Subscriptions, type ValidEventTypes, type ValidInteractionTypes, type ValidNonInteractionKeys, type WebhookFile, WebhookLog, type WebhookReport, WebhookUrl, checkBotPermissions, checkPermissions, fetchGuildMember, fetchManyGuildMembers, fetchManyUsers, fetchRole, fetchText, fetchUser, getBotRole, getConfirmation, hasPermsToAssign, updateMemberRoles, version };
2192
2098
  //# sourceMappingURL=index.d.mts.map