@open-discord-bots/framework 0.2.17 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +16 -15
- package/dist/api/index.js +16 -15
- package/dist/api/main.d.ts +31 -23
- package/dist/api/main.js +3 -1
- package/dist/api/modules/action.d.ts +2 -2
- package/dist/api/modules/action.js +1 -5
- package/dist/api/modules/base.d.ts +29 -11
- package/dist/api/modules/base.js +78 -80
- package/dist/api/modules/builder.d.ts +2 -11
- package/dist/api/modules/builder.js +0 -4
- package/dist/api/modules/checker.d.ts +28 -7
- package/dist/api/modules/checker.js +33 -37
- package/dist/api/modules/client.d.ts +66 -14
- package/dist/api/modules/client.js +146 -132
- package/dist/api/modules/component.d.ts +928 -0
- package/dist/api/modules/component.js +1346 -0
- package/dist/api/modules/config.d.ts +30 -2
- package/dist/api/modules/config.js +90 -7
- package/dist/api/modules/console.d.ts +16 -4
- package/dist/api/modules/console.js +25 -25
- package/dist/api/modules/cooldown.d.ts +5 -5
- package/dist/api/modules/cooldown.js +1 -17
- package/dist/api/modules/database.d.ts +21 -13
- package/dist/api/modules/database.js +0 -23
- package/dist/api/modules/event.d.ts +4 -2
- package/dist/api/modules/event.js +8 -10
- package/dist/api/modules/fuse.d.ts +1 -1
- package/dist/api/modules/helpmenu.d.ts +11 -9
- package/dist/api/modules/helpmenu.js +24 -22
- package/dist/api/modules/language.d.ts +4 -3
- package/dist/api/modules/language.js +9 -16
- package/dist/api/modules/permission.d.ts +10 -1
- package/dist/api/modules/permission.js +17 -20
- package/dist/api/modules/plugin.d.ts +2 -1
- package/dist/api/modules/plugin.js +2 -2
- package/dist/api/modules/post.d.ts +12 -4
- package/dist/api/modules/post.js +36 -10
- package/dist/api/modules/progressbar.d.ts +18 -6
- package/dist/api/modules/progressbar.js +35 -35
- package/dist/api/modules/responder.d.ts +97 -28
- package/dist/api/modules/responder.js +213 -176
- package/dist/api/modules/session.d.ts +11 -2
- package/dist/api/modules/session.js +16 -16
- package/dist/api/modules/startscreen.d.ts +2 -3
- package/dist/api/modules/startscreen.js +8 -9
- package/dist/api/modules/statistic.d.ts +2 -1
- package/dist/api/modules/statistic.js +4 -7
- package/dist/api/modules/worker.d.ts +2 -1
- package/dist/api/modules/worker.js +3 -3
- package/package.json +3 -2
- package/src/api/index.ts +16 -15
- package/src/api/main.ts +33 -24
- package/src/api/modules/action.ts +2 -4
- package/src/api/modules/base.ts +77 -79
- package/src/api/modules/builder.ts +2 -14
- package/src/api/modules/checker.ts +36 -37
- package/src/api/modules/client.ts +144 -136
- package/src/api/modules/component.ts +1826 -0
- package/src/api/modules/config.ts +86 -7
- package/src/api/modules/console.ts +25 -25
- package/src/api/modules/cooldown.ts +8 -13
- package/src/api/modules/database.ts +24 -32
- package/src/api/modules/event.ts +6 -10
- package/src/api/modules/fuse.ts +1 -1
- package/src/api/modules/helpmenu.ts +31 -27
- package/src/api/modules/language.ts +11 -16
- package/src/api/modules/permission.ts +17 -20
- package/src/api/modules/plugin.ts +2 -2
- package/src/api/modules/post.ts +31 -10
- package/src/api/modules/progressbar.ts +36 -37
- package/src/api/modules/responder.ts +234 -185
- package/src/api/modules/session.ts +15 -15
- package/src/api/modules/startscreen.ts +9 -10
- package/src/api/modules/statistic.ts +4 -7
- package/src/api/modules/worker.ts +3 -3
- package/src/api/modules/component.txt +0 -350
|
@@ -24,10 +24,6 @@ export class ODResponderImplementation extends ODManagerData {
|
|
|
24
24
|
if (callback)
|
|
25
25
|
this.workers.add(new ODWorker(callbackId ? callbackId : id, priority ?? 0, callback));
|
|
26
26
|
}
|
|
27
|
-
/**Execute all workers & return the result. */
|
|
28
|
-
async respond(instance, origin, params) {
|
|
29
|
-
throw new ODSystemError("Tried to build an unimplemented ODResponderImplementation");
|
|
30
|
-
}
|
|
31
27
|
}
|
|
32
28
|
/**## ODResponderManager `class`
|
|
33
29
|
* This is an Open Discord responder manager.
|
|
@@ -65,6 +61,35 @@ export class ODResponderManager {
|
|
|
65
61
|
this.autocomplete = new ODAutocompleteResponderManager(debug, "autocomplete responder", client);
|
|
66
62
|
}
|
|
67
63
|
}
|
|
64
|
+
/**## ODBaseResponderInstance `class`
|
|
65
|
+
* A base class for creating responder instances.
|
|
66
|
+
*/
|
|
67
|
+
export class ODBaseResponderInstance {
|
|
68
|
+
/**Get the final `messageCreateOptions` from a returned build result from builders/components. */
|
|
69
|
+
getMessageFromBuildResult(build, type) {
|
|
70
|
+
const msgFlags = [];
|
|
71
|
+
let msgData;
|
|
72
|
+
if ('message' in build) {
|
|
73
|
+
//USING BUILDERS (deprecated)
|
|
74
|
+
msgData = build.message;
|
|
75
|
+
if (build.ephemeral)
|
|
76
|
+
msgFlags.push(discord.MessageFlags.Ephemeral);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
//USING COMPONENTS
|
|
80
|
+
msgData = build.msg;
|
|
81
|
+
if (type == "interaction" && build.ephemeral)
|
|
82
|
+
msgFlags.push(discord.MessageFlags.Ephemeral); //disabled with regular messages
|
|
83
|
+
if (build.componentsV2)
|
|
84
|
+
msgFlags.push(discord.MessageFlags.IsComponentsV2);
|
|
85
|
+
if (build.supressEmbeds)
|
|
86
|
+
msgFlags.push(discord.MessageFlags.SuppressEmbeds);
|
|
87
|
+
if (build.supressNotifications)
|
|
88
|
+
msgFlags.push(discord.MessageFlags.SuppressNotifications);
|
|
89
|
+
}
|
|
90
|
+
return Object.assign(msgData, { flags: msgFlags });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
68
93
|
/**## ODCommandResponderManager `class`
|
|
69
94
|
* This is an Open Discord command responder manager.
|
|
70
95
|
*
|
|
@@ -81,35 +106,35 @@ export class ODResponderManager {
|
|
|
81
106
|
*/
|
|
82
107
|
export class ODCommandResponderManager extends ODManager {
|
|
83
108
|
/**An alias to the Open Discord client manager. */
|
|
84
|
-
|
|
109
|
+
client;
|
|
85
110
|
/**The callback executed when the default workers take too much time to reply. */
|
|
86
|
-
|
|
111
|
+
timeoutErrorCallback = null;
|
|
87
112
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
88
|
-
|
|
113
|
+
timeoutMs = null;
|
|
89
114
|
constructor(debug, debugname, client) {
|
|
90
115
|
super(debug, debugname);
|
|
91
|
-
this
|
|
116
|
+
this.client = client;
|
|
92
117
|
}
|
|
93
118
|
/**Set the message to send when the response times out! */
|
|
94
119
|
setTimeoutErrorCallback(callback, ms) {
|
|
95
|
-
this
|
|
96
|
-
this
|
|
120
|
+
this.timeoutErrorCallback = callback;
|
|
121
|
+
this.timeoutMs = ms;
|
|
97
122
|
}
|
|
98
123
|
add(data, overwrite) {
|
|
99
124
|
const res = super.add(data, overwrite);
|
|
100
125
|
//add the callback to the slash command manager
|
|
101
|
-
this
|
|
126
|
+
this.client.slashCommands.onInteraction(data.match, (interaction, cmd) => {
|
|
102
127
|
const newData = this.get(data.id);
|
|
103
128
|
if (!newData)
|
|
104
129
|
return;
|
|
105
|
-
newData.respond(new ODCommandResponderInstance(interaction, cmd, this
|
|
130
|
+
newData.respond(new ODCommandResponderInstance(interaction, cmd, this.timeoutErrorCallback, this.timeoutMs), "slash", {});
|
|
106
131
|
});
|
|
107
132
|
//add the callback to the text command manager
|
|
108
|
-
this
|
|
133
|
+
this.client.textCommands.onInteraction(data.prefix, data.match, (interaction, cmd, options) => {
|
|
109
134
|
const newData = this.get(data.id);
|
|
110
135
|
if (!newData)
|
|
111
136
|
return;
|
|
112
|
-
newData.respond(new ODCommandResponderInstance(interaction, cmd, this
|
|
137
|
+
newData.respond(new ODCommandResponderInstance(interaction, cmd, this.timeoutErrorCallback, this.timeoutMs, options), "text", {});
|
|
113
138
|
});
|
|
114
139
|
return res;
|
|
115
140
|
}
|
|
@@ -130,27 +155,27 @@ export class ODCommandResponderManager extends ODManager {
|
|
|
130
155
|
*/
|
|
131
156
|
export class ODCommandResponderInstanceOptions {
|
|
132
157
|
/**The interaction to get data from. */
|
|
133
|
-
|
|
158
|
+
interaction;
|
|
134
159
|
/**The command which is related to the interaction. */
|
|
135
|
-
|
|
160
|
+
cmd;
|
|
136
161
|
/**A list of options which have been parsed by the text command parser. */
|
|
137
|
-
|
|
162
|
+
options;
|
|
138
163
|
constructor(interaction, cmd, options) {
|
|
139
|
-
this
|
|
140
|
-
this
|
|
141
|
-
this
|
|
164
|
+
this.interaction = interaction;
|
|
165
|
+
this.cmd = cmd;
|
|
166
|
+
this.options = options ?? [];
|
|
142
167
|
}
|
|
143
168
|
getString(name, required) {
|
|
144
|
-
if (this
|
|
169
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
145
170
|
try {
|
|
146
|
-
return this
|
|
171
|
+
return this.interaction.options.getString(name, required);
|
|
147
172
|
}
|
|
148
173
|
catch {
|
|
149
174
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getString() slash command option not found!");
|
|
150
175
|
}
|
|
151
176
|
}
|
|
152
|
-
else if (this
|
|
153
|
-
const opt = this
|
|
177
|
+
else if (this.interaction instanceof discord.Message) {
|
|
178
|
+
const opt = this.options.find((opt) => opt.type == "string" && opt.name == name);
|
|
154
179
|
if (opt && typeof opt.value == "string")
|
|
155
180
|
return opt.value;
|
|
156
181
|
else
|
|
@@ -160,16 +185,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
160
185
|
return null;
|
|
161
186
|
}
|
|
162
187
|
getBoolean(name, required) {
|
|
163
|
-
if (this
|
|
188
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
164
189
|
try {
|
|
165
|
-
return this
|
|
190
|
+
return this.interaction.options.getBoolean(name, required);
|
|
166
191
|
}
|
|
167
192
|
catch {
|
|
168
193
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getBoolean() slash command option not found!");
|
|
169
194
|
}
|
|
170
195
|
}
|
|
171
|
-
else if (this
|
|
172
|
-
const opt = this
|
|
196
|
+
else if (this.interaction instanceof discord.Message) {
|
|
197
|
+
const opt = this.options.find((opt) => opt.type == "boolean" && opt.name == name);
|
|
173
198
|
if (opt && typeof opt.value == "boolean")
|
|
174
199
|
return opt.value;
|
|
175
200
|
else
|
|
@@ -179,16 +204,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
179
204
|
return null;
|
|
180
205
|
}
|
|
181
206
|
getNumber(name, required) {
|
|
182
|
-
if (this
|
|
207
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
183
208
|
try {
|
|
184
|
-
return this
|
|
209
|
+
return this.interaction.options.getNumber(name, required);
|
|
185
210
|
}
|
|
186
211
|
catch {
|
|
187
212
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getNumber() slash command option not found!");
|
|
188
213
|
}
|
|
189
214
|
}
|
|
190
|
-
else if (this
|
|
191
|
-
const opt = this
|
|
215
|
+
else if (this.interaction instanceof discord.Message) {
|
|
216
|
+
const opt = this.options.find((opt) => opt.type == "number" && opt.name == name);
|
|
192
217
|
if (opt && typeof opt.value == "number")
|
|
193
218
|
return opt.value;
|
|
194
219
|
else
|
|
@@ -198,16 +223,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
198
223
|
return null;
|
|
199
224
|
}
|
|
200
225
|
getChannel(name, required) {
|
|
201
|
-
if (this
|
|
226
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
202
227
|
try {
|
|
203
|
-
return this
|
|
228
|
+
return this.interaction.options.getChannel(name, required);
|
|
204
229
|
}
|
|
205
230
|
catch {
|
|
206
231
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getChannel() slash command option not found!");
|
|
207
232
|
}
|
|
208
233
|
}
|
|
209
|
-
else if (this
|
|
210
|
-
const opt = this
|
|
234
|
+
else if (this.interaction instanceof discord.Message) {
|
|
235
|
+
const opt = this.options.find((opt) => opt.type == "channel" && opt.name == name);
|
|
211
236
|
if (opt && (opt.value instanceof discord.TextChannel || opt.value instanceof discord.VoiceChannel || opt.value instanceof discord.StageChannel || opt.value instanceof discord.NewsChannel || opt.value instanceof discord.MediaChannel || opt.value instanceof discord.ForumChannel || opt.value instanceof discord.CategoryChannel))
|
|
212
237
|
return opt.value;
|
|
213
238
|
else
|
|
@@ -217,16 +242,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
217
242
|
return null;
|
|
218
243
|
}
|
|
219
244
|
getRole(name, required) {
|
|
220
|
-
if (this
|
|
245
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
221
246
|
try {
|
|
222
|
-
return this
|
|
247
|
+
return this.interaction.options.getRole(name, required);
|
|
223
248
|
}
|
|
224
249
|
catch {
|
|
225
250
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getRole() slash command option not found!");
|
|
226
251
|
}
|
|
227
252
|
}
|
|
228
|
-
else if (this
|
|
229
|
-
const opt = this
|
|
253
|
+
else if (this.interaction instanceof discord.Message) {
|
|
254
|
+
const opt = this.options.find((opt) => opt.type == "role" && opt.name == name);
|
|
230
255
|
if (opt && opt.value instanceof discord.Role)
|
|
231
256
|
return opt.value;
|
|
232
257
|
else
|
|
@@ -236,16 +261,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
236
261
|
return null;
|
|
237
262
|
}
|
|
238
263
|
getUser(name, required) {
|
|
239
|
-
if (this
|
|
264
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
240
265
|
try {
|
|
241
|
-
return this
|
|
266
|
+
return this.interaction.options.getUser(name, required);
|
|
242
267
|
}
|
|
243
268
|
catch {
|
|
244
269
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getUser() slash command option not found!");
|
|
245
270
|
}
|
|
246
271
|
}
|
|
247
|
-
else if (this
|
|
248
|
-
const opt = this
|
|
272
|
+
else if (this.interaction instanceof discord.Message) {
|
|
273
|
+
const opt = this.options.find((opt) => opt.type == "user" && opt.name == name);
|
|
249
274
|
if (opt && opt.value instanceof discord.User)
|
|
250
275
|
return opt.value;
|
|
251
276
|
else
|
|
@@ -255,9 +280,9 @@ export class ODCommandResponderInstanceOptions {
|
|
|
255
280
|
return null;
|
|
256
281
|
}
|
|
257
282
|
getGuildMember(name, required) {
|
|
258
|
-
if (this
|
|
283
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
259
284
|
try {
|
|
260
|
-
const member = this
|
|
285
|
+
const member = this.interaction.options.getMember(name);
|
|
261
286
|
if (!member && required)
|
|
262
287
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
|
|
263
288
|
return member;
|
|
@@ -266,8 +291,8 @@ export class ODCommandResponderInstanceOptions {
|
|
|
266
291
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
|
|
267
292
|
}
|
|
268
293
|
}
|
|
269
|
-
else if (this
|
|
270
|
-
const opt = this
|
|
294
|
+
else if (this.interaction instanceof discord.Message) {
|
|
295
|
+
const opt = this.options.find((opt) => opt.type == "guildmember" && opt.name == name);
|
|
271
296
|
if (opt && opt.value instanceof discord.GuildMember)
|
|
272
297
|
return opt.value;
|
|
273
298
|
else
|
|
@@ -277,16 +302,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
277
302
|
return null;
|
|
278
303
|
}
|
|
279
304
|
getMentionable(name, required) {
|
|
280
|
-
if (this
|
|
305
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
281
306
|
try {
|
|
282
|
-
return this
|
|
307
|
+
return this.interaction.options.getMentionable(name, required);
|
|
283
308
|
}
|
|
284
309
|
catch {
|
|
285
310
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!");
|
|
286
311
|
}
|
|
287
312
|
}
|
|
288
|
-
else if (this
|
|
289
|
-
const opt = this
|
|
313
|
+
else if (this.interaction instanceof discord.Message) {
|
|
314
|
+
const opt = this.options.find((opt) => opt.type == "mentionable" && opt.name == name);
|
|
290
315
|
if (opt && (opt.value instanceof discord.User || opt.value instanceof discord.GuildMember || opt.value instanceof discord.Role))
|
|
291
316
|
return opt.value;
|
|
292
317
|
else
|
|
@@ -296,34 +321,34 @@ export class ODCommandResponderInstanceOptions {
|
|
|
296
321
|
return null;
|
|
297
322
|
}
|
|
298
323
|
getSubGroup() {
|
|
299
|
-
if (this
|
|
324
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
300
325
|
try {
|
|
301
|
-
return this
|
|
326
|
+
return this.interaction.options.getSubcommandGroup(true);
|
|
302
327
|
}
|
|
303
328
|
catch {
|
|
304
329
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getSubGroup() slash command option not found!");
|
|
305
330
|
}
|
|
306
331
|
}
|
|
307
|
-
else if (this
|
|
332
|
+
else if (this.interaction instanceof discord.Message && this.cmd instanceof ODTextCommand) {
|
|
308
333
|
//0: name, 1:sub/group, 2:sub
|
|
309
|
-
const splittedName = this
|
|
334
|
+
const splittedName = this.cmd.builder.name.split(" ");
|
|
310
335
|
return splittedName[1] ?? null;
|
|
311
336
|
}
|
|
312
337
|
else
|
|
313
338
|
return null;
|
|
314
339
|
}
|
|
315
340
|
getSubCommand() {
|
|
316
|
-
if (this
|
|
341
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
317
342
|
try {
|
|
318
|
-
return this
|
|
343
|
+
return this.interaction.options.getSubcommand(true);
|
|
319
344
|
}
|
|
320
345
|
catch {
|
|
321
346
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getSubCommand() slash command option not found!");
|
|
322
347
|
}
|
|
323
348
|
}
|
|
324
|
-
else if (this
|
|
349
|
+
else if (this.interaction instanceof discord.Message && this.cmd instanceof ODTextCommand) {
|
|
325
350
|
//0: name, 1:sub/group, 2:sub
|
|
326
|
-
const splittedName = this
|
|
351
|
+
const splittedName = this.cmd.builder.name.split(" ");
|
|
327
352
|
//return the second subcommand when there is a subgroup
|
|
328
353
|
if (splittedName.length > 2) {
|
|
329
354
|
return splittedName[2] ?? null;
|
|
@@ -340,7 +365,7 @@ export class ODCommandResponderInstanceOptions {
|
|
|
340
365
|
*
|
|
341
366
|
* An instance is an active slash interaction or used text command. You can reply to the command using `reply()` for both slash & text commands.
|
|
342
367
|
*/
|
|
343
|
-
export class ODCommandResponderInstance {
|
|
368
|
+
export class ODCommandResponderInstance extends ODBaseResponderInstance {
|
|
344
369
|
/**The interaction which is the source of this instance. */
|
|
345
370
|
interaction;
|
|
346
371
|
/**The command wich is the source of this instance. */
|
|
@@ -360,6 +385,7 @@ export class ODCommandResponderInstance {
|
|
|
360
385
|
/**The channel where this command was triggered. */
|
|
361
386
|
channel;
|
|
362
387
|
constructor(interaction, cmd, errorCallback, timeoutMs, options) {
|
|
388
|
+
super();
|
|
363
389
|
if (!interaction.channel)
|
|
364
390
|
throw new ODSystemError("ODCommandResponderInstance: Unable to find interaction channel!");
|
|
365
391
|
this.interaction = interaction;
|
|
@@ -374,12 +400,18 @@ export class ODCommandResponderInstance {
|
|
|
374
400
|
if (!this.didReply) {
|
|
375
401
|
try {
|
|
376
402
|
if (!errorCallback) {
|
|
377
|
-
this.reply({ id: new ODId("
|
|
403
|
+
this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
|
|
378
404
|
content: ":x: **Something went wrong while replying to this command!**"
|
|
379
405
|
} });
|
|
380
406
|
}
|
|
381
407
|
else {
|
|
382
|
-
await errorCallback(this, (this.type == "interaction") ? "slash" : "text");
|
|
408
|
+
const errorResponse = await errorCallback(this, (this.type == "interaction") ? "slash" : "text");
|
|
409
|
+
//auto-delete timeout error message after 5sec when text-based
|
|
410
|
+
if (errorResponse.success && this.type == "message")
|
|
411
|
+
setTimeout(() => {
|
|
412
|
+
if (errorResponse.message?.deletable)
|
|
413
|
+
errorResponse.message?.delete();
|
|
414
|
+
}, 5000);
|
|
383
415
|
}
|
|
384
416
|
}
|
|
385
417
|
catch (err) {
|
|
@@ -389,23 +421,23 @@ export class ODCommandResponderInstance {
|
|
|
389
421
|
}, timeoutMs ?? 2500);
|
|
390
422
|
}
|
|
391
423
|
/**Reply to this command. */
|
|
392
|
-
async reply(
|
|
424
|
+
async reply(build) {
|
|
393
425
|
try {
|
|
394
|
-
const
|
|
426
|
+
const finalMessage = this.getMessageFromBuildResult(build, this.type);
|
|
395
427
|
if (this.type == "interaction" && this.interaction instanceof discord.ChatInputCommandInteraction) {
|
|
396
428
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
397
|
-
const sent = await this.interaction.editReply(
|
|
429
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
398
430
|
this.didReply = true;
|
|
399
431
|
return { success: true, message: sent };
|
|
400
432
|
}
|
|
401
433
|
else {
|
|
402
|
-
const sent = await this.interaction.reply(
|
|
434
|
+
const sent = await this.interaction.reply(finalMessage);
|
|
403
435
|
this.didReply = true;
|
|
404
436
|
return { success: true, message: await sent.fetch() };
|
|
405
437
|
}
|
|
406
438
|
}
|
|
407
439
|
else if (this.type == "message" && this.interaction instanceof discord.Message && this.interaction.channel.type != discord.ChannelType.GroupDM) {
|
|
408
|
-
const sent = await this.interaction.channel.send(
|
|
440
|
+
const sent = await this.interaction.channel.send(finalMessage);
|
|
409
441
|
this.didReply = true;
|
|
410
442
|
return { success: true, message: sent };
|
|
411
443
|
}
|
|
@@ -471,35 +503,35 @@ export class ODCommandResponder extends ODResponderImplementation {
|
|
|
471
503
|
*/
|
|
472
504
|
export class ODButtonResponderManager extends ODManager {
|
|
473
505
|
/**An alias to the Open Discord client manager. */
|
|
474
|
-
|
|
506
|
+
client;
|
|
475
507
|
/**The callback executed when the default workers take too much time to reply. */
|
|
476
|
-
|
|
508
|
+
timeoutErrorCallback = null;
|
|
477
509
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
478
|
-
|
|
510
|
+
timeoutMs = null;
|
|
479
511
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
480
|
-
|
|
512
|
+
listeners = [];
|
|
481
513
|
constructor(debug, debugname, client) {
|
|
482
514
|
super(debug, debugname);
|
|
483
|
-
this
|
|
484
|
-
this
|
|
515
|
+
this.client = client;
|
|
516
|
+
this.client.client.on("interactionCreate", (interaction) => {
|
|
485
517
|
if (!interaction.isButton())
|
|
486
518
|
return;
|
|
487
|
-
this
|
|
519
|
+
this.listeners.forEach((cb) => cb(interaction));
|
|
488
520
|
});
|
|
489
521
|
}
|
|
490
522
|
/**Set the message to send when the response times out! */
|
|
491
523
|
setTimeoutErrorCallback(callback, ms) {
|
|
492
|
-
this
|
|
493
|
-
this
|
|
524
|
+
this.timeoutErrorCallback = callback;
|
|
525
|
+
this.timeoutMs = ms;
|
|
494
526
|
}
|
|
495
527
|
add(data, overwrite) {
|
|
496
528
|
const res = super.add(data, overwrite);
|
|
497
|
-
this
|
|
529
|
+
this.listeners.push((interaction) => {
|
|
498
530
|
const newData = this.get(data.id);
|
|
499
531
|
if (!newData)
|
|
500
532
|
return;
|
|
501
533
|
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId))
|
|
502
|
-
newData.respond(new ODButtonResponderInstance(interaction, this
|
|
534
|
+
newData.respond(new ODButtonResponderInstance(interaction, this.timeoutErrorCallback, this.timeoutMs), "button", {});
|
|
503
535
|
});
|
|
504
536
|
return res;
|
|
505
537
|
}
|
|
@@ -518,7 +550,7 @@ export class ODButtonResponderManager extends ODManager {
|
|
|
518
550
|
*
|
|
519
551
|
* An instance is an active button interaction. You can reply to the button using `reply()`.
|
|
520
552
|
*/
|
|
521
|
-
export class ODButtonResponderInstance {
|
|
553
|
+
export class ODButtonResponderInstance extends ODBaseResponderInstance {
|
|
522
554
|
/**The interaction which is the source of this instance. */
|
|
523
555
|
interaction;
|
|
524
556
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -534,6 +566,7 @@ export class ODButtonResponderInstance {
|
|
|
534
566
|
/**The message this button originates from. */
|
|
535
567
|
message;
|
|
536
568
|
constructor(interaction, errorCallback, timeoutMs) {
|
|
569
|
+
super();
|
|
537
570
|
if (!interaction.channel)
|
|
538
571
|
throw new ODSystemError("ODButtonResponderInstance: Unable to find interaction channel!");
|
|
539
572
|
this.interaction = interaction;
|
|
@@ -546,7 +579,7 @@ export class ODButtonResponderInstance {
|
|
|
546
579
|
if (!this.didReply) {
|
|
547
580
|
try {
|
|
548
581
|
if (!errorCallback) {
|
|
549
|
-
this.reply({ id: new ODId("
|
|
582
|
+
this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
|
|
550
583
|
content: ":x: **Something went wrong while replying to this button!**"
|
|
551
584
|
} });
|
|
552
585
|
}
|
|
@@ -561,16 +594,16 @@ export class ODButtonResponderInstance {
|
|
|
561
594
|
}, timeoutMs ?? 2500);
|
|
562
595
|
}
|
|
563
596
|
/**Reply to this button. */
|
|
564
|
-
async reply(
|
|
597
|
+
async reply(build) {
|
|
565
598
|
try {
|
|
566
|
-
const
|
|
599
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
567
600
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
568
|
-
const sent = await this.interaction.editReply(
|
|
601
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
569
602
|
this.didReply = true;
|
|
570
603
|
return { success: true, message: sent };
|
|
571
604
|
}
|
|
572
605
|
else {
|
|
573
|
-
const sent = await this.interaction.reply(
|
|
606
|
+
const sent = await this.interaction.reply(finalMessage);
|
|
574
607
|
this.didReply = true;
|
|
575
608
|
return { success: true, message: await sent.fetch() };
|
|
576
609
|
}
|
|
@@ -580,16 +613,16 @@ export class ODButtonResponderInstance {
|
|
|
580
613
|
}
|
|
581
614
|
}
|
|
582
615
|
/**Update the message of this button. */
|
|
583
|
-
async update(
|
|
616
|
+
async update(build) {
|
|
584
617
|
try {
|
|
585
|
-
const
|
|
618
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
586
619
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
587
|
-
const sent = await this.interaction.editReply(
|
|
620
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
588
621
|
this.didReply = true;
|
|
589
622
|
return { success: true, message: await sent.fetch() };
|
|
590
623
|
}
|
|
591
624
|
else {
|
|
592
|
-
const sent = await this.interaction.update(
|
|
625
|
+
const sent = await this.interaction.update(finalMessage);
|
|
593
626
|
this.didReply = true;
|
|
594
627
|
return { success: true, message: await sent.fetch() };
|
|
595
628
|
}
|
|
@@ -674,35 +707,35 @@ export class ODButtonResponder extends ODResponderImplementation {
|
|
|
674
707
|
*/
|
|
675
708
|
export class ODDropdownResponderManager extends ODManager {
|
|
676
709
|
/**An alias to the Open Discord client manager. */
|
|
677
|
-
|
|
710
|
+
client;
|
|
678
711
|
/**The callback executed when the default workers take too much time to reply. */
|
|
679
|
-
|
|
712
|
+
timeoutErrorCallback = null;
|
|
680
713
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
681
|
-
|
|
714
|
+
timeoutMs = null;
|
|
682
715
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
683
|
-
|
|
716
|
+
listeners = [];
|
|
684
717
|
constructor(debug, debugname, client) {
|
|
685
718
|
super(debug, debugname);
|
|
686
|
-
this
|
|
687
|
-
this
|
|
719
|
+
this.client = client;
|
|
720
|
+
this.client.client.on("interactionCreate", (interaction) => {
|
|
688
721
|
if (!interaction.isAnySelectMenu())
|
|
689
722
|
return;
|
|
690
|
-
this
|
|
723
|
+
this.listeners.forEach((cb) => cb(interaction));
|
|
691
724
|
});
|
|
692
725
|
}
|
|
693
726
|
/**Set the message to send when the response times out! */
|
|
694
727
|
setTimeoutErrorCallback(callback, ms) {
|
|
695
|
-
this
|
|
696
|
-
this
|
|
728
|
+
this.timeoutErrorCallback = callback;
|
|
729
|
+
this.timeoutMs = ms;
|
|
697
730
|
}
|
|
698
731
|
add(data, overwrite) {
|
|
699
732
|
const res = super.add(data, overwrite);
|
|
700
|
-
this
|
|
733
|
+
this.listeners.push((interaction) => {
|
|
701
734
|
const newData = this.get(data.id);
|
|
702
735
|
if (!newData)
|
|
703
736
|
return;
|
|
704
737
|
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId))
|
|
705
|
-
newData.respond(new ODDropdownResponderInstance(interaction, this
|
|
738
|
+
newData.respond(new ODDropdownResponderInstance(interaction, this.timeoutErrorCallback, this.timeoutMs), "dropdown", {});
|
|
706
739
|
});
|
|
707
740
|
return res;
|
|
708
741
|
}
|
|
@@ -723,12 +756,12 @@ export class ODDropdownResponderManager extends ODManager {
|
|
|
723
756
|
*/
|
|
724
757
|
export class ODDropdownResponderInstanceValues {
|
|
725
758
|
/**The interaction to get data from. */
|
|
726
|
-
|
|
759
|
+
interaction;
|
|
727
760
|
/**The type of this dropdown. */
|
|
728
|
-
|
|
761
|
+
type;
|
|
729
762
|
constructor(interaction, type) {
|
|
730
|
-
this
|
|
731
|
-
this
|
|
763
|
+
this.interaction = interaction;
|
|
764
|
+
this.type = type;
|
|
732
765
|
if (interaction.isChannelSelectMenu()) {
|
|
733
766
|
interaction.values;
|
|
734
767
|
}
|
|
@@ -736,7 +769,7 @@ export class ODDropdownResponderInstanceValues {
|
|
|
736
769
|
/**Get the selected values. */
|
|
737
770
|
getStringValues() {
|
|
738
771
|
try {
|
|
739
|
-
return this
|
|
772
|
+
return this.interaction.values;
|
|
740
773
|
}
|
|
741
774
|
catch {
|
|
742
775
|
throw new ODSystemError("ODDropdownResponderInstanceValues:getStringValues() invalid values!");
|
|
@@ -744,14 +777,14 @@ export class ODDropdownResponderInstanceValues {
|
|
|
744
777
|
}
|
|
745
778
|
/**Get the selected roles. */
|
|
746
779
|
async getRoleValues() {
|
|
747
|
-
if (this
|
|
780
|
+
if (this.type != "role")
|
|
748
781
|
throw new ODSystemError("ODDropdownResponderInstanceValues:getRoleValues() dropdown type isn't role!");
|
|
749
782
|
try {
|
|
750
783
|
const result = [];
|
|
751
|
-
for (const id of this
|
|
752
|
-
if (!this
|
|
784
|
+
for (const id of this.interaction.values) {
|
|
785
|
+
if (!this.interaction.guild)
|
|
753
786
|
break;
|
|
754
|
-
const role = await this
|
|
787
|
+
const role = await this.interaction.guild.roles.fetch(id);
|
|
755
788
|
if (role)
|
|
756
789
|
result.push(role);
|
|
757
790
|
}
|
|
@@ -763,12 +796,12 @@ export class ODDropdownResponderInstanceValues {
|
|
|
763
796
|
}
|
|
764
797
|
/**Get the selected users. */
|
|
765
798
|
async getUserValues() {
|
|
766
|
-
if (this
|
|
799
|
+
if (this.type != "role")
|
|
767
800
|
throw new ODSystemError("ODDropdownResponderInstanceValues:getUserValues() dropdown type isn't user!");
|
|
768
801
|
try {
|
|
769
802
|
const result = [];
|
|
770
|
-
for (const id of this
|
|
771
|
-
const user = await this
|
|
803
|
+
for (const id of this.interaction.values) {
|
|
804
|
+
const user = await this.interaction.client.users.fetch(id);
|
|
772
805
|
if (user)
|
|
773
806
|
result.push(user);
|
|
774
807
|
}
|
|
@@ -780,14 +813,14 @@ export class ODDropdownResponderInstanceValues {
|
|
|
780
813
|
}
|
|
781
814
|
/**Get the selected channels. */
|
|
782
815
|
async getChannelValues() {
|
|
783
|
-
if (this
|
|
816
|
+
if (this.type != "role")
|
|
784
817
|
throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() dropdown type isn't channel!");
|
|
785
818
|
try {
|
|
786
819
|
const result = [];
|
|
787
|
-
for (const id of this
|
|
788
|
-
if (!this
|
|
820
|
+
for (const id of this.interaction.values) {
|
|
821
|
+
if (!this.interaction.guild)
|
|
789
822
|
break;
|
|
790
|
-
const guild = await this
|
|
823
|
+
const guild = await this.interaction.guild.channels.fetch(id);
|
|
791
824
|
if (guild)
|
|
792
825
|
result.push(guild);
|
|
793
826
|
}
|
|
@@ -803,7 +836,7 @@ export class ODDropdownResponderInstanceValues {
|
|
|
803
836
|
*
|
|
804
837
|
* An instance is an active dropdown interaction. You can reply to the dropdown using `reply()`.
|
|
805
838
|
*/
|
|
806
|
-
export class ODDropdownResponderInstance {
|
|
839
|
+
export class ODDropdownResponderInstance extends ODBaseResponderInstance {
|
|
807
840
|
/**The interaction which is the source of this instance. */
|
|
808
841
|
interaction;
|
|
809
842
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -823,6 +856,7 @@ export class ODDropdownResponderInstance {
|
|
|
823
856
|
/**The message this dropdown originates from. */
|
|
824
857
|
message;
|
|
825
858
|
constructor(interaction, errorCallback, timeoutMs) {
|
|
859
|
+
super();
|
|
826
860
|
if (!interaction.channel)
|
|
827
861
|
throw new ODSystemError("ODDropdownResponderInstance: Unable to find interaction channel!");
|
|
828
862
|
this.interaction = interaction;
|
|
@@ -853,7 +887,7 @@ export class ODDropdownResponderInstance {
|
|
|
853
887
|
if (!this.didReply) {
|
|
854
888
|
try {
|
|
855
889
|
if (!errorCallback) {
|
|
856
|
-
this.reply({ id: new ODId("
|
|
890
|
+
this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
|
|
857
891
|
content: ":x: **Something went wrong while replying to this dropdown!**"
|
|
858
892
|
} });
|
|
859
893
|
}
|
|
@@ -868,16 +902,16 @@ export class ODDropdownResponderInstance {
|
|
|
868
902
|
}, timeoutMs ?? 2500);
|
|
869
903
|
}
|
|
870
904
|
/**Reply to this dropdown. */
|
|
871
|
-
async reply(
|
|
905
|
+
async reply(build) {
|
|
872
906
|
try {
|
|
873
|
-
const
|
|
907
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
874
908
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
875
|
-
const sent = await this.interaction.editReply(
|
|
909
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
876
910
|
this.didReply = true;
|
|
877
911
|
return { success: true, message: sent };
|
|
878
912
|
}
|
|
879
913
|
else {
|
|
880
|
-
const sent = await this.interaction.reply(
|
|
914
|
+
const sent = await this.interaction.reply(finalMessage);
|
|
881
915
|
this.didReply = true;
|
|
882
916
|
return { success: true, message: await sent.fetch() };
|
|
883
917
|
}
|
|
@@ -887,16 +921,16 @@ export class ODDropdownResponderInstance {
|
|
|
887
921
|
}
|
|
888
922
|
}
|
|
889
923
|
/**Update the message of this dropdown. */
|
|
890
|
-
async update(
|
|
924
|
+
async update(build) {
|
|
891
925
|
try {
|
|
892
|
-
const
|
|
926
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
893
927
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
894
|
-
const sent = await this.interaction.editReply(
|
|
928
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
895
929
|
this.didReply = true;
|
|
896
930
|
return { success: true, message: await sent.fetch() };
|
|
897
931
|
}
|
|
898
932
|
else {
|
|
899
|
-
const sent = await this.interaction.update(
|
|
933
|
+
const sent = await this.interaction.update(finalMessage);
|
|
900
934
|
this.didReply = true;
|
|
901
935
|
return { success: true, message: await sent.fetch() };
|
|
902
936
|
}
|
|
@@ -981,35 +1015,35 @@ export class ODDropdownResponder extends ODResponderImplementation {
|
|
|
981
1015
|
*/
|
|
982
1016
|
export class ODModalResponderManager extends ODManager {
|
|
983
1017
|
/**An alias to the Open Discord client manager. */
|
|
984
|
-
|
|
1018
|
+
client;
|
|
985
1019
|
/**The callback executed when the default workers take too much time to reply. */
|
|
986
|
-
|
|
1020
|
+
timeoutErrorCallback = null;
|
|
987
1021
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
988
|
-
|
|
1022
|
+
timeoutMs = null;
|
|
989
1023
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
990
|
-
|
|
1024
|
+
listeners = [];
|
|
991
1025
|
constructor(debug, debugname, client) {
|
|
992
1026
|
super(debug, debugname);
|
|
993
|
-
this
|
|
994
|
-
this
|
|
1027
|
+
this.client = client;
|
|
1028
|
+
this.client.client.on("interactionCreate", (interaction) => {
|
|
995
1029
|
if (!interaction.isModalSubmit())
|
|
996
1030
|
return;
|
|
997
|
-
this
|
|
1031
|
+
this.listeners.forEach((cb) => cb(interaction));
|
|
998
1032
|
});
|
|
999
1033
|
}
|
|
1000
1034
|
/**Set the message to send when the response times out! */
|
|
1001
1035
|
setTimeoutErrorCallback(callback, ms) {
|
|
1002
|
-
this
|
|
1003
|
-
this
|
|
1036
|
+
this.timeoutErrorCallback = callback;
|
|
1037
|
+
this.timeoutMs = ms;
|
|
1004
1038
|
}
|
|
1005
1039
|
add(data, overwrite) {
|
|
1006
1040
|
const res = super.add(data, overwrite);
|
|
1007
|
-
this
|
|
1041
|
+
this.listeners.push((interaction) => {
|
|
1008
1042
|
const newData = this.get(data.id);
|
|
1009
1043
|
if (!newData)
|
|
1010
1044
|
return;
|
|
1011
1045
|
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId))
|
|
1012
|
-
newData.respond(new ODModalResponderInstance(interaction, this
|
|
1046
|
+
newData.respond(new ODModalResponderInstance(interaction, this.timeoutErrorCallback, this.timeoutMs), "modal", {});
|
|
1013
1047
|
});
|
|
1014
1048
|
return res;
|
|
1015
1049
|
}
|
|
@@ -1030,13 +1064,13 @@ export class ODModalResponderManager extends ODManager {
|
|
|
1030
1064
|
*/
|
|
1031
1065
|
export class ODModalResponderInstanceValues {
|
|
1032
1066
|
/**The interaction to get data from. */
|
|
1033
|
-
|
|
1067
|
+
interaction;
|
|
1034
1068
|
constructor(interaction) {
|
|
1035
|
-
this
|
|
1069
|
+
this.interaction = interaction;
|
|
1036
1070
|
}
|
|
1037
1071
|
getTextField(name, required) {
|
|
1038
1072
|
try {
|
|
1039
|
-
const data = this
|
|
1073
|
+
const data = this.interaction.fields.getField(name, discord.ComponentType.TextInput);
|
|
1040
1074
|
if (!data && required)
|
|
1041
1075
|
throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!");
|
|
1042
1076
|
return (data) ? data.value : null;
|
|
@@ -1051,7 +1085,7 @@ export class ODModalResponderInstanceValues {
|
|
|
1051
1085
|
*
|
|
1052
1086
|
* An instance is an active modal interaction. You can reply to the modal using `reply()`.
|
|
1053
1087
|
*/
|
|
1054
|
-
export class ODModalResponderInstance {
|
|
1088
|
+
export class ODModalResponderInstance extends ODBaseResponderInstance {
|
|
1055
1089
|
/**The interaction which is the source of this instance. */
|
|
1056
1090
|
interaction;
|
|
1057
1091
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -1067,6 +1101,7 @@ export class ODModalResponderInstance {
|
|
|
1067
1101
|
/**The channel where this modal was triggered. */
|
|
1068
1102
|
channel;
|
|
1069
1103
|
constructor(interaction, errorCallback, timeoutMs) {
|
|
1104
|
+
super();
|
|
1070
1105
|
this.interaction = interaction;
|
|
1071
1106
|
this.values = new ODModalResponderInstanceValues(interaction);
|
|
1072
1107
|
this.user = interaction.user;
|
|
@@ -1077,7 +1112,7 @@ export class ODModalResponderInstance {
|
|
|
1077
1112
|
if (!this.didReply) {
|
|
1078
1113
|
try {
|
|
1079
1114
|
if (!errorCallback) {
|
|
1080
|
-
this.reply({ id: new ODId("
|
|
1115
|
+
this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
|
|
1081
1116
|
content: ":x: **Something went wrong while replying to this modal!**"
|
|
1082
1117
|
} });
|
|
1083
1118
|
}
|
|
@@ -1092,10 +1127,10 @@ export class ODModalResponderInstance {
|
|
|
1092
1127
|
}, timeoutMs ?? 2500);
|
|
1093
1128
|
}
|
|
1094
1129
|
/**Reply to this modal. */
|
|
1095
|
-
async reply(
|
|
1130
|
+
async reply(build) {
|
|
1096
1131
|
try {
|
|
1097
|
-
const
|
|
1098
|
-
const sent = await this.interaction.followUp(
|
|
1132
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
1133
|
+
const sent = await this.interaction.followUp(finalMessage);
|
|
1099
1134
|
this.didReply = true;
|
|
1100
1135
|
return { success: true, message: sent };
|
|
1101
1136
|
}
|
|
@@ -1104,16 +1139,16 @@ export class ODModalResponderInstance {
|
|
|
1104
1139
|
}
|
|
1105
1140
|
}
|
|
1106
1141
|
/**Update the message of this modal. */
|
|
1107
|
-
async update(
|
|
1142
|
+
async update(build) {
|
|
1108
1143
|
try {
|
|
1109
|
-
const
|
|
1144
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
1110
1145
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
1111
|
-
const sent = await this.interaction.editReply(
|
|
1146
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
1112
1147
|
this.didReply = true;
|
|
1113
1148
|
return { success: true, message: await sent.fetch() };
|
|
1114
1149
|
}
|
|
1115
1150
|
else {
|
|
1116
|
-
const sent = await this.interaction.reply(
|
|
1151
|
+
const sent = await this.interaction.reply(finalMessage);
|
|
1117
1152
|
this.didReply = true;
|
|
1118
1153
|
return { success: true, message: await sent.fetch() };
|
|
1119
1154
|
}
|
|
@@ -1164,27 +1199,27 @@ export class ODModalResponder extends ODResponderImplementation {
|
|
|
1164
1199
|
*/
|
|
1165
1200
|
export class ODContextMenuResponderManager extends ODManager {
|
|
1166
1201
|
/**An alias to the Open Discord client manager. */
|
|
1167
|
-
|
|
1202
|
+
client;
|
|
1168
1203
|
/**The callback executed when the default workers take too much time to reply. */
|
|
1169
|
-
|
|
1204
|
+
timeoutErrorCallback = null;
|
|
1170
1205
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
1171
|
-
|
|
1206
|
+
timeoutMs = null;
|
|
1172
1207
|
constructor(debug, debugname, client) {
|
|
1173
1208
|
super(debug, debugname);
|
|
1174
|
-
this
|
|
1209
|
+
this.client = client;
|
|
1175
1210
|
}
|
|
1176
1211
|
/**Set the message to send when the response times out! */
|
|
1177
1212
|
setTimeoutErrorCallback(callback, ms) {
|
|
1178
|
-
this
|
|
1179
|
-
this
|
|
1213
|
+
this.timeoutErrorCallback = callback;
|
|
1214
|
+
this.timeoutMs = ms;
|
|
1180
1215
|
}
|
|
1181
1216
|
add(data, overwrite) {
|
|
1182
1217
|
const res = super.add(data, overwrite);
|
|
1183
|
-
this
|
|
1218
|
+
this.client.contextMenus.onInteraction(data.match, (interaction, cmd) => {
|
|
1184
1219
|
const newData = this.get(data.id);
|
|
1185
1220
|
if (!newData)
|
|
1186
1221
|
return;
|
|
1187
|
-
newData.respond(new ODContextMenuResponderInstance(interaction, cmd, this
|
|
1222
|
+
newData.respond(new ODContextMenuResponderInstance(interaction, cmd, this.timeoutErrorCallback, this.timeoutMs), "context-menu", {});
|
|
1188
1223
|
});
|
|
1189
1224
|
return res;
|
|
1190
1225
|
}
|
|
@@ -1203,7 +1238,7 @@ export class ODContextMenuResponderManager extends ODManager {
|
|
|
1203
1238
|
*
|
|
1204
1239
|
* An instance is an active context menu interaction. You can reply to the context menu using `reply()`.
|
|
1205
1240
|
*/
|
|
1206
|
-
export class ODContextMenuResponderInstance {
|
|
1241
|
+
export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
|
|
1207
1242
|
/**The interaction which is the source of this instance. */
|
|
1208
1243
|
interaction;
|
|
1209
1244
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -1221,6 +1256,7 @@ export class ODContextMenuResponderInstance {
|
|
|
1221
1256
|
/**The target of this context menu (user or message). */
|
|
1222
1257
|
target;
|
|
1223
1258
|
constructor(interaction, menu, errorCallback, timeoutMs) {
|
|
1259
|
+
super();
|
|
1224
1260
|
if (!interaction.channel)
|
|
1225
1261
|
throw new ODSystemError("ODContextMenuResponderInstance: Unable to find interaction channel!");
|
|
1226
1262
|
this.interaction = interaction;
|
|
@@ -1239,7 +1275,7 @@ export class ODContextMenuResponderInstance {
|
|
|
1239
1275
|
if (!this.didReply) {
|
|
1240
1276
|
try {
|
|
1241
1277
|
if (!errorCallback) {
|
|
1242
|
-
this.reply({ id: new ODId("
|
|
1278
|
+
this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
|
|
1243
1279
|
content: ":x: **Something went wrong while replying to this context menu!**"
|
|
1244
1280
|
} });
|
|
1245
1281
|
}
|
|
@@ -1254,16 +1290,16 @@ export class ODContextMenuResponderInstance {
|
|
|
1254
1290
|
}, timeoutMs ?? 2500);
|
|
1255
1291
|
}
|
|
1256
1292
|
/**Reply to this context menu. */
|
|
1257
|
-
async reply(
|
|
1293
|
+
async reply(build) {
|
|
1258
1294
|
try {
|
|
1259
|
-
const
|
|
1295
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
1260
1296
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
1261
|
-
const sent = await this.interaction.editReply(
|
|
1297
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
1262
1298
|
this.didReply = true;
|
|
1263
1299
|
return { success: true, message: sent };
|
|
1264
1300
|
}
|
|
1265
1301
|
else {
|
|
1266
|
-
const sent = await this.interaction.reply(
|
|
1302
|
+
const sent = await this.interaction.reply(finalMessage);
|
|
1267
1303
|
this.didReply = true;
|
|
1268
1304
|
return { success: true, message: await sent.fetch() };
|
|
1269
1305
|
}
|
|
@@ -1273,11 +1309,11 @@ export class ODContextMenuResponderInstance {
|
|
|
1273
1309
|
}
|
|
1274
1310
|
}
|
|
1275
1311
|
/**Update the message of this context menu. */
|
|
1276
|
-
async update(
|
|
1312
|
+
async update(build) {
|
|
1277
1313
|
try {
|
|
1278
|
-
const
|
|
1314
|
+
const finalMessage = this.getMessageFromBuildResult(build, "interaction");
|
|
1279
1315
|
if (this.interaction.replied || this.interaction.deferred) {
|
|
1280
|
-
const sent = await this.interaction.editReply(
|
|
1316
|
+
const sent = await this.interaction.editReply(finalMessage);
|
|
1281
1317
|
this.didReply = true;
|
|
1282
1318
|
return { success: true, message: await sent.fetch() };
|
|
1283
1319
|
}
|
|
@@ -1335,27 +1371,27 @@ export class ODContextMenuResponder extends ODResponderImplementation {
|
|
|
1335
1371
|
*/
|
|
1336
1372
|
export class ODAutocompleteResponderManager extends ODManager {
|
|
1337
1373
|
/**An alias to the Open Discord client manager. */
|
|
1338
|
-
|
|
1374
|
+
client;
|
|
1339
1375
|
/**The callback executed when the default workers take too much time to reply. */
|
|
1340
|
-
|
|
1376
|
+
timeoutErrorCallback = null;
|
|
1341
1377
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
1342
|
-
|
|
1378
|
+
timeoutMs = null;
|
|
1343
1379
|
constructor(debug, debugname, client) {
|
|
1344
1380
|
super(debug, debugname);
|
|
1345
|
-
this
|
|
1381
|
+
this.client = client;
|
|
1346
1382
|
}
|
|
1347
1383
|
/**Set the message to send when the response times out! */
|
|
1348
1384
|
setTimeoutErrorCallback(callback, ms) {
|
|
1349
|
-
this
|
|
1350
|
-
this
|
|
1385
|
+
this.timeoutErrorCallback = callback;
|
|
1386
|
+
this.timeoutMs = ms;
|
|
1351
1387
|
}
|
|
1352
1388
|
add(data, overwrite) {
|
|
1353
1389
|
const res = super.add(data, overwrite);
|
|
1354
|
-
this
|
|
1390
|
+
this.client.autocompletes.onInteraction(data.cmdMatch, data.match, (interaction) => {
|
|
1355
1391
|
const newData = this.get(data.id);
|
|
1356
1392
|
if (!newData)
|
|
1357
1393
|
return;
|
|
1358
|
-
newData.respond(new ODAutocompleteResponderInstance(interaction, this
|
|
1394
|
+
newData.respond(new ODAutocompleteResponderInstance(interaction, this.timeoutErrorCallback, this.timeoutMs), "autocomplete", {});
|
|
1359
1395
|
});
|
|
1360
1396
|
return res;
|
|
1361
1397
|
}
|
|
@@ -1374,7 +1410,7 @@ export class ODAutocompleteResponderManager extends ODManager {
|
|
|
1374
1410
|
*
|
|
1375
1411
|
* An instance is an active autocomplete interaction. You can reply to the autocomplete using `reply()`.
|
|
1376
1412
|
*/
|
|
1377
|
-
export class ODAutocompleteResponderInstance {
|
|
1413
|
+
export class ODAutocompleteResponderInstance extends ODBaseResponderInstance {
|
|
1378
1414
|
/**The interaction which is the source of this instance. */
|
|
1379
1415
|
interaction;
|
|
1380
1416
|
/**Did a worker already respond to this instance/interaction? */
|
|
@@ -1390,6 +1426,7 @@ export class ODAutocompleteResponderInstance {
|
|
|
1390
1426
|
/**The target slash command option of this autocomplete. */
|
|
1391
1427
|
target;
|
|
1392
1428
|
constructor(interaction, errorCallback, timeoutMs) {
|
|
1429
|
+
super();
|
|
1393
1430
|
if (!interaction.channel)
|
|
1394
1431
|
throw new ODSystemError("ODAutocompleteResponderInstance: Unable to find interaction channel!");
|
|
1395
1432
|
this.interaction = interaction;
|
|
@@ -1400,7 +1437,7 @@ export class ODAutocompleteResponderInstance {
|
|
|
1400
1437
|
this.target = interaction.options.getFocused(true);
|
|
1401
1438
|
setTimeout(async () => {
|
|
1402
1439
|
if (!this.didRespond) {
|
|
1403
|
-
process.emit("uncaughtException", new ODSystemError("Autocomplete responder instance failed to respond
|
|
1440
|
+
process.emit("uncaughtException", new ODSystemError("Autocomplete responder instance failed to respond within 2.5sec!"));
|
|
1404
1441
|
}
|
|
1405
1442
|
}, timeoutMs ?? 2500);
|
|
1406
1443
|
}
|