oopscord.js 0.0.29 → 0.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 +674 -201
- package/README.md +212 -11
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/structures/Constants.d.ts +2 -2
- package/dist/structures/Constants.d.ts.map +1 -1
- package/dist/structures/Constants.js +1 -0
- package/dist/structures/Constants.js.map +1 -0
- package/dist/structures/DiscordApp.d.ts +28 -10
- package/dist/structures/DiscordApp.d.ts.map +1 -1
- package/dist/structures/DiscordApp.js +681 -295
- package/dist/structures/DiscordApp.js.map +1 -0
- package/dist/structures/Plugin.d.ts +68 -0
- package/dist/structures/Plugin.d.ts.map +1 -1
- package/dist/structures/Plugin.js +28 -1
- package/dist/structures/Plugin.js.map +1 -0
- package/dist/structures/PluginManager.d.ts +122 -0
- package/dist/structures/PluginManager.d.ts.map +1 -0
- package/dist/structures/PluginManager.js +371 -0
- package/dist/structures/PluginManager.js.map +1 -0
- package/dist/structures/components/BaseButton.d.ts +2 -5
- package/dist/structures/components/BaseButton.d.ts.map +1 -1
- package/dist/structures/components/BaseButton.js +9 -14
- package/dist/structures/components/BaseButton.js.map +1 -0
- package/dist/structures/components/BaseModal.d.ts +13 -21
- package/dist/structures/components/BaseModal.d.ts.map +1 -1
- package/dist/structures/components/BaseModal.js +86 -132
- package/dist/structures/components/BaseModal.js.map +1 -0
- package/dist/structures/components/BaseSelectMenu.d.ts +2 -5
- package/dist/structures/components/BaseSelectMenu.d.ts.map +1 -1
- package/dist/structures/components/BaseSelectMenu.js +21 -25
- package/dist/structures/components/BaseSelectMenu.js.map +1 -0
- package/dist/structures/components/Listener.d.ts +18 -0
- package/dist/structures/components/Listener.d.ts.map +1 -0
- package/dist/structures/components/Listener.js +22 -0
- package/dist/structures/components/Listener.js.map +1 -0
- package/dist/structures/components/index.d.ts +1 -0
- package/dist/structures/components/index.d.ts.map +1 -1
- package/dist/structures/components/index.js +2 -0
- package/dist/structures/components/index.js.map +1 -0
- package/dist/structures/decorators/CommandDecorator.d.ts +39 -38
- package/dist/structures/decorators/CommandDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/CommandDecorator.js +145 -250
- package/dist/structures/decorators/CommandDecorator.js.map +1 -0
- package/dist/structures/decorators/Constants.d.ts +12 -8
- package/dist/structures/decorators/Constants.d.ts.map +1 -1
- package/dist/structures/decorators/Constants.js +13 -8
- package/dist/structures/decorators/Constants.js.map +1 -0
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts +11 -19
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/DiscordModuleDecorator.js +12 -54
- package/dist/structures/decorators/DiscordModuleDecorator.js.map +1 -0
- package/dist/structures/decorators/EventDecorator.d.ts +45 -0
- package/dist/structures/decorators/EventDecorator.d.ts.map +1 -0
- package/dist/structures/decorators/EventDecorator.js +52 -0
- package/dist/structures/decorators/EventDecorator.js.map +1 -0
- package/dist/structures/decorators/ExecutionDecorator.d.ts +19 -0
- package/dist/structures/decorators/ExecutionDecorator.d.ts.map +1 -0
- package/dist/structures/decorators/ExecutionDecorator.js +23 -0
- package/dist/structures/decorators/ExecutionDecorator.js.map +1 -0
- package/dist/structures/decorators/InjectionMetadata.d.ts +35 -0
- package/dist/structures/decorators/InjectionMetadata.d.ts.map +1 -0
- package/dist/structures/decorators/InjectionMetadata.js +34 -0
- package/dist/structures/decorators/InjectionMetadata.js.map +1 -0
- package/dist/structures/decorators/InteractionHandlerDecorator.d.ts +17 -2
- package/dist/structures/decorators/InteractionHandlerDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/InteractionHandlerDecorator.js +48 -7
- package/dist/structures/decorators/InteractionHandlerDecorator.js.map +1 -0
- package/dist/structures/decorators/MessageComponentDecorator.d.ts +25 -40
- package/dist/structures/decorators/MessageComponentDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/MessageComponentDecorator.js +66 -78
- package/dist/structures/decorators/MessageComponentDecorator.js.map +1 -0
- package/dist/structures/decorators/Metadata.d.ts +16 -0
- package/dist/structures/decorators/Metadata.d.ts.map +1 -0
- package/dist/structures/decorators/Metadata.js +50 -0
- package/dist/structures/decorators/Metadata.js.map +1 -0
- package/dist/structures/decorators/PluginDecorator.d.ts +41 -0
- package/dist/structures/decorators/PluginDecorator.d.ts.map +1 -0
- package/dist/structures/decorators/PluginDecorator.js +36 -0
- package/dist/structures/decorators/PluginDecorator.js.map +1 -0
- package/dist/structures/decorators/UseDecorator.d.ts +44 -0
- package/dist/structures/decorators/UseDecorator.d.ts.map +1 -0
- package/dist/structures/decorators/UseDecorator.js +49 -0
- package/dist/structures/decorators/UseDecorator.js.map +1 -0
- package/dist/structures/decorators/index.d.ts +4 -0
- package/dist/structures/decorators/index.d.ts.map +1 -1
- package/dist/structures/decorators/index.js +5 -0
- package/dist/structures/decorators/index.js.map +1 -0
- package/dist/structures/index.d.ts +3 -1
- package/dist/structures/index.d.ts.map +1 -1
- package/dist/structures/index.js +5 -1
- package/dist/structures/index.js.map +1 -0
- package/dist/utils/Util.d.ts +2 -0
- package/dist/utils/Util.d.ts.map +1 -1
- package/dist/utils/Util.js +23 -8
- package/dist/utils/Util.js.map +1 -0
- package/dist/utils/cache.d.ts +4 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +17 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/customId.d.ts +12 -0
- package/dist/utils/customId.d.ts.map +1 -0
- package/dist/utils/customId.js +49 -0
- package/dist/utils/customId.js.map +1 -0
- package/package.json +35 -9
- package/bun.lock +0 -264
package/README.md
CHANGED
|
@@ -1,11 +1,212 @@
|
|
|
1
|
-
# oopscord.js
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
# oopscord.js
|
|
2
|
+
|
|
3
|
+
A TypeScript framework for Discord commands, events, buttons, select menus, and modals using standard decorators and property injection.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Requires Node.js 20.19 or newer and discord.js 14.28.1 or newer within major version 14. Upgrading from 0.0.x? See [MIGRATING.md](MIGRATING.md).
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install oopscord.js discord.js huruhuru@0.0.2
|
|
11
|
+
npm install --save-dev typescript @types/node
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Use TypeScript 5.2 or newer with standard decorators in your application's `tsconfig.json`. Remove `experimentalDecorators` and `emitDecoratorMetadata` from existing configurations:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"compilerOptions": {
|
|
19
|
+
"target": "ES2022",
|
|
20
|
+
"module": "Node16",
|
|
21
|
+
"moduleResolution": "Node16",
|
|
22
|
+
"lib": ["ES2022", "ESNext.Decorators"],
|
|
23
|
+
"strict": true,
|
|
24
|
+
"outDir": "dist"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
For this CommonJS configuration, set your application's package `type` to `commonjs`. The library also supports importing its public exports from ESM.
|
|
30
|
+
|
|
31
|
+
## Your first bot
|
|
32
|
+
|
|
33
|
+
Create `app.ts`, supply `DISCORD_TOKEN` through the environment, compile with `npx tsc`, and run `node dist/app.js`.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { ChatInputCommandInteraction, GatewayIntentBits } from "discord.js";
|
|
37
|
+
import { CommandContext } from "huruhuru";
|
|
38
|
+
import { BaseDiscordModule, Command, CommandModule, Context, DiscordApp, DiscordModule, Run } from "oopscord.js";
|
|
39
|
+
|
|
40
|
+
@Command({ name: "ping", description: "Check whether the bot is online" })
|
|
41
|
+
class Ping {
|
|
42
|
+
@Context
|
|
43
|
+
ctx!: CommandContext<ChatInputCommandInteraction>;
|
|
44
|
+
|
|
45
|
+
@Run
|
|
46
|
+
async run() {
|
|
47
|
+
await this.ctx.reply("Pong!");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@CommandModule({ commands: [Ping] })
|
|
52
|
+
class Commands {}
|
|
53
|
+
|
|
54
|
+
@DiscordModule({
|
|
55
|
+
token: process.env.DISCORD_TOKEN!,
|
|
56
|
+
intents: [GatewayIntentBits.Guilds],
|
|
57
|
+
imports: [Commands],
|
|
58
|
+
test: { enable: true, guild: process.env.TEST_GUILD_ID! }
|
|
59
|
+
})
|
|
60
|
+
class AppModule extends BaseDiscordModule {}
|
|
61
|
+
|
|
62
|
+
const app = DiscordApp.create(AppModule);
|
|
63
|
+
process.once("SIGINT", () => { void app.stop().catch(console.error); });
|
|
64
|
+
void app.login().catch(console.error);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Set `TEST_GUILD_ID` to a dedicated development guild. Disable test mode to deploy global commands. A version that validates environment variables and handles both shutdown signals is in [examples/App.ts](examples/App.ts); replace `../src` with `oopscord.js` when copying it into a consumer project, then call `bootstrap()`.
|
|
68
|
+
|
|
69
|
+
## Commands and deployment
|
|
70
|
+
|
|
71
|
+
Use `@Private(guildId)` for guild commands, `@ContextMenu({ name, type })` for user/message commands, and `@AddSubcommand` or `@AddSubcommandGroup` for command containers. Every registered executable handler requires `@Run`; containers with subcommands do not. Optional option injections return `null` when absent.
|
|
72
|
+
|
|
73
|
+
Handlers are constructed without arguments, then the framework injects their decorated properties before calling `@Run` or `@Autocomplete`. Constructors and property initializers run before injection, so access injected values inside the handler methods.
|
|
74
|
+
|
|
75
|
+
Option decorators register the Discord option and inject its value together. The property name is the default option name; specify `name` to use another name:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
@Command({ name: "echo", description: "Repeat a message" })
|
|
79
|
+
class Echo {
|
|
80
|
+
@Interaction
|
|
81
|
+
interaction!: ChatInputCommandInteraction;
|
|
82
|
+
|
|
83
|
+
@StringOption({ description: "Message", required: true })
|
|
84
|
+
text!: string;
|
|
85
|
+
|
|
86
|
+
@Run
|
|
87
|
+
async run() {
|
|
88
|
+
await this.interaction.reply(this.text);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Import `Interaction` and `StringOption` from `oopscord.js` alongside the command decorators. `IntegerOption`, `NumberOption`, `BooleanOption`, `UserOption`, `ChannelOption`, `RoleOption`, `MentionableOption`, `AttachmentOption`, and the choice variants work the same way. Use nullable property types for optional options. Symbol and private fields require an explicit option `name`.
|
|
94
|
+
|
|
95
|
+
Move former constructor or method parameter injections to properties. Separate decorators such as `StringOptionInjection` have been removed. Decorated properties are inherited; decorating the same property in a subclass replaces its inherited injection and option definition. Static injections are rejected. The library provides the `Symbol.metadata` polyfill needed by supported Node versions.
|
|
96
|
+
|
|
97
|
+
`login()` deploys commands by default and rejects on deployment failure. To manage deployment separately:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
console.log(app.getCommandManifest()); // No login or REST request.
|
|
101
|
+
await app.login({ deployCommands: false });
|
|
102
|
+
await app.deployCommands();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Deployment replaces each target scope's complete command list. Test and private commands targeting the same guild are merged into one request; conflicting names/types are rejected. Removing a private guild from configuration does not clear that guild's existing commands automatically.
|
|
106
|
+
|
|
107
|
+
## huruhuru contexts and messages
|
|
108
|
+
|
|
109
|
+
`@Context` injects a new `huruhuru.CommandContext<ChatInputCommandInteraction>` into each slash command invocation, including subcommands. Its `reply`, `deferReply`, `editReply`, and `followUp` methods operate on the original interaction. After `deferReply()`, finish with `editReply()`. `@Interaction` can be used alongside `@Context` on another property.
|
|
110
|
+
|
|
111
|
+
Contexts are supported only for slash commands. During autocomplete, `@Context` receives `undefined`; declare that union on the property and use `@Interaction` for the autocomplete interaction. Buttons, select menus, modals, and context menus use `@Interaction` properties.
|
|
112
|
+
|
|
113
|
+
oopscord.js depends on `huruhuru` 0.0.2, currently published under its `dev` tag, and installs it for you. When your application imports from `huruhuru`, install that same version so npm shares one copy with the library. Import its message and pagination helpers directly from `huruhuru`:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { createSimpleContainer, paginate } from "huruhuru";
|
|
117
|
+
import { MessageFlags } from "discord.js";
|
|
118
|
+
|
|
119
|
+
await ctx.reply({
|
|
120
|
+
components: [createSimpleContainer("Hello!", [100, 150, 255])],
|
|
121
|
+
flags: MessageFlags.IsComponentsV2,
|
|
122
|
+
allowedMentions: { parse: [] }
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// In a separate command, or after deferring its reply:
|
|
126
|
+
await paginate(ctx, ["{{number}}. Commands", "{{number}}. Modals"], null, 1, 1, "{{page}}/{{pages}}");
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Pagination uses its own collector and does not need a registered button handler. Supply an `onError` callback for background errors. See [examples/Huruhuru.ts](examples/Huruhuru.ts) for two complete commands and their command module.
|
|
130
|
+
|
|
131
|
+
## Autocomplete and execution policies
|
|
132
|
+
|
|
133
|
+
Set `autocomplete: true` on an option property and decorate a method with `@Autocomplete("optionName")`. Return up to 25 `{ name, value }` choices; the framework awaits the method and responds. Both autocomplete and `@Run` use the injected properties through `this`.
|
|
134
|
+
|
|
135
|
+
`@Guard(predicate)` accepts an asynchronous predicate with `{ interaction, handler, parameters, logger }`. Returning false prevents construction and execution. Guards on command containers apply to their subcommands and autocomplete. `@Cooldown(milliseconds, "user" | "guild" | "global")` limits dispatch attempts per application instance; the default scope is `user`. Autocomplete does not consume cooldowns. Multi-process deployments need shared rate limiting through a guard or plugin.
|
|
136
|
+
|
|
137
|
+
## Components and modals
|
|
138
|
+
|
|
139
|
+
Import handlers through `@MessageComponentModule({ components: [...] })`. Extend `BaseButton`, `BaseSelectMenu`, or `BaseModal` to create builders. Getter and override methods return independent copies; arrays supplied to overrides replace the defaults.
|
|
140
|
+
|
|
141
|
+
Use `@CustomId("ticket:close:{ticketId}")` with `@CustomIdInjection("ticketId")` to route colon-separated component IDs and inject captured values. Build a concrete ID with `CloseTicket.override({ customId: "ticket:close:123" })`. Exact routes take precedence, and overlapping patterns fail at startup. See [examples/Features.ts](examples/Features.ts).
|
|
142
|
+
|
|
143
|
+
For modal labels, `ModalLabel.customId` identifies the outer label for overrides; the inner component's `customId` identifies a submitted field. Use `@TextInputFieldInjection`, `@SelectMenuFieldInjection`, or the corresponding upload/checkbox/radio injection decorator on instance properties. Registered submit handlers require `@Run`.
|
|
144
|
+
|
|
145
|
+
For a one-off prompt, `await MyModal.getInput(interaction, { time: 60_000 })` returns the invoking user's submitted fields and handles acknowledgement. Display, acknowledgement, and timeout errors reject. Prompt-only templates do not need registration or `@Run`.
|
|
146
|
+
|
|
147
|
+
## Events, plugins, and shutdown
|
|
148
|
+
|
|
149
|
+
Use `@EventHandler("eventName")` on a method and import listeners through `@EventModule({ listeners: [...] })`. Event methods in a module share one instance. The root module can have no event handlers.
|
|
150
|
+
|
|
151
|
+
Extend `Plugin` to hook into the application lifecycle. Available hooks are `onEnable`, `prefix`, `postfix`, `onError`, and `onDisable`. Hooks are awaited; returning false from `prefix` prevents execution. Plugins are enabled once on `initialize()`, `login()`, or the first interaction, before the client connects.
|
|
152
|
+
|
|
153
|
+
Register plugins through `DiscordApp.create(AppModule, { plugins: [...] })`, as instances or as classes. A class is constructed once with `(client, logger)`. A plain plugin observes the whole application.
|
|
154
|
+
|
|
155
|
+
Decorate a plugin with `@PluginModule({ imports, commands, components, listeners })` to let it own handlers like a module. The application registers everything it owns, plus the plugin's own `@EventHandler` methods. `prefix`, `postfix`, and `onError` then cover only the interactions and event failures of what the plugin owns; set `scope: "global"` to cover the whole application. A plugin is not a module, so it cannot be listed in `imports`, and the same plugin class cannot be registered twice.
|
|
156
|
+
|
|
157
|
+
Plugins can declare these members:
|
|
158
|
+
|
|
159
|
+
- `name` and `version`: `name` is unique and defaults to the class name (`plugin-N` for plain objects). Logs and errors from hooks name the plugin, and hook failures arrive in `onError` as a `PluginError` whose `cause` is the original error.
|
|
160
|
+
- `depends`: classes or names of plugins that must be enabled first. `@Use(Other)` on a plugin field declares the same dependency. Missing, circular, or self dependencies fail at startup. Plugins enable dependencies first, in the order given otherwise, and disable in reverse.
|
|
161
|
+
- `softDepends`: classes or names of plugins to enable first when they happen to be registered. Unlike `depends`, a missing one is not an error, and disabling or failing one does not disable this plugin, so check `plugins.isEnabled(Other)` before relying on it. A plugin listed in both `depends` and `softDepends` is a hard dependency. A soft dependency that would close a cycle is ignored with a warning.
|
|
162
|
+
- `timeout`: milliseconds a hook may take before failing with a `PluginError`. It overrides `DiscordApp.create(AppModule, { pluginTimeout })`; the default 0 means no limit. Keep `prefix` fast, since Discord expects a response within three seconds.
|
|
163
|
+
- `isolate`: when `onEnable` fails, disable only this plugin and its dependents instead of failing `initialize()`. `onDisable` still runs to release anything `onEnable` acquired.
|
|
164
|
+
|
|
165
|
+
Use `@Use(SomeClass)` on an instance field to inject a shared instance of a class, so classes can use what another class provides:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
@Command({ name: "ticket", description: "Open a ticket" })
|
|
169
|
+
class Ticket {
|
|
170
|
+
@Use(TicketStore) store!: TicketStore;
|
|
171
|
+
@Use(() => Support) support!: Support;
|
|
172
|
+
|
|
173
|
+
@Run
|
|
174
|
+
async run() { await this.support.open(await this.store.create()); }
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
- A registered plugin (of that class or a subclass) is injected as it is. Use a plugin for anything that needs a lifecycle.
|
|
179
|
+
- A support registered with `supports` is injected as it is. List classes, which are created once with `(client, logger)`, or instances you made, which can carry configuration: `@DiscordModule({ supports: [Mailer, new Database(url)] })`. A plugin can provide supports with `@PluginModule({ supports: [...] })`. They are available only while the plugin is enabled, and a plugin that uses one depends on the plugin that provides it. `@Use(Database)` also finds a registered subclass, so an abstract base class works as the key.
|
|
180
|
+
- Any other class needs no registration. One instance is created for the application, with `(client, logger)`, when the application is created, and everyone who uses it shares it.
|
|
181
|
+
- A support's own `@Use` fields are injected too, so supports may use each other. Registering the same support class twice, or a plugin in `supports`, fails startup.
|
|
182
|
+
- A `Plugin` subclass that is not registered fails startup instead of being created without a lifecycle.
|
|
183
|
+
- It works in interaction handlers, listeners, event modules, the root module, plugins, and the classes injected this way. The field type must accept the class type, and startup fails when a constructor throws.
|
|
184
|
+
- While a plugin that a handler uses, or that provides a support it uses, is not enabled, the handler answers "This feature is currently disabled." and a listener's event handlers do not run. Only direct uses count, not a plugin used by a support.
|
|
185
|
+
- On a plugin, `@Use(OtherPlugin)` also declares a dependency, as does using a support that another plugin provides. Plugin fields are set after every plugin is registered, so read them in hooks rather than in a constructor. Handlers are created per interaction, so their fields are always set when `@Run` runs.
|
|
186
|
+
- When two declarations refer to each other, pass an arrow function: a plugin that owns a handler through `@PluginModule` is declared after it, so the handler writes `@Use(() => Support)`.
|
|
187
|
+
|
|
188
|
+
`app.plugins`, also available as `context.plugins` in every hook, is a `PluginManager`:
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
app.plugins.get(Database); // the registered plugin by class, name, or instance
|
|
192
|
+
app.plugins.list(); // name, version, state, and dependencies, in dependency order
|
|
193
|
+
await app.plugins.disable(Support); // also disables dependents first; resolves with the names disabled
|
|
194
|
+
await app.plugins.enable(Support); // requires its dependencies to be enabled
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Disabling runs `onDisable` and takes the plugin out of service without a restart: its hooks and event handlers stop, interactions for handlers it owns are answered with "This feature is currently disabled.", and `getCommandManifest()` leaves its commands out. Call `deployCommands()` afterwards to remove them from Discord. Handlers that are already running finish normally. `enable` and `disable` initialize the application first, so do not call them from inside `onEnable`. See [examples/Features.ts](examples/Features.ts).
|
|
198
|
+
|
|
199
|
+
`await app.stop()` stops accepting events, waits for active handlers, disables plugins in reverse order, and destroys the client. Repeated calls share the same shutdown operation. Applications cannot restart after stopping.
|
|
200
|
+
|
|
201
|
+
`@DiscordModule({ disableCache: true, ... })` disables optional manager caches while preserving Discord.js's required caches and the bot's own guild member. Use `makeCache` instead when specifying custom limits; the two options cannot be combined.
|
|
202
|
+
|
|
203
|
+
## Development
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
npm ci
|
|
207
|
+
npm run typecheck
|
|
208
|
+
npm test
|
|
209
|
+
npm run test:package
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Sources are in `src/`, regression tests in `tests/`, and checked examples in `examples/`. `npm run build` generates `dist/`; do not edit generated files. CI checks Node 20, 22, and 24 on Linux and Windows. Package checks verify CommonJS/ESM imports and published file contents. Tests use mocked Discord connections and REST calls.
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
|
|
1
|
+
import { SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandUserOption } from "discord.js";
|
|
2
2
|
/** The type of all slash command options. */
|
|
3
|
-
export type SlashCommandOptions = SlashCommandAttachmentOption | SlashCommandBooleanOption |
|
|
3
|
+
export type SlashCommandOptions = SlashCommandAttachmentOption | SlashCommandBooleanOption | SlashCommandChannelOption | SlashCommandIntegerOption | SlashCommandMentionableOption | SlashCommandNumberOption | SlashCommandRoleOption | SlashCommandStringOption | SlashCommandUserOption | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder;
|
|
4
4
|
/** The interaction type enum. */
|
|
5
5
|
export declare enum InteractionType {
|
|
6
6
|
CHAT_INPUT_COMMAND = 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/structures/Constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/structures/Constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,6BAA6B,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,kCAAkC,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEjV,6CAA6C;AAC7C,MAAM,MAAM,mBAAmB,GAC3B,4BAA4B,GAC5B,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,6BAA6B,GAC7B,wBAAwB,GACxB,sBAAsB,GACtB,wBAAwB,GACxB,sBAAsB,GACtB,6BAA6B,GAC7B,kCAAkC,CAAC;AAEvC,iCAAiC;AACjC,oBAAY,eAAe;IACvB,kBAAkB,IAAA;IAClB,oBAAoB,IAAA;IACpB,MAAM,IAAA;IACN,WAAW,IAAA;IACX,YAAY,IAAA;CACf"}
|
|
@@ -10,3 +10,4 @@ var InteractionType;
|
|
|
10
10
|
InteractionType[InteractionType["SELECT_MENU"] = 3] = "SELECT_MENU";
|
|
11
11
|
InteractionType[InteractionType["MODAL_SUBMIT"] = 4] = "MODAL_SUBMIT";
|
|
12
12
|
})(InteractionType || (exports.InteractionType = InteractionType = {}));
|
|
13
|
+
//# sourceMappingURL=Constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/structures/Constants.ts"],"names":[],"mappings":";;;AAgBA,iCAAiC;AACjC,IAAY,eAMX;AAND,WAAY,eAAe;IACvB,iFAAkB,CAAA;IAClB,qFAAoB,CAAA;IACpB,yDAAM,CAAA;IACN,mEAAW,CAAA;IACX,qEAAY,CAAA;AAChB,CAAC,EANW,eAAe,+BAAf,eAAe,QAM1B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Client } from "discord.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v10";
|
|
3
|
+
import { Plugin } from "./Plugin";
|
|
4
|
+
import { PluginManager } from "./PluginManager";
|
|
3
5
|
/** The logger interface used for logging application events and errors. You can implement this interface to create a custom logger or use the default console logger. */
|
|
4
6
|
export interface Logger {
|
|
5
7
|
info(message: string): void;
|
|
@@ -9,12 +11,19 @@ export interface Logger {
|
|
|
9
11
|
/**
|
|
10
12
|
* Options for configuring the Discord application, including logger and plugins.
|
|
11
13
|
* @param logger An optional logger object for logging application events and errors. Defaults to the console if not provided.
|
|
12
|
-
* @param plugins An optional array of plugins
|
|
14
|
+
* @param plugins An optional array of plugins, as instances or classes. A class is constructed with `(client, logger)`. Plugins observe the whole application unless they are decorated with `@PluginModule`, which lets them own commands, components, and listeners.
|
|
15
|
+
* @param pluginTimeout Milliseconds any plugin hook may take before it fails with a `PluginError`. A plugin's own `timeout` overrides it. Defaults to 0, which disables the limit.
|
|
13
16
|
* @public
|
|
14
17
|
*/
|
|
15
18
|
export interface DiscordAppOptions {
|
|
16
19
|
logger?: Logger;
|
|
17
|
-
plugins?: Plugin[];
|
|
20
|
+
plugins?: (Plugin | (new (...args: any[]) => Plugin))[];
|
|
21
|
+
pluginTimeout?: number;
|
|
22
|
+
}
|
|
23
|
+
/** Command JSON grouped by deployment scope, suitable for inspecting before deployment. */
|
|
24
|
+
export interface CommandManifest {
|
|
25
|
+
global: RESTPostAPIApplicationCommandsJSONBody[];
|
|
26
|
+
guilds: Record<string, RESTPostAPIApplicationCommandsJSONBody[]>;
|
|
18
27
|
}
|
|
19
28
|
/**
|
|
20
29
|
* The main class that you must extend to create a Discord application. You create an instance by using the `DiscordApp.create()` method.
|
|
@@ -69,18 +78,27 @@ export declare class BaseDiscordModule {
|
|
|
69
78
|
* - Must be instantiated using the static `create()` method
|
|
70
79
|
* - Supports global and guild-specific (private) command deployment
|
|
71
80
|
* - Routes interactions (commands, buttons, select menus, modals) to appropriate handlers
|
|
72
|
-
* - Uses
|
|
81
|
+
* - Uses standard decorator metadata for configuration and property injection
|
|
73
82
|
*
|
|
74
83
|
* @public
|
|
75
84
|
*/
|
|
76
85
|
export declare class DiscordApp {
|
|
77
86
|
#private;
|
|
78
|
-
constructor();
|
|
79
|
-
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
private constructor();
|
|
88
|
+
/** Logs in and deploys commands by default. Pass false to manage deployment separately. */
|
|
89
|
+
login(options?: {
|
|
90
|
+
deployCommands?: boolean;
|
|
91
|
+
}): Promise<void>;
|
|
92
|
+
/** Looks up plugins and enables or disables them at runtime. */
|
|
93
|
+
get plugins(): PluginManager;
|
|
94
|
+
/** Enables plugins once, including concurrent calls; no Discord connection is required. */
|
|
95
|
+
initialize(): Promise<void>;
|
|
96
|
+
/** Stops accepting events, drains handlers, disables plugins in reverse order, and destroys the client. */
|
|
97
|
+
stop(): Promise<void>;
|
|
98
|
+
/** Builds command JSON without logging in or making REST requests. Commands of disabled plugins are left out. */
|
|
99
|
+
getCommandManifest(): CommandManifest;
|
|
100
|
+
/** Deploys each scope once; REST failures reject instead of reporting startup success. */
|
|
101
|
+
deployCommands(): Promise<void>;
|
|
84
102
|
/**
|
|
85
103
|
* Creates a new Discord application. This is the main entry point of the library. You must provide a class that extends {@link BaseDiscordModule}, which will be used as the main module of the application.
|
|
86
104
|
* @param discordModule The main module of the application. This class must extend `BaseDiscordModule`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiscordApp.d.ts","sourceRoot":"","sources":["../../src/structures/DiscordApp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DiscordApp.d.ts","sourceRoot":"","sources":["../../src/structures/DiscordApp.ts"],"names":[],"mappings":"AACA,OAAO,EAAwD,MAAM,EAAoK,MAAM,YAAY,CAAC;AAC5P,OAAO,EAA2D,sCAAsC,EAAU,MAAM,uBAAuB,CAAC;AAKhJ,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAA8B,aAAa,EAAqC,MAAM,iBAAiB,CAAC;AAQ/G,yKAAyK;AACzK,MAAM,WAAW,MAAM;IACnB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,2FAA2F;AAC3F,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,sCAAsC,EAAE,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,sCAAsC,EAAE,CAAC,CAAC;CACpE;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,iBAAiB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK1C,aAAa;IACb,QAAQ;CAGX;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,UAAU;;IAyBnB,OAAO;IAIP,2FAA2F;IACrF,KAAK,CAAC,OAAO,GAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtE,gEAAgE;IAChE,IAAI,OAAO,IAAI,aAAa,CAE3B;IAED,2FAA2F;IACrF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAejC,2GAA2G;IAC3G,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAqBrB,iHAAiH;IACjH,kBAAkB,IAAI,eAAe;IA4BrC,0FAA0F;IACpF,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAwgBrC;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,iBAAiB,EAAE,OAAO,GAAE,iBAAsB;CASzF"}
|