oopscord.js 0.0.28 → 0.0.30
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/README.md +1 -1
- package/bun.lock +264 -264
- package/dist/index.js +1 -17
- package/dist/structures/Constants.js +2 -5
- package/dist/structures/DiscordApp.d.ts.map +1 -1
- package/dist/structures/DiscordApp.js +94 -81
- package/dist/structures/Plugin.js +1 -5
- package/dist/structures/components/BaseButton.js +11 -15
- package/dist/structures/components/BaseModal.js +28 -35
- package/dist/structures/components/BaseSelectMenu.js +13 -17
- 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 +17 -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 +4 -19
- package/dist/structures/decorators/CommandDecorator.d.ts +1 -1
- package/dist/structures/decorators/CommandDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/CommandDecorator.js +127 -158
- package/dist/structures/decorators/Constants.d.ts +5 -3
- package/dist/structures/decorators/Constants.d.ts.map +1 -1
- package/dist/structures/decorators/Constants.js +32 -33
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts +4 -17
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/DiscordModuleDecorator.js +9 -34
- package/dist/structures/decorators/EventDecorator.d.ts +44 -0
- package/dist/structures/decorators/EventDecorator.d.ts.map +1 -0
- package/dist/structures/decorators/EventDecorator.js +44 -0
- package/dist/structures/decorators/InteractionHandlerDecorator.js +5 -9
- package/dist/structures/decorators/MessageComponentDecorator.d.ts +1 -1
- package/dist/structures/decorators/MessageComponentDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/MessageComponentDecorator.js +68 -86
- package/dist/structures/decorators/index.d.ts +1 -0
- package/dist/structures/decorators/index.d.ts.map +1 -1
- package/dist/structures/decorators/index.js +6 -21
- package/dist/structures/index.js +6 -22
- package/dist/utils/Util.js +3 -7
- package/package.json +38 -38
- package/tsdown.config.json +3 -0
package/dist/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./structures"), exports);
|
|
1
|
+
export * from "./structures";
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InteractionType = void 0;
|
|
4
1
|
/** The interaction type enum. */
|
|
5
|
-
var InteractionType;
|
|
2
|
+
export var InteractionType;
|
|
6
3
|
(function (InteractionType) {
|
|
7
4
|
InteractionType[InteractionType["CHAT_INPUT_COMMAND"] = 0] = "CHAT_INPUT_COMMAND";
|
|
8
5
|
InteractionType[InteractionType["CONTEXT_MENU_COMMAND"] = 1] = "CONTEXT_MENU_COMMAND";
|
|
9
6
|
InteractionType[InteractionType["BUTTON"] = 2] = "BUTTON";
|
|
10
7
|
InteractionType[InteractionType["SELECT_MENU"] = 3] = "SELECT_MENU";
|
|
11
8
|
InteractionType[InteractionType["MODAL_SUBMIT"] = 4] = "MODAL_SUBMIT";
|
|
12
|
-
})(InteractionType || (
|
|
9
|
+
})(InteractionType || (InteractionType = {}));
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAIrG,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;IA2aX;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,iBAAiB,EAAE,OAAO,GAAE,iBAAsB;CAWzF"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Constants_1 = require("./decorators/Constants");
|
|
7
|
-
const Constants_2 = require("./Constants");
|
|
8
|
-
const Util_1 = require("../utils/Util");
|
|
1
|
+
import { Client, Collection, ContextMenuCommandBuilder, REST, SlashCommandBuilder } from "discord.js";
|
|
2
|
+
import { Routes } from "discord-api-types/v10";
|
|
3
|
+
import { COMMAND_DESCRIPTION_KEY, COMMAND_NAME_KEY, COMMAND_PRIVATE_KEY, DICSORD_MODULE_OPTIONS_KEY, INTERNAL_EVENTS_KEY, INTERACTION_TYPE_KEY, COMMAND_OPTIONS_KEY, COMMAND_PRIVATE_GUILD_KEY, INTERACTION_RUN_METHOD_KEY, OPTIONS_PARAMETER_INDEX_KEY, INTERACTION_PARAMETER_INDEX_KEY, COMMAND_SUBCOMMAND_GROUPS_KEY, COMMAND_SUBCOMMANDS_KEY, MODULE_TYPE_KEY, ModuleType, COMMAND_MODULE_COMMANDS_KEY, MESSAGE_COMPONENT_MODULE_COMPONENTS_KEY, BUTTON_OPTIONS_KEY, SELECT_MENU_OPTIONS_KEY, MODAL_OPTIONS_KEY, MODAL_TEXT_INPUT_VALUE_INDEX_KEY, CONTEXT_MENU_TYPE_KEY, INTERACTION_INTEGRATION_TYPES_KEY, MODAL_SELECT_MENU_VALUE_INDEX_KEY, MODAL_FILE_UPLOAD_VALUE_INDEX_KEY, MODAL_COMPONENTS_KEY, EVENT_MODULE_LISTENERS_KEY } from "./decorators/Constants";
|
|
4
|
+
import { InteractionType } from "./Constants";
|
|
5
|
+
import { Util } from "../utils/Util";
|
|
9
6
|
const defaultDiscordAppOptions = {
|
|
10
7
|
logger: console,
|
|
11
8
|
plugins: []
|
|
@@ -33,7 +30,7 @@ const defaultDiscordAppOptions = {
|
|
|
33
30
|
*
|
|
34
31
|
* @see {@link DiscordApp.create}
|
|
35
32
|
*/
|
|
36
|
-
class BaseDiscordModule {
|
|
33
|
+
export class BaseDiscordModule {
|
|
37
34
|
client;
|
|
38
35
|
logger;
|
|
39
36
|
constructor(client, logger) {
|
|
@@ -44,7 +41,6 @@ class BaseDiscordModule {
|
|
|
44
41
|
_onReady() {
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
|
-
exports.BaseDiscordModule = BaseDiscordModule;
|
|
48
44
|
let a1 = false;
|
|
49
45
|
/**
|
|
50
46
|
* Main application class for managing Discord bot functionality.
|
|
@@ -73,7 +69,7 @@ let a1 = false;
|
|
|
73
69
|
*
|
|
74
70
|
* @public
|
|
75
71
|
*/
|
|
76
|
-
class DiscordApp {
|
|
72
|
+
export class DiscordApp {
|
|
77
73
|
#rest;
|
|
78
74
|
#client;
|
|
79
75
|
#moduleFunction;
|
|
@@ -90,40 +86,40 @@ class DiscordApp {
|
|
|
90
86
|
throw new ReferenceError("Please use DiscordApp.create()");
|
|
91
87
|
a1 = false;
|
|
92
88
|
this.#loadStartTimestamp = Date.now();
|
|
93
|
-
this.#rest = new
|
|
89
|
+
this.#rest = new REST({ version: "10" });
|
|
94
90
|
}
|
|
95
91
|
/**
|
|
96
92
|
* Logs in to Discord and deploys the commands. This method must be called after creating the application with `DiscordApp.create()`.
|
|
97
93
|
* @see {@link DiscordApp.create}
|
|
98
94
|
*/
|
|
99
95
|
async login() {
|
|
100
|
-
const commands = this.#commands.filter(i => Reflect.getMetadata(
|
|
101
|
-
const privateCommands = commands.filter(c => Reflect.getMetadata(
|
|
102
|
-
const globalCommands = commands.filter(c => !Reflect.getMetadata(
|
|
96
|
+
const commands = this.#commands.filter(i => Reflect.getMetadata(INTERACTION_TYPE_KEY, i) == InteractionType.CHAT_INPUT_COMMAND || Reflect.getMetadata(INTERACTION_TYPE_KEY, i) == InteractionType.CONTEXT_MENU_COMMAND);
|
|
97
|
+
const privateCommands = commands.filter(c => Reflect.getMetadata(COMMAND_PRIVATE_KEY, c));
|
|
98
|
+
const globalCommands = commands.filter(c => !Reflect.getMetadata(COMMAND_PRIVATE_KEY, c));
|
|
103
99
|
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
100
|
this.#module.logger.info("Mapping global commands...");
|
|
105
101
|
// Prepare global commands
|
|
106
102
|
const apiGlobalCommands = globalCommands.map(c => {
|
|
107
|
-
const type = Reflect.getMetadata(
|
|
108
|
-
const integrationTypes = Reflect.getMetadata(
|
|
109
|
-
if (type ==
|
|
110
|
-
return this.#mapSlashCommand(Reflect.getMetadata(
|
|
103
|
+
const type = Reflect.getMetadata(INTERACTION_TYPE_KEY, c);
|
|
104
|
+
const integrationTypes = Reflect.getMetadata(INTERACTION_INTEGRATION_TYPES_KEY, c);
|
|
105
|
+
if (type == InteractionType.CHAT_INPUT_COMMAND)
|
|
106
|
+
return this.#mapSlashCommand(Reflect.getMetadata(COMMAND_NAME_KEY, c), Reflect.getMetadata(COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(COMMAND_OPTIONS_KEY, c), integrationTypes);
|
|
111
107
|
else
|
|
112
|
-
return this.#mapContextMenuCommand(Reflect.getMetadata(
|
|
108
|
+
return this.#mapContextMenuCommand(Reflect.getMetadata(COMMAND_NAME_KEY, c), Reflect.getMetadata(CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
|
|
113
109
|
});
|
|
114
110
|
this.#module.logger.info(`└─ Mapped ${apiGlobalCommands.length} global command(s). (${(Date.now() - this.#loadStartTimestamp)}ms)`);
|
|
115
111
|
this.#module.logger.info("Mapping private commands...");
|
|
116
112
|
// Prepare private commands
|
|
117
113
|
const apiPrivateCommands = {};
|
|
118
114
|
privateCommands.forEach(c => {
|
|
119
|
-
const guildId = Reflect.getMetadata(
|
|
120
|
-
const type = Reflect.getMetadata(
|
|
121
|
-
const integrationTypes = Reflect.getMetadata(
|
|
115
|
+
const guildId = Reflect.getMetadata(COMMAND_PRIVATE_GUILD_KEY, c);
|
|
116
|
+
const type = Reflect.getMetadata(INTERACTION_TYPE_KEY, c);
|
|
117
|
+
const integrationTypes = Reflect.getMetadata(INTERACTION_INTEGRATION_TYPES_KEY, c);
|
|
122
118
|
let data;
|
|
123
|
-
if (type ==
|
|
124
|
-
data = this.#mapSlashCommand(Reflect.getMetadata(
|
|
119
|
+
if (type == InteractionType.CHAT_INPUT_COMMAND)
|
|
120
|
+
data = this.#mapSlashCommand(Reflect.getMetadata(COMMAND_NAME_KEY, c), Reflect.getMetadata(COMMAND_DESCRIPTION_KEY, c), Reflect.getMetadata(COMMAND_OPTIONS_KEY, c), integrationTypes);
|
|
125
121
|
else
|
|
126
|
-
data = this.#mapContextMenuCommand(Reflect.getMetadata(
|
|
122
|
+
data = this.#mapContextMenuCommand(Reflect.getMetadata(COMMAND_NAME_KEY, c), Reflect.getMetadata(CONTEXT_MENU_TYPE_KEY, c), integrationTypes);
|
|
127
123
|
if (!Array.isArray(apiPrivateCommands[guildId]))
|
|
128
124
|
apiPrivateCommands[guildId] = [];
|
|
129
125
|
apiPrivateCommands[guildId].push(data);
|
|
@@ -137,15 +133,15 @@ class DiscordApp {
|
|
|
137
133
|
try {
|
|
138
134
|
this.#module.logger.info("Deploying commands...");
|
|
139
135
|
if (this.#moduleOptions.test.enable) {
|
|
140
|
-
await this.#rest.put(
|
|
136
|
+
await this.#rest.put(Routes.applicationGuildCommands(this.#client.user.id, this.#moduleOptions.test.guild), { body: apiGlobalCommands });
|
|
141
137
|
this.#module.logger.info(`├─ Successfully registered global commands, in test guild ${this.#moduleOptions.test.guild}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
|
|
142
138
|
}
|
|
143
139
|
else {
|
|
144
|
-
await this.#rest.put(
|
|
140
|
+
await this.#rest.put(Routes.applicationCommands(this.#client.user.id), { body: apiGlobalCommands });
|
|
145
141
|
this.#module.logger.info(`├─ Successfully registered global commands. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
|
|
146
142
|
}
|
|
147
143
|
for (const guildId in apiPrivateCommands) {
|
|
148
|
-
await this.#rest.put(
|
|
144
|
+
await this.#rest.put(Routes.applicationGuildCommands(this.#client.user.id, guildId), { body: apiPrivateCommands[guildId] });
|
|
149
145
|
this.#module.logger.info(`├─ Successfully registered private commands in ${guildId}. (${(Date.now() - this.#loadStartTimestamp)}ms)`);
|
|
150
146
|
}
|
|
151
147
|
this.#module.logger.info("└─ Successfully deployed all commands.");
|
|
@@ -163,17 +159,17 @@ class DiscordApp {
|
|
|
163
159
|
* @internal
|
|
164
160
|
*/
|
|
165
161
|
#chatInputCommandHandler(itr) {
|
|
166
|
-
const commands = this.#commands.filter(i => Reflect.getMetadata(
|
|
162
|
+
const commands = this.#commands.filter(i => Reflect.getMetadata(INTERACTION_TYPE_KEY, i) == InteractionType.CHAT_INPUT_COMMAND);
|
|
167
163
|
const commandName = itr.commandName;
|
|
168
|
-
const command = commands.find(c => Reflect.getMetadata(
|
|
164
|
+
const command = commands.find(c => Reflect.getMetadata(COMMAND_NAME_KEY, c) == commandName);
|
|
169
165
|
if (!command)
|
|
170
166
|
return;
|
|
171
167
|
if (itr.options.getSubcommandGroup(false)) {
|
|
172
|
-
let handler = Reflect.getMetadata(
|
|
168
|
+
let handler = Reflect.getMetadata(COMMAND_SUBCOMMAND_GROUPS_KEY, command)[itr.options.getSubcommandGroup(true)]?.find(c => Reflect.getMetadata(COMMAND_NAME_KEY, c) == itr.options.getSubcommand(true));
|
|
173
169
|
if (!handler)
|
|
174
170
|
return;
|
|
175
|
-
let runMethod = Reflect.getMetadata(
|
|
176
|
-
let preArgs = [Reflect.getMetadata(
|
|
171
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, handler);
|
|
172
|
+
let preArgs = [Reflect.getMetadata(INTERACTION_PARAMETER_INDEX_KEY, handler), ...(Reflect.getMetadata(OPTIONS_PARAMETER_INDEX_KEY, handler) || [])];
|
|
177
173
|
let args = Array(preArgs.length).fill(null);
|
|
178
174
|
if (runMethod == undefined)
|
|
179
175
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
@@ -187,11 +183,11 @@ class DiscordApp {
|
|
|
187
183
|
cmd[runMethod]();
|
|
188
184
|
}
|
|
189
185
|
else if (itr.options.getSubcommand(false)) {
|
|
190
|
-
let handler = Reflect.getMetadata(
|
|
186
|
+
let handler = Reflect.getMetadata(COMMAND_SUBCOMMANDS_KEY, command).find(c => Reflect.getMetadata(COMMAND_NAME_KEY, c) == itr.options.getSubcommand(true));
|
|
191
187
|
if (!handler)
|
|
192
188
|
return;
|
|
193
|
-
let runMethod = Reflect.getMetadata(
|
|
194
|
-
let preArgs = [Reflect.getMetadata(
|
|
189
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, handler);
|
|
190
|
+
let preArgs = [Reflect.getMetadata(INTERACTION_PARAMETER_INDEX_KEY, handler), ...(Reflect.getMetadata(OPTIONS_PARAMETER_INDEX_KEY, handler) || [])];
|
|
195
191
|
let args = Array(preArgs.length).fill(null);
|
|
196
192
|
if (runMethod == undefined)
|
|
197
193
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
@@ -205,8 +201,8 @@ class DiscordApp {
|
|
|
205
201
|
cmd[runMethod]();
|
|
206
202
|
}
|
|
207
203
|
else {
|
|
208
|
-
let runMethod = Reflect.getMetadata(
|
|
209
|
-
let preArgs = [Reflect.getMetadata(
|
|
204
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, command);
|
|
205
|
+
let preArgs = [Reflect.getMetadata(INTERACTION_PARAMETER_INDEX_KEY, command), ...(Reflect.getMetadata(OPTIONS_PARAMETER_INDEX_KEY, command) || [])];
|
|
210
206
|
let args = Array(preArgs.length).fill(null);
|
|
211
207
|
if (runMethod == undefined)
|
|
212
208
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
@@ -227,12 +223,12 @@ class DiscordApp {
|
|
|
227
223
|
* @internal
|
|
228
224
|
*/
|
|
229
225
|
#contextMenuCommandHandler(itr) {
|
|
230
|
-
const commands = this.#commands.filter(i => Reflect.getMetadata(
|
|
226
|
+
const commands = this.#commands.filter(i => Reflect.getMetadata(INTERACTION_TYPE_KEY, i) == InteractionType.CONTEXT_MENU_COMMAND);
|
|
231
227
|
const commandName = itr.commandName;
|
|
232
|
-
const command = commands.find(c => Reflect.getMetadata(
|
|
228
|
+
const command = commands.find(c => Reflect.getMetadata(COMMAND_NAME_KEY, c) == commandName && Reflect.getMetadata(COMMAND_OPTIONS_KEY, c).type == itr.commandType);
|
|
233
229
|
if (!command)
|
|
234
230
|
return;
|
|
235
|
-
let runMethod = Reflect.getMetadata(
|
|
231
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, command);
|
|
236
232
|
if (runMethod == undefined)
|
|
237
233
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
238
234
|
let cmd = new command(itr);
|
|
@@ -245,10 +241,10 @@ class DiscordApp {
|
|
|
245
241
|
* @internal
|
|
246
242
|
*/
|
|
247
243
|
#buttonHandler(itr) {
|
|
248
|
-
const button = this.#buttons.find(b => Reflect.getMetadata(
|
|
244
|
+
const button = this.#buttons.find(b => Reflect.getMetadata(BUTTON_OPTIONS_KEY, b).customId == itr.customId);
|
|
249
245
|
if (!button)
|
|
250
246
|
return;
|
|
251
|
-
let runMethod = Reflect.getMetadata(
|
|
247
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, button);
|
|
252
248
|
if (runMethod == undefined)
|
|
253
249
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
254
250
|
let cmd = new button(itr);
|
|
@@ -261,10 +257,10 @@ class DiscordApp {
|
|
|
261
257
|
* @internal
|
|
262
258
|
*/
|
|
263
259
|
#selectMenuHandler(itr) {
|
|
264
|
-
const selectMenu = this.#selectMenus.find(b => Reflect.getMetadata(
|
|
260
|
+
const selectMenu = this.#selectMenus.find(b => Reflect.getMetadata(SELECT_MENU_OPTIONS_KEY, b).customId == itr.customId);
|
|
265
261
|
if (!selectMenu)
|
|
266
262
|
return;
|
|
267
|
-
let runMethod = Reflect.getMetadata(
|
|
263
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, selectMenu);
|
|
268
264
|
if (runMethod == undefined)
|
|
269
265
|
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
270
266
|
let cmd = new selectMenu(itr);
|
|
@@ -277,12 +273,12 @@ class DiscordApp {
|
|
|
277
273
|
* @internal
|
|
278
274
|
*/
|
|
279
275
|
#modalHandler(itr) {
|
|
280
|
-
const modal = this.#modals.find(b => Reflect.getMetadata(
|
|
276
|
+
const modal = this.#modals.find(b => Reflect.getMetadata(MODAL_OPTIONS_KEY, b).customId == itr.customId);
|
|
281
277
|
if (!modal)
|
|
282
278
|
return;
|
|
283
|
-
const modalComponents = Reflect.getMetadata(
|
|
284
|
-
let runMethod = Reflect.getMetadata(
|
|
285
|
-
let preArgs = [Reflect.getMetadata(
|
|
279
|
+
const modalComponents = Reflect.getMetadata(MODAL_COMPONENTS_KEY, modal);
|
|
280
|
+
let runMethod = Reflect.getMetadata(INTERACTION_RUN_METHOD_KEY, modal);
|
|
281
|
+
let preArgs = [Reflect.getMetadata(INTERACTION_PARAMETER_INDEX_KEY, modal), ...(Reflect.getMetadata(MODAL_TEXT_INPUT_VALUE_INDEX_KEY, modal) || []), ...(Reflect.getMetadata(MODAL_SELECT_MENU_VALUE_INDEX_KEY, modal) || []), ...(Reflect.getMetadata(MODAL_FILE_UPLOAD_VALUE_INDEX_KEY, modal) || [])];
|
|
286
282
|
let args = Array(preArgs.length).fill(null);
|
|
287
283
|
preArgs.forEach(arg => {
|
|
288
284
|
if (typeof arg == "number") {
|
|
@@ -300,17 +296,14 @@ class DiscordApp {
|
|
|
300
296
|
"user_select": itr.fields.getSelectedUsers,
|
|
301
297
|
"role_select": itr.fields.getSelectedRoles,
|
|
302
298
|
"mentionable_select": itr.fields.getSelectedMentionables,
|
|
303
|
-
"channel_select": itr.fields.getSelectedChannels
|
|
304
|
-
"radio_group": itr.fields.getRadioGroup,
|
|
305
|
-
"checkbox_group": itr.fields.getCheckboxGroup,
|
|
306
|
-
"checkbox": itr.fields.getCheckbox
|
|
299
|
+
"channel_select": itr.fields.getSelectedChannels
|
|
307
300
|
};
|
|
308
301
|
const label = modalComponents.find(c => c.outerType == "label" && c.innerType.endsWith("select") && c.component.data.component?.data?.custom_id == fieldIndex.customId);
|
|
309
302
|
const getMethod = getMethods[label?.innerType];
|
|
310
303
|
if (!getMethod)
|
|
311
304
|
throw new TypeError(`Failed to get the select menu values for custom ID ${fieldIndex.customId}. Failed to gather necessary metadata.`);
|
|
312
305
|
const result = getMethod.bind(itr.fields)(fieldIndex.customId);
|
|
313
|
-
if (result instanceof
|
|
306
|
+
if (result instanceof Collection)
|
|
314
307
|
args[arg.index] = result.toJSON();
|
|
315
308
|
else
|
|
316
309
|
args[arg.index] = result;
|
|
@@ -318,13 +311,23 @@ class DiscordApp {
|
|
|
318
311
|
case "file_upload":
|
|
319
312
|
args[arg.index] = itr.fields.getUploadedFiles(fieldIndex.customId);
|
|
320
313
|
break;
|
|
314
|
+
case "radio_group":
|
|
315
|
+
args[arg.index] = itr.fields.getRadioGroup(fieldIndex.customId);
|
|
316
|
+
break;
|
|
317
|
+
case "checkbox":
|
|
318
|
+
args[arg.index] = itr.fields.getCheckbox(fieldIndex.customId);
|
|
319
|
+
break;
|
|
320
|
+
case "checkbox_group":
|
|
321
|
+
args[arg.index] = itr.fields.getCheckboxGroup(fieldIndex.customId);
|
|
322
|
+
break;
|
|
321
323
|
}
|
|
322
324
|
}
|
|
323
325
|
});
|
|
324
|
-
if (runMethod == undefined)
|
|
325
|
-
throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
326
|
+
// if (runMethod == undefined) throw new TypeError("Failed to get the run method. Did you add the @Run decorator?");
|
|
326
327
|
let cmd = new modal(...args);
|
|
327
|
-
|
|
328
|
+
if (runMethod) {
|
|
329
|
+
cmd[runMethod]();
|
|
330
|
+
}
|
|
328
331
|
}
|
|
329
332
|
/**
|
|
330
333
|
* 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.
|
|
@@ -355,52 +358,63 @@ class DiscordApp {
|
|
|
355
358
|
* @internal
|
|
356
359
|
*/
|
|
357
360
|
#init() {
|
|
358
|
-
const options = Reflect.getMetadata(
|
|
359
|
-
const internalEvents = Reflect.getMetadata(
|
|
361
|
+
const options = Reflect.getMetadata(DICSORD_MODULE_OPTIONS_KEY, this.#moduleFunction);
|
|
362
|
+
const internalEvents = Reflect.getMetadata(INTERNAL_EVENTS_KEY, this.#moduleFunction);
|
|
360
363
|
// const externalEvents = Reflect.getMetadata(DISCORD_MODULE_EXTERNAL_EVENTS_KEY, this.#moduleFunction) as ExternalModuleEvents[];
|
|
361
|
-
this.#client = new
|
|
364
|
+
this.#client = new Client(options);
|
|
362
365
|
this.#module = new this.#moduleFunction(this.#client, this.#appOptions.logger);
|
|
363
366
|
this.#moduleOptions = options;
|
|
367
|
+
this.#commands = [];
|
|
368
|
+
this.#buttons = [];
|
|
369
|
+
this.#selectMenus = [];
|
|
370
|
+
this.#modals = [];
|
|
364
371
|
const module = this.#module;
|
|
365
372
|
internalEvents.forEach(e => {
|
|
366
373
|
this.#client.on(e.eventName, (...args) => module[e.methodName](...args));
|
|
367
374
|
});
|
|
368
375
|
this.#client.on("interactionCreate", (itr) => this.#autoHandler(itr));
|
|
369
376
|
this.#moduleOptions.imports.forEach(module => {
|
|
370
|
-
const moduleType = Reflect.getMetadata(
|
|
377
|
+
const moduleType = Reflect.getMetadata(MODULE_TYPE_KEY, module);
|
|
371
378
|
switch (moduleType) {
|
|
372
|
-
case
|
|
373
|
-
|
|
374
|
-
this.#commands = [];
|
|
375
|
-
this.#commands.push(...Reflect.getMetadata(Constants_1.COMMAND_MODULE_COMMANDS_KEY, module));
|
|
379
|
+
case ModuleType.COMMAND:
|
|
380
|
+
this.#commands.push(...Reflect.getMetadata(COMMAND_MODULE_COMMANDS_KEY, module));
|
|
376
381
|
break;
|
|
377
|
-
case
|
|
378
|
-
const components = Reflect.getMetadata(
|
|
379
|
-
const buttons = components.filter(c => Reflect.getMetadata(
|
|
380
|
-
const selectMenus = components.filter(c => Reflect.getMetadata(
|
|
381
|
-
const modals = components.filter(c => Reflect.getMetadata(
|
|
382
|
-
if (!this.#buttons)
|
|
383
|
-
this.#buttons = [];
|
|
382
|
+
case ModuleType.MESSAGE_COMPONENT:
|
|
383
|
+
const components = Reflect.getMetadata(MESSAGE_COMPONENT_MODULE_COMPONENTS_KEY, module);
|
|
384
|
+
const buttons = components.filter(c => Reflect.getMetadata(INTERACTION_TYPE_KEY, c) == InteractionType.BUTTON);
|
|
385
|
+
const selectMenus = components.filter(c => Reflect.getMetadata(INTERACTION_TYPE_KEY, c) == InteractionType.SELECT_MENU);
|
|
386
|
+
const modals = components.filter(c => Reflect.getMetadata(INTERACTION_TYPE_KEY, c) == InteractionType.MODAL_SUBMIT);
|
|
384
387
|
this.#buttons.push(...buttons);
|
|
385
|
-
if (!this.#selectMenus)
|
|
386
|
-
this.#selectMenus = [];
|
|
387
388
|
this.#selectMenus.push(...selectMenus);
|
|
388
|
-
if (!this.#modals)
|
|
389
|
-
this.#modals = [];
|
|
390
389
|
this.#modals.push(...modals);
|
|
391
390
|
break;
|
|
391
|
+
case ModuleType.EVENT:
|
|
392
|
+
const moduleEvents = (Reflect.getMetadata(INTERNAL_EVENTS_KEY, module) ?? []);
|
|
393
|
+
moduleEvents.forEach(e => {
|
|
394
|
+
const moduleInstance = new module(this.#client, this.#appOptions.logger);
|
|
395
|
+
this.#client.on(e.eventName, (...args) => moduleInstance[e.methodName](...args));
|
|
396
|
+
});
|
|
397
|
+
const listeners = (Reflect.getMetadata(EVENT_MODULE_LISTENERS_KEY, module) ?? []);
|
|
398
|
+
listeners.forEach(listener => {
|
|
399
|
+
const listenerInstance = new listener(this.#client, this.#appOptions.logger);
|
|
400
|
+
const listenerEvents = (Reflect.getMetadata(INTERNAL_EVENTS_KEY, listener) ?? []);
|
|
401
|
+
listenerEvents.forEach(e => {
|
|
402
|
+
this.#client.on(e.eventName, (...args) => listenerInstance[e.methodName](...args));
|
|
403
|
+
});
|
|
404
|
+
});
|
|
392
405
|
}
|
|
406
|
+
;
|
|
393
407
|
});
|
|
394
408
|
}
|
|
395
409
|
#setModule(discordModule) {
|
|
396
410
|
this.#moduleFunction = discordModule;
|
|
397
411
|
}
|
|
398
412
|
#setOptions(options) {
|
|
399
|
-
this.#appOptions =
|
|
413
|
+
this.#appOptions = Util.mergeDefault(defaultDiscordAppOptions, options);
|
|
400
414
|
}
|
|
401
415
|
#mapSlashCommand(name, description, options = [], integrationTypes = []) {
|
|
402
416
|
const requiredOptions = options.filter(o => o.required);
|
|
403
|
-
const data = new
|
|
417
|
+
const data = new SlashCommandBuilder()
|
|
404
418
|
.setName(name)
|
|
405
419
|
.setDescription(description);
|
|
406
420
|
if (integrationTypes.length > 0)
|
|
@@ -410,7 +424,7 @@ class DiscordApp {
|
|
|
410
424
|
return data.toJSON();
|
|
411
425
|
}
|
|
412
426
|
#mapContextMenuCommand(name, type, integrationTypes = []) {
|
|
413
|
-
const data = new
|
|
427
|
+
const data = new ContextMenuCommandBuilder()
|
|
414
428
|
.setName(name)
|
|
415
429
|
.setType(type);
|
|
416
430
|
if (integrationTypes.length > 0)
|
|
@@ -445,4 +459,3 @@ class DiscordApp {
|
|
|
445
459
|
return app;
|
|
446
460
|
}
|
|
447
461
|
}
|
|
448
|
-
exports.DiscordApp = DiscordApp;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
const __1 = require("..");
|
|
6
|
-
const Util_1 = require("../../utils/Util");
|
|
1
|
+
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
|
2
|
+
import { BUTTON_OPTIONS_KEY } from "..";
|
|
3
|
+
import { Util } from "../../utils/Util";
|
|
7
4
|
/**
|
|
8
5
|
* 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.
|
|
9
6
|
*
|
|
@@ -29,21 +26,21 @@ const Util_1 = require("../../utils/Util");
|
|
|
29
26
|
* }
|
|
30
27
|
* ```
|
|
31
28
|
*/
|
|
32
|
-
class BaseButton {
|
|
29
|
+
export class BaseButton {
|
|
33
30
|
static options;
|
|
34
31
|
static button = null;
|
|
35
32
|
/** Returns {@link ButtonBuilder} that was created from the button options. */
|
|
36
33
|
static getButton() {
|
|
37
34
|
if (this.button)
|
|
38
35
|
return this.button;
|
|
39
|
-
const options = Reflect.getMetadata(
|
|
36
|
+
const options = Reflect.getMetadata(BUTTON_OPTIONS_KEY, this);
|
|
40
37
|
if (!options)
|
|
41
38
|
throw new TypeError("Failed to get the button.");
|
|
42
39
|
this.options = options;
|
|
43
40
|
const button = create(options);
|
|
44
41
|
this.button = button;
|
|
45
42
|
// Return a copy of the button to prevent accidental mutations to the original button stored in the class.
|
|
46
|
-
return
|
|
43
|
+
return ButtonBuilder.from(button.toJSON());
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
46
|
* Returns a new {@link ButtonBuilder} with the specified options merged with the default options defined in the class.
|
|
@@ -51,23 +48,22 @@ class BaseButton {
|
|
|
51
48
|
* @param options The options to merge with the default options.
|
|
52
49
|
*/
|
|
53
50
|
static override(options) {
|
|
54
|
-
const currentOptions = this.options ?? Reflect.getMetadata(
|
|
51
|
+
const currentOptions = this.options ?? Reflect.getMetadata(BUTTON_OPTIONS_KEY, this);
|
|
55
52
|
if (!currentOptions)
|
|
56
53
|
throw new TypeError("Failed to get the button options.");
|
|
57
|
-
const newOptions =
|
|
54
|
+
const newOptions = Util.mergeDefault(currentOptions, options);
|
|
58
55
|
return create(newOptions);
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
exports.BaseButton = BaseButton;
|
|
62
58
|
function create(options) {
|
|
63
|
-
const button = new
|
|
64
|
-
if (options.style ==
|
|
59
|
+
const button = new ButtonBuilder();
|
|
60
|
+
if (options.style == ButtonStyle.Premium) {
|
|
65
61
|
button
|
|
66
62
|
.setStyle(options.style)
|
|
67
63
|
.setSKUId(options.skuId);
|
|
68
64
|
return button;
|
|
69
65
|
}
|
|
70
|
-
if (options.style ==
|
|
66
|
+
if (options.style == ButtonStyle.Link) {
|
|
71
67
|
button
|
|
72
68
|
.setStyle(options.style)
|
|
73
69
|
.setURL(options.url);
|