oopscord.js 0.0.25 → 0.0.26

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.
Files changed (31) hide show
  1. package/dist/structures/Constants.d.ts +2 -0
  2. package/dist/structures/Constants.d.ts.map +1 -1
  3. package/dist/structures/Constants.js +1 -0
  4. package/dist/structures/DiscordApp.d.ts +79 -2
  5. package/dist/structures/DiscordApp.d.ts.map +1 -1
  6. package/dist/structures/DiscordApp.js +215 -56
  7. package/dist/structures/components/BaseButton.d.ts +35 -1
  8. package/dist/structures/components/BaseButton.d.ts.map +1 -1
  9. package/dist/structures/components/BaseButton.js +70 -24
  10. package/dist/structures/components/BaseModal.d.ts +75 -6
  11. package/dist/structures/components/BaseModal.d.ts.map +1 -1
  12. package/dist/structures/components/BaseModal.js +128 -28
  13. package/dist/structures/components/BaseModal.test.d.ts +2 -0
  14. package/dist/structures/components/BaseModal.test.d.ts.map +1 -0
  15. package/dist/structures/components/BaseModal.test.js +109 -0
  16. package/dist/structures/components/BaseSelectMenu.d.ts +73 -3
  17. package/dist/structures/components/BaseSelectMenu.d.ts.map +1 -1
  18. package/dist/structures/components/BaseSelectMenu.js +117 -47
  19. package/dist/structures/decorators/Constants.d.ts +2 -0
  20. package/dist/structures/decorators/Constants.d.ts.map +1 -1
  21. package/dist/structures/decorators/Constants.js +3 -1
  22. package/dist/structures/decorators/DiscordModuleDecorator.d.ts +27 -0
  23. package/dist/structures/decorators/DiscordModuleDecorator.d.ts.map +1 -1
  24. package/dist/structures/decorators/DiscordModuleDecorator.js +27 -0
  25. package/dist/structures/decorators/MessageComponentDecorator.d.ts +28 -2
  26. package/dist/structures/decorators/MessageComponentDecorator.d.ts.map +1 -1
  27. package/dist/structures/decorators/MessageComponentDecorator.js +19 -3
  28. package/dist/utils/Util.d.ts +3 -0
  29. package/dist/utils/Util.d.ts.map +1 -1
  30. package/dist/utils/Util.js +15 -2
  31. package/package.json +3 -2
@@ -1,5 +1,7 @@
1
1
  import { SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandUserOption } from "discord.js";
2
+ /** The type of all slash command options. */
2
3
  export type SlashCommandOptions = SlashCommandAttachmentOption | SlashCommandBooleanOption | SlashCommandBooleanOption | SlashCommandChannelOption | SlashCommandIntegerOption | SlashCommandMentionableOption | SlashCommandNumberOption | SlashCommandRoleOption | SlashCommandStringOption | SlashCommandUserOption;
4
+ /** The interaction type enum. */
3
5
  export declare enum InteractionType {
4
6
  CHAT_INPUT_COMMAND = 0,
5
7
  CONTEXT_MENU_COMMAND = 1,
@@ -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;AAE9Q,MAAM,MAAM,mBAAmB,GAC3B,4BAA4B,GAC5B,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,6BAA6B,GAC7B,wBAAwB,GACxB,sBAAsB,GACtB,wBAAwB,GACxB,sBAAsB,CAAC;AAE3B,oBAAY,eAAe;IACvB,kBAAkB,IAAA;IAClB,oBAAoB,IAAA;IACpB,MAAM,IAAA;IACN,WAAW,IAAA;IACX,YAAY,IAAA;CACf"}
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;AAE9Q,6CAA6C;AAC7C,MAAM,MAAM,mBAAmB,GAC3B,4BAA4B,GAC5B,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,yBAAyB,GACzB,6BAA6B,GAC7B,wBAAwB,GACxB,sBAAsB,GACtB,wBAAwB,GACxB,sBAAsB,CAAC;AAE3B,iCAAiC;AACjC,oBAAY,eAAe;IACvB,kBAAkB,IAAA;IAClB,oBAAoB,IAAA;IACpB,MAAM,IAAA;IACN,WAAW,IAAA;IACX,YAAY,IAAA;CACf"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InteractionType = void 0;
4
+ /** The interaction type enum. */
4
5
  var InteractionType;
5
6
  (function (InteractionType) {
6
7
  InteractionType[InteractionType["CHAT_INPUT_COMMAND"] = 0] = "CHAT_INPUT_COMMAND";
@@ -1,16 +1,44 @@
1
1
  import { Client } from "discord.js";
2
2
  import { Plugin } from ".";
3
+ /** 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. */
3
4
  export interface Logger {
4
5
  info(message: string): void;
5
- trace(message: string): void;
6
6
  warn(message: string): void;
7
7
  error(message: string): void;
8
- trace(message: string): void;
9
8
  }
9
+ /**
10
+ * Options for configuring the Discord application, including logger and plugins.
11
+ * @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 to extend the functionality of the Discord application. Plugins can be used to add additional features or integrations.
13
+ * @public
14
+ */
10
15
  export interface DiscordAppOptions {
11
16
  logger?: Logger;
12
17
  plugins?: Plugin[];
13
18
  }
19
+ /**
20
+ * The main class that you must extend to create a Discord application. You create an instance by using the `DiscordApp.create()` method.
21
+ *
22
+ * @example
23
+ *
24
+ * ```ts
25
+ * import { DiscordApp, BaseDiscordModule } from "oopscord.js";
26
+ *
27
+ * @DiscordModule({
28
+ * token: "your-token-goes-here",
29
+ * intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent ],
30
+ * imports: [ MyCommandModule, MyComponentModule ]
31
+ * })
32
+ * export class AppModule extends BaseDiscordModule {
33
+ * @EventHandler("clientReady")
34
+ * onReady() {
35
+ * this.logger.info("Client is ready!");
36
+ * }
37
+ * }
38
+ * ```
39
+ *
40
+ * @see {@link DiscordApp.create}
41
+ */
14
42
  export declare class BaseDiscordModule {
15
43
  client: Client;
16
44
  logger: Logger;
@@ -18,10 +46,59 @@ export declare class BaseDiscordModule {
18
46
  /** Dummy. */
19
47
  _onReady(): void;
20
48
  }
49
+ /**
50
+ * Main application class for managing Discord bot functionality.
51
+ *
52
+ * Handles initialization, login, command deployment, and interaction routing for a Discord application.
53
+ * This class uses the Discord.js library and implements a decorator-based command and component system.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { DiscordApp } from "oopscord.js";
58
+ * import { AppModule } from "./app.module";
59
+ *
60
+ * async function bootstrap() {
61
+ * const app = DiscordApp.create(AppModule);
62
+ * await app.login();
63
+ * }
64
+ *
65
+ * bootstrap();
66
+ * ```
67
+ *
68
+ * @remarks
69
+ * - Must be instantiated using the static `create()` method
70
+ * - Supports global and guild-specific (private) command deployment
71
+ * - Routes interactions (commands, buttons, select menus, modals) to appropriate handlers
72
+ * - Uses reflection metadata for decorator-based configuration
73
+ *
74
+ * @public
75
+ */
21
76
  export declare class DiscordApp {
22
77
  #private;
23
78
  constructor();
79
+ /**
80
+ * Logs in to Discord and deploys the commands. This method must be called after creating the application with `DiscordApp.create()`.
81
+ * @see {@link DiscordApp.create}
82
+ */
24
83
  login(): Promise<void>;
84
+ /**
85
+ * 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
+ * @param discordModule The main module of the application. This class must extend `BaseDiscordModule`.
87
+ * @param options The options for the application.
88
+ * @example
89
+ * ```ts
90
+ * import { DiscordApp } from "oopscord.js";
91
+ * import { AppModule } from "./app.module";
92
+ *
93
+ * async function bootstrap() {
94
+ * const app = DiscordApp.create(AppModule);
95
+ *
96
+ * await app.login();
97
+ * }
98
+ *
99
+ * bootstrap();
100
+ * ```
101
+ */
25
102
  static create(discordModule: typeof BaseDiscordModule, options?: DiscordAppOptions): DiscordApp;
26
103
  }
27
104
  //# sourceMappingURL=DiscordApp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DiscordApp.d.ts","sourceRoot":"","sources":["../../src/structures/DiscordApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsG,MAAM,EAAmI,MAAM,YAAY,CAAC;AAMzQ,OAAO,EAAc,MAAM,EAAE,MAAM,GAAG,CAAC;AAEvC,MAAM,WAAW,MAAM;IACnB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAOD,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;AAID,qBAAa,UAAU;;;IAuBb,KAAK;IAyRX,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,iBAAiB,EAAE,OAAO,GAAE,iBAAsB;CAWzF"}
1
+ {"version":3,"file":"DiscordApp.d.ts","sourceRoot":"","sources":["../../src/structures/DiscordApp.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4E,MAAM,EAA4L,MAAM,YAAY,CAAC;AAMxS,OAAO,EAA4E,MAAM,EAAE,MAAM,GAAG,CAAC;AAGrG,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;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAOD;;;;;;;;;;;;;;;;;;;;;;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;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,UAAU;;;IAuBnB;;;OAGG;IACG,KAAK;IA2YX;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,iBAAiB,EAAE,OAAO,GAAE,iBAAsB;CAWzF"}
@@ -5,10 +5,34 @@ const discord_js_1 = require("discord.js");
5
5
  const v10_1 = require("discord-api-types/v10");
6
6
  const Constants_1 = require("./decorators/Constants");
7
7
  const Constants_2 = require("./Constants");
8
+ const Util_1 = require("../utils/Util");
8
9
  const defaultDiscordAppOptions = {
9
10
  logger: console,
10
11
  plugins: []
11
12
  };
13
+ /**
14
+ * The main class that you must extend to create a Discord application. You create an instance by using the `DiscordApp.create()` method.
15
+ *
16
+ * @example
17
+ *
18
+ * ```ts
19
+ * import { DiscordApp, BaseDiscordModule } from "oopscord.js";
20
+ *
21
+ * @DiscordModule({
22
+ * token: "your-token-goes-here",
23
+ * intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.MessageContent ],
24
+ * imports: [ MyCommandModule, MyComponentModule ]
25
+ * })
26
+ * export class AppModule extends BaseDiscordModule {
27
+ * @EventHandler("clientReady")
28
+ * onReady() {
29
+ * this.logger.info("Client is ready!");
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * @see {@link DiscordApp.create}
35
+ */
12
36
  class BaseDiscordModule {
13
37
  client;
14
38
  logger;
@@ -22,6 +46,33 @@ class BaseDiscordModule {
22
46
  }
23
47
  exports.BaseDiscordModule = BaseDiscordModule;
24
48
  let a1 = false;
49
+ /**
50
+ * Main application class for managing Discord bot functionality.
51
+ *
52
+ * Handles initialization, login, command deployment, and interaction routing for a Discord application.
53
+ * This class uses the Discord.js library and implements a decorator-based command and component system.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { DiscordApp } from "oopscord.js";
58
+ * import { AppModule } from "./app.module";
59
+ *
60
+ * async function bootstrap() {
61
+ * const app = DiscordApp.create(AppModule);
62
+ * await app.login();
63
+ * }
64
+ *
65
+ * bootstrap();
66
+ * ```
67
+ *
68
+ * @remarks
69
+ * - Must be instantiated using the static `create()` method
70
+ * - Supports global and guild-specific (private) command deployment
71
+ * - Routes interactions (commands, buttons, select menus, modals) to appropriate handlers
72
+ * - Uses reflection metadata for decorator-based configuration
73
+ *
74
+ * @public
75
+ */
25
76
  class DiscordApp {
26
77
  #rest;
27
78
  #client;
@@ -41,55 +92,61 @@ class DiscordApp {
41
92
  this.#loadStartTimestamp = Date.now();
42
93
  this.#rest = new discord_js_1.REST({ version: "10" });
43
94
  }
95
+ /**
96
+ * Logs in to Discord and deploys the commands. This method must be called after creating the application with `DiscordApp.create()`.
97
+ * @see {@link DiscordApp.create}
98
+ */
44
99
  async login() {
100
+ const commands = this.#commands.filter(i => Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CHAT_INPUT_COMMAND || Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CONTEXT_MENU_COMMAND);
101
+ const privateCommands = commands.filter(c => Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_KEY, c));
102
+ const globalCommands = commands.filter(c => !Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_KEY, c));
103
+ this.#module.logger.info(`Found ${commands.length} command(s) in total, ${globalCommands.length} global command(s) and ${privateCommands.length} private command(s). (${(Date.now() - this.#loadStartTimestamp)}ms)`);
104
+ this.#module.logger.info("Mapping global commands...");
105
+ // Prepare global commands
106
+ const apiGlobalCommands = globalCommands.map(c => {
107
+ const type = Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, c);
108
+ const integrationTypes = Reflect.getMetadata(Constants_1.INTERACTION_INTEGRATION_TYPES_KEY, c);
109
+ if (type == Constants_2.InteractionType.CHAT_INPUT_COMMAND)
110
+ return this.#mapSlashCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_OPTIONS_KEY, c), integrationTypes);
111
+ else
112
+ return this.#mapContextMenuCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
113
+ });
114
+ this.#module.logger.info(`└─ Mapped ${apiGlobalCommands.length} global command(s). (${(Date.now() - this.#loadStartTimestamp)}ms)`);
115
+ this.#module.logger.info("Mapping private commands...");
116
+ // Prepare private commands
117
+ const apiPrivateCommands = {};
118
+ privateCommands.forEach(c => {
119
+ const guildId = Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_GUILD_KEY, c);
120
+ const type = Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, c);
121
+ const integrationTypes = Reflect.getMetadata(Constants_1.INTERACTION_INTEGRATION_TYPES_KEY, c);
122
+ let data;
123
+ if (type == Constants_2.InteractionType.CHAT_INPUT_COMMAND)
124
+ data = this.#mapSlashCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_OPTIONS_KEY, c), integrationTypes);
125
+ else
126
+ data = this.#mapContextMenuCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
127
+ if (!Array.isArray(apiPrivateCommands[guildId]))
128
+ apiPrivateCommands[guildId] = [];
129
+ apiPrivateCommands[guildId].push(data);
130
+ });
131
+ const wholePrivateCommands = Object.values(apiPrivateCommands).flat();
132
+ this.#module.logger.info(`└─ Mapped ${Object.keys(apiPrivateCommands).length} guild(s) with ${wholePrivateCommands.length} private command(s). (${(Date.now() - this.#loadStartTimestamp)}ms)`);
45
133
  this.#rest.setToken(this.#moduleOptions.token);
134
+ this.#module.logger.info("Logging in...");
46
135
  await this.#client.login(this.#moduleOptions.token);
136
+ this.#module.logger.info(`Successfully logged in. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
47
137
  try {
48
- const commands = this.#commands.filter(i => Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CHAT_INPUT_COMMAND || Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CONTEXT_MENU_COMMAND);
49
- const privateCommands = commands.filter(c => Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_KEY, c));
50
- const globalCommands = commands.filter(c => !Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_KEY, c));
51
- this.#module.logger.info(`Found ${commands.length} command(s) in total, ${globalCommands.length} global command(s) and ${privateCommands.length} private command(s).`);
52
- this.#module.logger.info("Mapping global commands...");
53
- // Prepare global commands
54
- const apiGlobalCommands = globalCommands.map(c => {
55
- const type = Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, c);
56
- const integrationTypes = Reflect.getMetadata(Constants_1.INTERACTION_INTEGRATION_TYPES_KEY, c);
57
- if (type == Constants_2.InteractionType.CHAT_INPUT_COMMAND)
58
- return this.#mapSlashCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_OPTIONS_KEY, c), integrationTypes);
59
- else
60
- return this.#mapContextMenuCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
61
- });
62
- this.#module.logger.info(`└─ Mapped ${apiGlobalCommands.length} global command(s).`);
63
- this.#module.logger.info("Mapping private commands...");
64
- // Prepare private commands
65
- const apiPrivateCommands = {};
66
- privateCommands.forEach(c => {
67
- const guildId = Reflect.getMetadata(Constants_1.COMMAND_PRIVATE_GUILD_KEY, c);
68
- const type = Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, c);
69
- const integrationTypes = Reflect.getMetadata(Constants_1.INTERACTION_INTEGRATION_TYPES_KEY, c);
70
- let data;
71
- if (type == Constants_2.InteractionType.CHAT_INPUT_COMMAND)
72
- data = this.#mapSlashCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(Constants_1.COMMAND_OPTIONS_KEY, c), integrationTypes);
73
- else
74
- data = this.#mapContextMenuCommand(Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c), Reflect.getMetadata(Constants_1.CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
75
- if (!Array.isArray(apiPrivateCommands[guildId]))
76
- apiPrivateCommands[guildId] = [];
77
- apiPrivateCommands[guildId].push(data);
78
- });
79
- const wholePrivateCommands = Object.values(apiPrivateCommands).flat();
80
- this.#module.logger.info(`└─ Mapped ${Object.keys(apiPrivateCommands).length} guild(s) with ${wholePrivateCommands.length} private command(s).`);
81
138
  this.#module.logger.info("Deploying commands...");
82
139
  if (this.#moduleOptions.test.enable) {
83
140
  await this.#rest.put(v10_1.Routes.applicationGuildCommands(this.#client.user.id, this.#moduleOptions.test.guild), { body: apiGlobalCommands });
84
- this.#module.logger.info(`├─ Successfully registered global commands, in test guild ${this.#moduleOptions.test.guild}.`);
141
+ this.#module.logger.info(`├─ Successfully registered global commands, in test guild ${this.#moduleOptions.test.guild}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
85
142
  }
86
143
  else {
87
144
  await this.#rest.put(v10_1.Routes.applicationCommands(this.#client.user.id), { body: apiGlobalCommands });
88
- this.#module.logger.info(`├─ Successfully registered global commands.`);
145
+ this.#module.logger.info(`├─ Successfully registered global commands. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
89
146
  }
90
147
  for (const guildId in apiPrivateCommands) {
91
148
  await this.#rest.put(v10_1.Routes.applicationGuildCommands(this.#client.user.id, guildId), { body: apiPrivateCommands[guildId] });
92
- this.#module.logger.info(`├─ Successfully registered private commands in ${guildId}.`);
149
+ this.#module.logger.info(`├─ Successfully registered private commands in ${guildId}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
93
150
  }
94
151
  this.#module.logger.info("└─ Successfully deployed all commands.");
95
152
  }
@@ -99,6 +156,12 @@ class DiscordApp {
99
156
  }
100
157
  this.#module.logger.info("Application took " + (Date.now() - this.#loadStartTimestamp) + "ms to load.");
101
158
  }
159
+ /**
160
+ * Handles incoming chat input command interactions by routing them to the appropriate command handler based on the command name, subcommand group, and subcommand. It uses reflection metadata to determine which handler to invoke and what arguments to pass.
161
+ * @param itr The chat input command interaction to handle.
162
+ * @returns {void}
163
+ * @internal
164
+ */
102
165
  #chatInputCommandHandler(itr) {
103
166
  const commands = this.#commands.filter(i => Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CHAT_INPUT_COMMAND);
104
167
  const commandName = itr.commandName;
@@ -112,6 +175,8 @@ class DiscordApp {
112
175
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, handler);
113
176
  let preArgs = [Reflect.getMetadata(Constants_1.INTERACTION_PARAMETER_INDEX_KEY, handler), ...(Reflect.getMetadata(Constants_1.OPTIONS_PARAMETER_INDEX_KEY, handler) || [])];
114
177
  let args = Array(preArgs.length).fill(null);
178
+ if (runMethod == undefined)
179
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
115
180
  preArgs.forEach(arg => {
116
181
  if (typeof arg == "number")
117
182
  args[arg] = itr;
@@ -128,6 +193,8 @@ class DiscordApp {
128
193
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, handler);
129
194
  let preArgs = [Reflect.getMetadata(Constants_1.INTERACTION_PARAMETER_INDEX_KEY, handler), ...(Reflect.getMetadata(Constants_1.OPTIONS_PARAMETER_INDEX_KEY, handler) || [])];
130
195
  let args = Array(preArgs.length).fill(null);
196
+ if (runMethod == undefined)
197
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
131
198
  preArgs.forEach(arg => {
132
199
  if (typeof arg == "number")
133
200
  args[arg] = itr;
@@ -141,6 +208,8 @@ class DiscordApp {
141
208
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, command);
142
209
  let preArgs = [Reflect.getMetadata(Constants_1.INTERACTION_PARAMETER_INDEX_KEY, command), ...(Reflect.getMetadata(Constants_1.OPTIONS_PARAMETER_INDEX_KEY, command) || [])];
143
210
  let args = Array(preArgs.length).fill(null);
211
+ if (runMethod == undefined)
212
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
144
213
  preArgs.forEach(arg => {
145
214
  if (typeof arg == "number")
146
215
  args[arg] = itr;
@@ -151,42 +220,122 @@ class DiscordApp {
151
220
  cmd[runMethod]();
152
221
  }
153
222
  }
223
+ /**
224
+ * Handles incoming context menu command interactions by routing them to the appropriate command handler based on the command name and type. It uses reflection metadata to determine which handler to invoke and what arguments to pass.
225
+ * @param itr The context menu command interaction to handle.
226
+ * @returns {void}
227
+ * @internal
228
+ */
229
+ #contextMenuCommandHandler(itr) {
230
+ const commands = this.#commands.filter(i => Reflect.getMetadata(Constants_1.INTERACTION_TYPE_KEY, i) == Constants_2.InteractionType.CONTEXT_MENU_COMMAND);
231
+ const commandName = itr.commandName;
232
+ const command = commands.find(c => Reflect.getMetadata(Constants_1.COMMAND_NAME_KEY, c) == commandName && Reflect.getMetadata(Constants_1.COMMAND_OPTIONS_KEY, c).type == itr.commandType);
233
+ if (!command)
234
+ return;
235
+ let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, command);
236
+ if (runMethod == undefined)
237
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
238
+ let cmd = new command(itr);
239
+ cmd[runMethod]();
240
+ }
241
+ /**
242
+ * Handles incoming button interactions by routing them to the appropriate button handler based on the custom ID. It uses reflection metadata to determine which handler to invoke and what arguments to pass.
243
+ * @param itr The button interaction to handle.
244
+ * @returns {void}
245
+ * @internal
246
+ */
154
247
  #buttonHandler(itr) {
155
248
  const button = this.#buttons.find(b => Reflect.getMetadata(Constants_1.BUTTON_OPTIONS_KEY, b).customId == itr.customId);
156
249
  if (!button)
157
250
  return;
158
251
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, button);
252
+ if (runMethod == undefined)
253
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
159
254
  let cmd = new button(itr);
160
255
  cmd[runMethod]();
161
256
  }
257
+ /**
258
+ * Handles incoming select menu interactions by routing them to the appropriate select menu handler based on the custom ID. It uses reflection metadata to determine which handler to invoke and what arguments to pass.
259
+ * @param itr The select menu interaction to handle.
260
+ * @returns {void}
261
+ * @internal
262
+ */
162
263
  #selectMenuHandler(itr) {
163
264
  const selectMenu = this.#selectMenus.find(b => Reflect.getMetadata(Constants_1.SELECT_MENU_OPTIONS_KEY, b).customId == itr.customId);
164
265
  if (!selectMenu)
165
266
  return;
166
267
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, selectMenu);
268
+ if (runMethod == undefined)
269
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
167
270
  let cmd = new selectMenu(itr);
168
271
  cmd[runMethod]();
169
272
  }
273
+ /**
274
+ * Handles incoming modal submit interactions by routing them to the appropriate modal handler based on the custom ID. It uses reflection metadata to determine which handler to invoke and what arguments to pass, including extracting values from text input components if necessary.
275
+ * @param itr The modal submit interaction to handle.
276
+ * @returns {void}
277
+ * @internal
278
+ */
170
279
  #modalHandler(itr) {
171
280
  const modal = this.#modals.find(b => Reflect.getMetadata(Constants_1.MODAL_OPTIONS_KEY, b).customId == itr.customId);
172
281
  if (!modal)
173
282
  return;
283
+ const modalComponents = Reflect.getMetadata(Constants_1.MODAL_COMPONENTS_KEY, modal);
174
284
  let runMethod = Reflect.getMetadata(Constants_1.INTERACTION_RUN_METHOD_KEY, modal);
175
- let preArgs = [Reflect.getMetadata(Constants_1.INTERACTION_PARAMETER_INDEX_KEY, modal), ...(Reflect.getMetadata(Constants_1.MODAL_TEXT_INPUT_VALUE_INDEX_KEY, modal) || [])];
285
+ let preArgs = [Reflect.getMetadata(Constants_1.INTERACTION_PARAMETER_INDEX_KEY, modal), ...(Reflect.getMetadata(Constants_1.MODAL_TEXT_INPUT_VALUE_INDEX_KEY, modal) || []), ...(Reflect.getMetadata(Constants_1.MODAL_SELECT_MENU_VALUE_INDEX_KEY, modal) || []), ...(Reflect.getMetadata(Constants_1.MODAL_FILE_UPLOAD_VALUE_INDEX_KEY, modal) || [])];
176
286
  let args = Array(preArgs.length).fill(null);
177
287
  preArgs.forEach(arg => {
178
- if (typeof arg == "number")
288
+ if (typeof arg == "number") {
179
289
  args[arg] = itr;
180
- else
181
- args[arg.index] = itr.fields.getTextInputValue(arg.customId);
290
+ }
291
+ else {
292
+ const fieldIndex = arg;
293
+ switch (fieldIndex.type) {
294
+ case "text_input":
295
+ args[arg.index] = itr.fields.getTextInputValue(fieldIndex.customId);
296
+ break;
297
+ case "select_menu":
298
+ const getMethods = {
299
+ "string_select": itr.fields.getStringSelectValues,
300
+ "user_select": itr.fields.getSelectedUsers,
301
+ "role_select": itr.fields.getSelectedRoles,
302
+ "mentionable_select": itr.fields.getSelectedMentionables,
303
+ "channel_select": itr.fields.getSelectedChannels
304
+ };
305
+ const label = modalComponents.find(c => c.outerType == "label" && c.innerType.endsWith("select") && c.component.data.component?.data?.custom_id == fieldIndex.customId);
306
+ const getMethod = getMethods[label?.innerType];
307
+ if (!getMethod)
308
+ throw new TypeError(`Failed to get the select menu values for custom ID ${fieldIndex.customId}. Failed to gather necessary metadata.`);
309
+ const result = getMethod.bind(itr.fields)(fieldIndex.customId);
310
+ if (result instanceof discord_js_1.Collection)
311
+ args[arg.index] = result.toJSON();
312
+ else
313
+ args[arg.index] = result;
314
+ break;
315
+ case "file_upload":
316
+ args[arg.index] = itr.fields.getUploadedFiles(fieldIndex.customId);
317
+ break;
318
+ }
319
+ }
182
320
  });
321
+ if (runMethod == undefined)
322
+ throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
183
323
  let cmd = new modal(...args);
184
324
  cmd[runMethod]();
185
325
  }
326
+ /**
327
+ * Automatically handles incoming interactions by determining their type (chat input command, context menu command, button interaction, select menu interaction, or modal submit) and routing them to the appropriate handler method. This method is called internally whenever an interaction is created.
328
+ * @param itr The interaction to handle.
329
+ * @returns {void}
330
+ * @internal
331
+ */
186
332
  #autoHandler(itr) {
187
333
  if (itr.isChatInputCommand()) {
188
334
  this.#chatInputCommandHandler(itr);
189
335
  }
336
+ else if (itr.isContextMenuCommand()) {
337
+ this.#contextMenuCommandHandler(itr);
338
+ }
190
339
  else if (itr.isButton()) {
191
340
  this.#buttonHandler(itr);
192
341
  }
@@ -196,7 +345,12 @@ class DiscordApp {
196
345
  else if (itr.isModalSubmit()) {
197
346
  this.#modalHandler(itr);
198
347
  }
348
+ return;
199
349
  }
350
+ /**
351
+ * Initializes the Discord application by creating the Discord client, setting up event listeners based on the provided module, and preparing command and component handlers. This method is called internally by the `create()` method after setting the main module and options.
352
+ * @internal
353
+ */
200
354
  #init() {
201
355
  const options = Reflect.getMetadata(Constants_1.DICSORD_MODULE_OPTIONS_KEY, this.#moduleFunction);
202
356
  const internalEvents = Reflect.getMetadata(Constants_1.DISCORD_MODULE_INTERNAL_EVENTS_KEY, this.#moduleFunction);
@@ -239,7 +393,7 @@ class DiscordApp {
239
393
  this.#moduleFunction = discordModule;
240
394
  }
241
395
  #setOptions(options) {
242
- this.#appOptions = mergeDefault(defaultDiscordAppOptions, options);
396
+ this.#appOptions = Util_1.Util.mergeDefault(defaultDiscordAppOptions, options);
243
397
  }
244
398
  #mapSlashCommand(name, description, options = [], integrationTypes = []) {
245
399
  const requiredOptions = options.filter(o => o.required);
@@ -249,7 +403,7 @@ class DiscordApp {
249
403
  if (integrationTypes.length > 0)
250
404
  data.setIntegrationTypes(integrationTypes);
251
405
  Reflect.set(data, "options", [...requiredOptions, ...options.filter(o => !o.required)]);
252
- this.#module.logger.info(`├─ Mapped slash command ${name}.`);
406
+ this.#module.logger.info(`├─ Mapped slash command ${name}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
253
407
  return data.toJSON();
254
408
  }
255
409
  #mapContextMenuCommand(name, type, integrationTypes = []) {
@@ -258,9 +412,27 @@ class DiscordApp {
258
412
  .setType(type);
259
413
  if (integrationTypes.length > 0)
260
414
  data.setIntegrationTypes(integrationTypes);
261
- this.#module.logger.info(`├─ Mapped context command ${name}.`);
415
+ this.#module.logger.info(`├─ Mapped context command ${name}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
262
416
  return data.toJSON();
263
417
  }
418
+ /**
419
+ * 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.
420
+ * @param discordModule The main module of the application. This class must extend `BaseDiscordModule`.
421
+ * @param options The options for the application.
422
+ * @example
423
+ * ```ts
424
+ * import { DiscordApp } from "oopscord.js";
425
+ * import { AppModule } from "./app.module";
426
+ *
427
+ * async function bootstrap() {
428
+ * const app = DiscordApp.create(AppModule);
429
+ *
430
+ * await app.login();
431
+ * }
432
+ *
433
+ * bootstrap();
434
+ * ```
435
+ */
264
436
  static create(discordModule, options = {}) {
265
437
  a1 = true;
266
438
  const app = new DiscordApp();
@@ -271,16 +443,3 @@ class DiscordApp {
271
443
  }
272
444
  }
273
445
  exports.DiscordApp = DiscordApp;
274
- function mergeDefault(def, given) {
275
- if (!given)
276
- return def;
277
- for (const key in def) {
278
- if (!Object.hasOwn(given, key) || given[key] === undefined) {
279
- given[key] = def[key];
280
- }
281
- else if (given[key] === Object(given[key])) {
282
- given[key] = mergeDefault(def[key], given[key]);
283
- }
284
- }
285
- return given;
286
- }
@@ -1,6 +1,40 @@
1
1
  import { ButtonBuilder } from "discord.js";
2
+ import { ButtonOptions } from "..";
3
+ /**
4
+ * The base class for buttons created with the {@link Button} decorator. This class is used to create a button from the options defined in the class, and to override the default options with new options when creating the button.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { ButtonInteraction, ButtonStyle } from "discord.js";
9
+ * import { Button, BaseButton, Interaction, Run } from "oopscord.js";
10
+ *
11
+ * @Button({
12
+ * customId: "my_button",
13
+ * label: "Click me!",
14
+ * style: ButtonStyle.Primary
15
+ * })
16
+ * class MyButton extends BaseButton {
17
+ * constructor(@Interaction readonly interaction: ButtonInteraction) {
18
+ * super();
19
+ * }
20
+ *
21
+ * @Run
22
+ * async run() {
23
+ * await this.interaction.reply("You clicked the button!");
24
+ * }
25
+ * }
26
+ * ```
27
+ */
2
28
  export declare class BaseButton {
3
- static button: ButtonBuilder | null;
29
+ private static options;
30
+ private static button;
31
+ /** Returns {@link ButtonBuilder} that was created from the button options. */
4
32
  static getButton(): ButtonBuilder;
33
+ /**
34
+ * Returns a new {@link ButtonBuilder} with the specified options merged with the default options defined in the class.
35
+ *
36
+ * @param options The options to merge with the default options.
37
+ */
38
+ static override<T extends ButtonOptions>(options: Partial<T>): ButtonBuilder;
5
39
  }
6
40
  //# sourceMappingURL=BaseButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseButton.d.ts","sourceRoot":"","sources":["../../../src/structures/components/BaseButton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AAGxD,qBAAa,UAAU;IACnB,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAQ;IAE3C,MAAM,CAAC,SAAS;CAkCnB"}
1
+ {"version":3,"file":"BaseButton.d.ts","sourceRoot":"","sources":["../../../src/structures/components/BaseButton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AACxD,OAAO,EAA8B,aAAa,EAAE,MAAM,IAAI,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAgB;IACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAA8B;IAEnD,8EAA8E;IAC9E,MAAM,CAAC,SAAS;IAiBhB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CAS/D"}