@wolfstar/http-framework 2.3.1 → 3.1.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2022 Wolfstar Project
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -82,6 +82,59 @@ interface Args {
82
82
  }
83
83
  ```
84
84
 
85
+ ### Registering commands without decorators
86
+
87
+ If you don't want to rely on TS decorators (for example, when writing plain JavaScript, or [`@sapphire/framework`]-style
88
+ codebases), you can instead override the `registerApplicationCommands` method, which receives a per-command registry
89
+ with the same capabilities as the decorators above:
90
+
91
+ ```typescript
92
+ import { Command } from '@wolfstar/http-framework';
93
+
94
+ export class UserCommand extends Command {
95
+ registerApplicationCommands(registry) {
96
+ registry.registerChatInputCommand((builder) =>
97
+ builder //
98
+ .setName('ping')
99
+ .setDescription('Runs a network connection test with me')
100
+ );
101
+ }
102
+
103
+ chatInputRun(interaction) {
104
+ return interaction.sendMessage({ content: 'Pong!' });
105
+ }
106
+ }
107
+ ```
108
+
109
+ Subcommands, subcommand groups, context menu commands, and guild restriction are all available on the registry:
110
+
111
+ ```typescript
112
+ import { Command } from '@wolfstar/http-framework';
113
+
114
+ export class UserCommand extends Command {
115
+ registerApplicationCommands(registry) {
116
+ registry
117
+ .registerChatInputCommand((builder) => builder.setName('math').setDescription('Does some maths.'))
118
+ .registerSubcommand((builder) => buildSubcommandBuilders(builder, 'add', 'Adds the first number to the second number'), 'add')
119
+ .registerSubcommand(
120
+ (builder) => buildSubcommandBuilders(builder, 'subtract', 'Subtracts the second number from the first number'),
121
+ 'subtract'
122
+ );
123
+ }
124
+
125
+ add(interaction, { first, second }) {
126
+ return interaction.sendMessage({ content: `The result is: ${first + second}` });
127
+ }
128
+
129
+ subtract(interaction, { first, second }) {
130
+ return interaction.sendMessage({ content: `The result is: ${first - second}` });
131
+ }
132
+ }
133
+ ```
134
+
135
+ > **Note**: this is an alternative to the decorators, not a replacement — both approaches share the same underlying
136
+ > registry and can be mixed across different commands in the same project.
137
+
85
138
  ### Client
86
139
 
87
140
  The `Client` class contains the HTTP server, powered by [`node:http`], it also registers a handler that processes whether or not the HTTP request comes from Discord and processes the information accordingly, handling the heavyweight in the background.
@@ -142,3 +195,4 @@ await applicationCommandRegistry.pushGuildRestrictedCommands();
142
195
  [`node:http`]: https://nodejs.org/api/http.html
143
196
  [`@discordjs/rest`]: https://www.npmjs.com/package/@discordjs/rest
144
197
  [`@sapphire/pieces`]: https://www.npmjs.com/package/@sapphire/pieces
198
+ [`@sapphire/framework`]: https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/
@@ -2,7 +2,7 @@ import { AliasPiece, AliasPieceOptions, AliasStore, Container, LoaderError, Load
2
2
  import { DiscordAPIError, HTTPError, REST, RESTOptions, RawFile, RequestData } from "@discordjs/rest";
3
3
  import { Awaitable, NonNullObject } from "@sapphire/utilities";
4
4
  import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter";
5
- import { APIApplicationCommandAutocompleteInteraction, APIApplicationCommandAutocompleteResponse, APIApplicationCommandInteraction, APIApplicationCommandInteractionDataBasicOption, APIApplicationCommandInteractionDataOption, APIApplicationCommandInteractionDataSubcommandGroupOption, APIApplicationCommandInteractionDataSubcommandOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandSubcommandOption, APIAttachment, APIBaseInteraction, APIChannel, APIChatInputApplicationCommandInteraction, APIChatInputApplicationCommandInteractionData, APIContextMenuInteractionData, APIGuild, APIInteraction, APIInteractionDataResolved, APIInteractionDataResolvedChannel, APIInteractionDataResolvedGuildMember, APIInteractionResponseChannelMessageWithSource, APIInteractionResponseDeferredChannelMessageWithSource, APIInteractionResponseDeferredMessageUpdate, APIInteractionResponseUpdateMessage, APIMessage, APIMessageApplicationCommandInteraction, APIMessageApplicationCommandInteractionData, APIMessageChannelSelectInteractionData, APIMessageComponentButtonInteraction, APIMessageComponentInteraction, APIMessageComponentSelectMenuInteraction, APIMessageMentionableSelectInteractionData, APIMessageRoleSelectInteractionData, APIMessageStringSelectInteractionData, APIMessageUserSelectInteractionData, APIModalInteractionResponse, APIModalSubmitInteraction, APIPingInteraction, APIPrimaryEntryPointCommandInteraction, APIRole, APIUser, APIUserApplicationCommandInteraction, APIUserApplicationCommandInteractionData, ApplicationCommandOptionType, InteractionType, RESTPatchAPIInteractionOriginalResponseJSONBody, RESTPatchAPIInteractionOriginalResponseResult, RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, RESTPostAPIInteractionFollowupJSONBody, RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody, RESTPutAPIApplicationCommandsResult, RESTPutAPIApplicationGuildCommandsResult, Snowflake } from "discord-api-types/v10";
5
+ import { APIApplicationCommandAutocompleteInteraction, APIApplicationCommandAutocompleteResponse, APIApplicationCommandInteraction, APIApplicationCommandInteractionDataBasicOption, APIApplicationCommandInteractionDataOption, APIApplicationCommandInteractionDataSubcommandGroupOption, APIApplicationCommandInteractionDataSubcommandOption, APIApplicationCommandSubcommandGroupOption, APIApplicationCommandSubcommandOption, APIAttachment, APIBaseInteraction, APIChannel, APIChatInputApplicationCommandInteraction, APIChatInputApplicationCommandInteractionData, APIContextMenuInteractionData, APIGuild, APIInteraction, APIInteractionDataResolved, APIInteractionDataResolvedChannel, APIInteractionDataResolvedGuildMember, APIInteractionResponseChannelMessageWithSource, APIInteractionResponseDeferredChannelMessageWithSource, APIInteractionResponseDeferredMessageUpdate, APIInteractionResponseUpdateMessage, APIMessage, APIMessageApplicationCommandInteraction, APIMessageApplicationCommandInteractionData, APIMessageChannelSelectInteractionData, APIMessageComponentButtonInteraction, APIMessageComponentInteraction, APIMessageComponentSelectMenuInteraction, APIMessageMentionableSelectInteractionData, APIMessageRoleSelectInteractionData, APIMessageStringSelectInteractionData, APIMessageUserSelectInteractionData, APIModalInteractionResponse, APIModalSubmitInteraction, APIPingInteraction, APIPrimaryEntryPointCommandInteraction, APIRole, APIUser, APIUserApplicationCommandInteraction, APIUserApplicationCommandInteractionData, ApplicationCommandOptionType, ApplicationCommandType, InteractionType, RESTPatchAPIInteractionOriginalResponseJSONBody, RESTPatchAPIInteractionOriginalResponseResult, RESTPostAPIApplicationCommandsJSONBody, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, RESTPostAPIInteractionFollowupJSONBody, RESTPostAPIPrimaryEntryPointApplicationCommandJSONBody, RESTPutAPIApplicationCommandsResult, RESTPutAPIApplicationGuildCommandsResult, Snowflake } from "discord-api-types/v10";
6
6
  import { IncomingMessage, Server, ServerOptions, ServerResponse } from "node:http";
7
7
  import { Result } from "@sapphire/result";
8
8
  import { Collection } from "@discordjs/collection";
@@ -665,6 +665,93 @@ declare namespace ApplicationCommandRegistry {
665
665
  }
666
666
  declare const applicationCommandRegistry: ApplicationCommandRegistry;
667
667
  //#endregion
668
+ //#region src/lib/interactions/shared/CommandRegistry.d.ts
669
+ /**
670
+ * A per-command registry passed to {@linkcode Command.registerApplicationCommands}, allowing commands to be
671
+ * registered imperatively, without relying on decorators.
672
+ *
673
+ * @remarks This is the decorator-free equivalent of {@link RegisterCommand}, {@link RegisterSubcommand},
674
+ * {@link RegisterSubcommandGroup}, {@link RegisterMessageCommand}, {@link RegisterUserCommand}, and
675
+ * {@link RestrictGuildIds}; both approaches can be used interchangeably as they share the same underlying
676
+ * {@linkcode ApplicationCommandRegistryEntry}.
677
+ * @since 3.1.0
678
+ */
679
+ declare class CommandRegistry<Options extends Command.Options = Command.Options> {
680
+ #private;
681
+ constructor(target: typeof Command<Options>);
682
+ /**
683
+ * Registers the chat input (slash) command for this command.
684
+ *
685
+ * @since 3.1.0
686
+ * @param data - The command data.
687
+ * @returns This registry, for chaining.
688
+ * @example
689
+ * ```typescript
690
+ * public override registerApplicationCommands(registry: Command.Registry) {
691
+ * registry.registerChatInputCommand((builder) =>
692
+ * builder.setName('ping').setDescription('A simple ping pong command')
693
+ * );
694
+ * }
695
+ * ```
696
+ */
697
+ registerChatInputCommand(data: ChatInputCommandResolver.CommandData): this;
698
+ /**
699
+ * Registers a subcommand for the chat input command of this command.
700
+ *
701
+ * @since 3.1.0
702
+ * @param data - The subcommand data.
703
+ * @param method - The name of the method that handles this subcommand.
704
+ * @param groupName - The name of the subcommand group this subcommand belongs to, if any.
705
+ * @returns This registry, for chaining.
706
+ */
707
+ registerSubcommand(data: ChatInputCommandResolver.SubcommandData, method: string, groupName?: string | null): this;
708
+ /**
709
+ * Registers a subcommand group for the chat input command of this command.
710
+ *
711
+ * @since 3.1.0
712
+ * @param data - The subcommand group data.
713
+ * @param method - The name of the method that handles this subcommand group, if any.
714
+ * @returns This registry, for chaining.
715
+ */
716
+ registerSubcommandGroup(data: ChatInputCommandResolver.SubcommandGroupData, method?: string | null): this;
717
+ /**
718
+ * Registers a context menu command for this command.
719
+ *
720
+ * @since 3.1.0
721
+ * @param data - The command data.
722
+ * @param type - The type of context menu command to register.
723
+ * @param method - The name of the method that handles this context menu command, if any.
724
+ * @returns This registry, for chaining.
725
+ */
726
+ registerContextMenuCommand(data: ContextMenuCommandResolver.CommandData, type: ApplicationCommandType.Message | ApplicationCommandType.User, method?: string | null): this;
727
+ /**
728
+ * Registers a "Message" context menu command for this command.
729
+ *
730
+ * @since 3.1.0
731
+ * @param data - The command data.
732
+ * @param method - The name of the method that handles this context menu command, if any.
733
+ * @returns This registry, for chaining.
734
+ */
735
+ registerMessageCommand(data: ContextMenuCommandResolver.CommandData, method?: string | null): this;
736
+ /**
737
+ * Registers a "User" context menu command for this command.
738
+ *
739
+ * @since 3.1.0
740
+ * @param data - The command data.
741
+ * @param method - The name of the method that handles this context menu command, if any.
742
+ * @returns This registry, for chaining.
743
+ */
744
+ registerUserCommand(data: ContextMenuCommandResolver.CommandData, method?: string | null): this;
745
+ /**
746
+ * Restricts this command to the given guild IDs, so it is only registered there instead of globally.
747
+ *
748
+ * @since 3.1.0
749
+ * @param guildIds - The guild IDs to restrict this command to.
750
+ * @returns This registry, for chaining.
751
+ */
752
+ setGuildIds(guildIds: readonly string[]): this;
753
+ }
754
+ //#endregion
668
755
  //#region src/lib/interactions/utils/util-types.d.ts
669
756
  type DiscordResult<T> = Result<T, DiscordError>;
670
757
  type AsyncDiscordResult<T> = Promise<DiscordResult<T>>;
@@ -1517,6 +1604,36 @@ declare abstract class Command<Options extends Command.Options = Command.Options
1517
1604
  * @returns The registry for this command, or `null` if it is not registered.
1518
1605
  */
1519
1606
  get registry(): ApplicationCommandRegistryEntry | null;
1607
+ /**
1608
+ * Registers this command's application commands imperatively, without relying on decorators.
1609
+ *
1610
+ * @remarks This is invoked once, synchronously, from the base {@linkcode Command} constructor, right before this
1611
+ * command's router is built, and therefore before any subclass field initializers or subclass constructor body have
1612
+ * run. Because of this it must be declared as a method (not a class-field arrow function, which would not yet be
1613
+ * assigned at this point and would be silently skipped) and it must not read subclass instance state, which is still
1614
+ * uninitialized; it should register commands using only the provided `registry`. This matches the static, class-level
1615
+ * nature of the decorators: it is the decorator-free equivalent of {@link RegisterCommand} and its siblings, and a
1616
+ * command should use either this method or the decorators, not both.
1617
+ * @since 3.1.0
1618
+ * @param registry - The registry to register this command's application commands with.
1619
+ * @example
1620
+ * ```typescript
1621
+ * import { Command } from '@wolfstar/http-framework';
1622
+ *
1623
+ * export class UserCommand extends Command {
1624
+ * public override registerApplicationCommands(registry: Command.Registry) {
1625
+ * registry.registerChatInputCommand((builder) =>
1626
+ * builder.setName('ping').setDescription('Runs a network connection test with me')
1627
+ * );
1628
+ * }
1629
+ *
1630
+ * public override chatInputRun(interaction: Command.ChatInputInteraction) {
1631
+ * return interaction.reply({ content: 'Pong!' });
1632
+ * }
1633
+ * }
1634
+ * ```
1635
+ */
1636
+ registerApplicationCommands?(registry: Command.Registry): unknown;
1520
1637
  /**
1521
1638
  * Responds to the chat input command for this command
1522
1639
  *
@@ -1543,6 +1660,7 @@ declare namespace Command {
1543
1660
  type ApplicationCommandInteraction = Interactions.ApplicationCommand;
1544
1661
  type Interaction = ChatInputInteraction | AutocompleteInteraction | UserInteraction | MessageInteraction;
1545
1662
  type InteractionData = Interaction['data'];
1663
+ type Registry = CommandRegistry;
1546
1664
  /** @deprecated Use {@linkcode LoaderContext} instead. */
1547
1665
  type Context = LoaderContext;
1548
1666
  type LoaderContext = Piece$1.LoaderContext<'commands'>;
@@ -1573,6 +1691,15 @@ declare namespace InteractionHandler {
1573
1691
  type Options = Piece$1.Options;
1574
1692
  }
1575
1693
  //#endregion
1694
+ //#region src/lib/types/Enums.d.ts
1695
+ declare enum PluginHook {
1696
+ PreGenericsInitialization = "preGenericsInitialization",
1697
+ PreInitialization = "preInitialization",
1698
+ PostInitialization = "postInitialization",
1699
+ PreLoad = "preLoad",
1700
+ PostListen = "postListen"
1701
+ }
1702
+ //#endregion
1576
1703
  //#region src/lib/ClientEvents.d.ts
1577
1704
  interface ClientEventCommandContext {
1578
1705
  command: Command;
@@ -1591,6 +1718,19 @@ interface ClientEventInteractionHandlerContext {
1591
1718
  }
1592
1719
  interface ClientEvents {
1593
1720
  error: [error: unknown];
1721
+ /**
1722
+ * Emitted after a plugin hook runs, providing the hook's {@link PluginHook} and the plugin's name
1723
+ * (or `undefined` when the registering plugin did not provide one).
1724
+ *
1725
+ * @remarks
1726
+ * The `PreGenericsInitialization`, `PreInitialization`, and `PostInitialization` hooks run
1727
+ * synchronously inside the `Client` constructor, so their emissions fire before `new Client()`
1728
+ * returns. A listener attached afterwards cannot observe them (not even one added by a subclass,
1729
+ * whose constructor body only runs after `super()` has already executed those hooks), so only the
1730
+ * `PreLoad` (during `Client#load`) and `PostListen` (during `Client#listen`) emissions are
1731
+ * observable. To react to the constructor-phase hooks, use the plugin hooks themselves.
1732
+ */
1733
+ pluginLoaded: [hook: PluginHook, name: string | undefined];
1594
1734
  commandNameMissing: [interaction: APIApplicationCommandAutocompleteInteraction, response: ServerResponse];
1595
1735
  commandNameUnknown: [interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction, response: ServerResponse];
1596
1736
  commandMethodUnknown: [context: ClientEventCommandContext];
@@ -1620,6 +1760,57 @@ interface IdParserRead {
1620
1760
  content: unknown;
1621
1761
  }
1622
1762
  //#endregion
1763
+ //#region src/lib/plugins/symbols.d.ts
1764
+ declare const preGenericsInitialization: unique symbol;
1765
+ declare const preInitialization: unique symbol;
1766
+ declare const postInitialization: unique symbol;
1767
+ declare const preLoad: unique symbol;
1768
+ declare const postListen: unique symbol;
1769
+ //#endregion
1770
+ //#region src/lib/plugins/Plugin.d.ts
1771
+ /**
1772
+ * The base class for all plugins. Plugins hook into the {@link Client}'s lifecycle by defining static
1773
+ * methods keyed by the plugin symbols. Use {@link PluginManager.use} (via `Client.use`) to register a plugin.
1774
+ *
1775
+ * @since 2.4.0
1776
+ */
1777
+ declare abstract class Plugin {
1778
+ static [preGenericsInitialization]?: (this: Client, options: ClientOptions) => void;
1779
+ static [preInitialization]?: (this: Client, options: ClientOptions) => void;
1780
+ static [postInitialization]?: (this: Client, options: ClientOptions) => void;
1781
+ static [preLoad]?: (this: Client, options: ClientOptions) => Awaitable<void>;
1782
+ static [postListen]?: (this: Client, options: ClientOptions) => Awaitable<void>;
1783
+ }
1784
+ //#endregion
1785
+ //#region src/lib/plugins/PluginManager.d.ts
1786
+ type AsyncPluginHooks = PluginHook.PreLoad | PluginHook.PostListen;
1787
+ interface HttpFrameworkPluginAsyncHook {
1788
+ (this: Client, options: ClientOptions): Awaitable<unknown>;
1789
+ }
1790
+ type SyncPluginHooks = Exclude<PluginHook, AsyncPluginHooks>;
1791
+ interface HttpFrameworkPluginHook {
1792
+ (this: Client, options: ClientOptions): unknown;
1793
+ }
1794
+ interface HttpFrameworkPluginHookEntry<T = HttpFrameworkPluginHook | HttpFrameworkPluginAsyncHook> {
1795
+ hook: T;
1796
+ type: PluginHook;
1797
+ name?: string;
1798
+ }
1799
+ declare class PluginManager {
1800
+ readonly registry: Set<HttpFrameworkPluginHookEntry<HttpFrameworkPluginHook | HttpFrameworkPluginAsyncHook>>;
1801
+ registerHook(hook: HttpFrameworkPluginHook, type: SyncPluginHooks, name?: string): this;
1802
+ registerHook(hook: HttpFrameworkPluginAsyncHook, type: AsyncPluginHooks, name?: string): this;
1803
+ registerPreGenericsInitializationHook(hook: HttpFrameworkPluginHook, name?: string): this;
1804
+ registerPreInitializationHook(hook: HttpFrameworkPluginHook, name?: string): this;
1805
+ registerPostInitializationHook(hook: HttpFrameworkPluginHook, name?: string): this;
1806
+ registerPreLoadHook(hook: HttpFrameworkPluginAsyncHook, name?: string): this;
1807
+ registerPostListenHook(hook: HttpFrameworkPluginAsyncHook, name?: string): this;
1808
+ use(plugin: typeof Plugin): this;
1809
+ values(): Generator<HttpFrameworkPluginHookEntry, void, unknown>;
1810
+ values(hook: SyncPluginHooks): Generator<HttpFrameworkPluginHookEntry<HttpFrameworkPluginHook>, void, unknown>;
1811
+ values(hook: AsyncPluginHooks): Generator<HttpFrameworkPluginHookEntry<HttpFrameworkPluginAsyncHook>, void, unknown>;
1812
+ }
1813
+ //#endregion
1623
1814
  //#region src/lib/structures/InteractionHandlerStore.d.ts
1624
1815
  declare class InteractionHandlerStore extends Store$1<InteractionHandler, 'interaction-handlers'> {
1625
1816
  constructor();
@@ -1667,9 +1858,23 @@ declare class Client extends AsyncEventEmitter<MappedClientEvents> {
1667
1858
  #private;
1668
1859
  server: Server;
1669
1860
  readonly id: string;
1861
+ readonly options: ClientOptions;
1670
1862
  readonly bodySizeLimit: number;
1671
1863
  readonly httpReplyOnError: boolean;
1672
1864
  constructor(options?: ClientOptions);
1865
+ /**
1866
+ * The plugin manager, holding every registered plugin hook.
1867
+ *
1868
+ * @since 2.4.0
1869
+ */
1870
+ static readonly plugins: PluginManager;
1871
+ /**
1872
+ * Registers a plugin onto the {@link Client}, applying all of its hooks.
1873
+ *
1874
+ * @since 2.4.0
1875
+ * @param plugin The plugin to register.
1876
+ */
1877
+ static use(plugin: typeof Plugin): typeof Client;
1673
1878
  /**
1674
1879
  * Gets the application command registry.
1675
1880
  *
@@ -2221,5 +2426,5 @@ declare class ListenerLoaderStrategy extends LoaderStrategy<Listener> {
2221
2426
  onUnload(_store: ListenerStore, piece: Listener): void;
2222
2427
  }
2223
2428
  //#endregion
2224
- export { type AbortError, type AddFiles, AliasPiece, type AliasPieceOptions, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, ArgumentTypes, type AsyncDiscordResult, AutocompleteInteraction$1 as AutocompleteInteraction, AutocompleteInteractionArguments, AutocompleteResponseData, AutocompleteResponseOptions, BaseCommandInteractionType, BaseInteraction, BaseInteractionType, ChatInputCommandInteraction, Client, ClientEventAutocompleteContext, ClientEventCommandContext, ClientEventInteractionHandlerContext, ClientEvents, ClientOptions, Command, CommandInteraction, CommandLoaderStrategy, CommandRouter, CommandStore, CommandStoreRouter, DeferResponseData, DeferResponseOptions, DeferUpdateResult, type DiscordError, type DiscordResult, ExtractedOptions, FollowupOptions, HttpCodes, IIdParser, IdParserRead, InGuild, Interaction$1 as Interaction, InteractionArguments, InteractionHandler, InteractionHandlerStore, Interactions, ListenOptions, Listener, ListenerLoaderStrategy, ListenerStore, LoadOptions, LoaderError, type LoaderPieceContext, MakeArguments, MappedClientEvents, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentInteractionType, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MessageResponseData, MessageResponseOptions, MissingExportsError, ModalResponseData, ModalResponseOptions, ModalSubmitInteraction, type NonPingInteraction, PartialMessage, Piece, type PieceContext, type PieceOptions, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RequestAuthPrefix, RestrictGuildIds, Store, type StoreOptions, StoreRegistry, type StoreRegistryEntries, StringIdParser, TransformedArguments, UpdateData, UpdateOptions, UpdateResponseOptions, UpdateResponseResult, UserContextMenuCommandInteraction, applicationCommandRegistry, container, extractTopLevelOptions, makeInteraction, restrictedGuildIdRegistry, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
2429
+ export { type AbortError, type AddFiles, AliasPiece, type AliasPieceOptions, AliasStore, ApplicationCommandRegistry, ApplicationCommandRegistryEntry, ArgumentTypes, type AsyncDiscordResult, AsyncPluginHooks, AutocompleteInteraction$1 as AutocompleteInteraction, AutocompleteInteractionArguments, AutocompleteResponseData, AutocompleteResponseOptions, BaseCommandInteractionType, BaseInteraction, BaseInteractionType, ChatInputCommandInteraction, Client, ClientEventAutocompleteContext, ClientEventCommandContext, ClientEventInteractionHandlerContext, ClientEvents, ClientOptions, Command, CommandInteraction, CommandLoaderStrategy, CommandRegistry, CommandRouter, CommandStore, CommandStoreRouter, DeferResponseData, DeferResponseOptions, DeferUpdateResult, type DiscordError, type DiscordResult, ExtractedOptions, FollowupOptions, HttpCodes, HttpFrameworkPluginAsyncHook, HttpFrameworkPluginHook, HttpFrameworkPluginHookEntry, IIdParser, IdParserRead, InGuild, Interaction$1 as Interaction, InteractionArguments, InteractionHandler, InteractionHandlerStore, Interactions, ListenOptions, Listener, ListenerLoaderStrategy, ListenerStore, LoadOptions, LoaderError, type LoaderPieceContext, MakeArguments, MappedClientEvents, Message, MessageComponentButtonInteraction, MessageComponentChannelSelectInteraction, MessageComponentInteraction, MessageComponentInteractionType, MessageComponentMentionableSelectInteraction, MessageComponentRoleSelectInteraction, MessageComponentStringSelectInteraction as MessageComponentSelectMenuInteraction, MessageComponentStringSelectInteraction, MessageComponentUserSelectInteraction, MessageContextMenuCommandInteraction, MessageResponseData, MessageResponseOptions, MissingExportsError, ModalResponseData, ModalResponseOptions, ModalSubmitInteraction, type NonPingInteraction, PartialMessage, Piece, type PieceContext, type PieceOptions, Plugin, PluginHook, PluginManager, RegisterCommand, RegisterMessageCommand, RegisterSubcommand, RegisterSubcommandGroup, RegisterUserCommand, RequestAuthPrefix, RestrictGuildIds, Store, type StoreOptions, StoreRegistry, type StoreRegistryEntries, StringIdParser, SyncPluginHooks, TransformedArguments, UpdateData, UpdateOptions, UpdateResponseOptions, UpdateResponseResult, UserContextMenuCommandInteraction, applicationCommandRegistry, container, extractTopLevelOptions, makeInteraction, postInitialization, postListen, preGenericsInitialization, preInitialization, preLoad, restrictedGuildIdRegistry, transformAutocompleteInteraction, transformInteraction, transformMessageInteraction, transformUserInteraction };
2225
2430
  //# sourceMappingURL=index.d.ts.map