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