@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
|
@@ -6,7 +6,8 @@ import * as discord from "discord.js"
|
|
|
6
6
|
import { ODWorkerManager, ODWorkerCallback, ODWorker } from "./worker.js"
|
|
7
7
|
import { ODDebugger } from "./console.js"
|
|
8
8
|
import { ODClientManager, ODContextMenu, ODSlashCommand, ODTextCommand, ODTextCommandInteractionOption } from "./client.js"
|
|
9
|
-
import { ODDropdownData, ODMessageBuildResult,
|
|
9
|
+
import { ODDropdownData, ODMessageBuildResult, ODModalBuildResult } from "./builder.js"
|
|
10
|
+
import { ODMessageComponentBuildResult } from "./component.js"
|
|
10
11
|
|
|
11
12
|
/**## ODResponderImplementation `class`
|
|
12
13
|
* This is an Open Discord responder implementation.
|
|
@@ -34,7 +35,22 @@ export abstract class ODResponderImplementation<Instance,Origin extends string,P
|
|
|
34
35
|
/**## ODResponderTimeoutErrorCallback `type`
|
|
35
36
|
* This is the callback for the responder timeout function. It will be executed when something went wrong or the action takes too much time.
|
|
36
37
|
*/
|
|
37
|
-
export type ODResponderTimeoutErrorCallback<Instance, Origin extends "slash"|"text"|"button"|"dropdown"|"modal"|"other"|"context-menu"|"autocomplete"> = (instance:Instance, origin:Origin) =>
|
|
38
|
+
export type ODResponderTimeoutErrorCallback<Instance, Origin extends "slash"|"text"|"button"|"dropdown"|"modal"|"other"|"context-menu"|"autocomplete"> = (instance:Instance, origin:Origin) => ODResponderSendResult<boolean>|Promise<ODResponderSendResult<boolean>>
|
|
39
|
+
|
|
40
|
+
/**## ODResponderSendResult `type`
|
|
41
|
+
* The result from a sent message using responders. Can be used to edit, view & save the message that got created.
|
|
42
|
+
*/
|
|
43
|
+
export type ODResponderSendResult<InGuild extends boolean> = {
|
|
44
|
+
/**Did the message get sent successfully? */
|
|
45
|
+
success:true,
|
|
46
|
+
/**The message that got sent. */
|
|
47
|
+
message:discord.Message<InGuild>
|
|
48
|
+
} | {
|
|
49
|
+
/**Did the message get sent successfully? */
|
|
50
|
+
success:boolean,
|
|
51
|
+
/**The message that got sent. */
|
|
52
|
+
message:null
|
|
53
|
+
}
|
|
38
54
|
|
|
39
55
|
/**## ODResponderManager `class`
|
|
40
56
|
* This is an Open Discord responder manager.
|
|
@@ -81,6 +97,30 @@ export class ODResponderManager<
|
|
|
81
97
|
}
|
|
82
98
|
}
|
|
83
99
|
|
|
100
|
+
/**## ODBaseResponderInstance `class`
|
|
101
|
+
* A base class for creating responder instances.
|
|
102
|
+
*/
|
|
103
|
+
export abstract class ODBaseResponderInstance {
|
|
104
|
+
/**Get the final `messageCreateOptions` from a returned build result from builders/components. */
|
|
105
|
+
protected getMessageFromBuildResult(build:ODMessageBuildResult|ODMessageComponentBuildResult,type:"interaction"|"message"){
|
|
106
|
+
const msgFlags: number[] = []
|
|
107
|
+
let msgData: discord.MessageCreateOptions
|
|
108
|
+
if ('message' in build){
|
|
109
|
+
//USING BUILDERS (deprecated)
|
|
110
|
+
msgData = build.message
|
|
111
|
+
if (build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral)
|
|
112
|
+
}else{
|
|
113
|
+
//USING COMPONENTS
|
|
114
|
+
msgData = build.msg
|
|
115
|
+
if (type == "interaction" && build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral) //disabled with regular messages
|
|
116
|
+
if (build.componentsV2) msgFlags.push(discord.MessageFlags.IsComponentsV2)
|
|
117
|
+
if (build.supressEmbeds) msgFlags.push(discord.MessageFlags.SuppressEmbeds)
|
|
118
|
+
if (build.supressNotifications) msgFlags.push(discord.MessageFlags.SuppressNotifications)
|
|
119
|
+
}
|
|
120
|
+
return Object.assign(msgData,{flags:msgFlags})
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
84
124
|
/**## ODCommandResponderManagerIdConstraint `type`
|
|
85
125
|
* The constraint/layout for id mappings/interfaces of the `ODCommandResponderManager` class.
|
|
86
126
|
*/
|
|
@@ -102,38 +142,38 @@ export type ODCommandResponderManagerIdConstraint = Record<string,{origin:"slash
|
|
|
102
142
|
*/
|
|
103
143
|
export class ODCommandResponderManager<IdList extends ODCommandResponderManagerIdConstraint = ODCommandResponderManagerIdConstraint> extends ODManager<ODCommandResponder<"slash"|"text",any>> {
|
|
104
144
|
/**An alias to the Open Discord client manager. */
|
|
105
|
-
|
|
145
|
+
private client: ODClientManager
|
|
106
146
|
/**The callback executed when the default workers take too much time to reply. */
|
|
107
|
-
|
|
147
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODCommandResponderInstance,"slash"|"text">|null = null
|
|
108
148
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
109
|
-
|
|
149
|
+
private timeoutMs: number|null = null
|
|
110
150
|
|
|
111
151
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
112
152
|
super(debug,debugname)
|
|
113
|
-
this
|
|
153
|
+
this.client = client
|
|
114
154
|
}
|
|
115
155
|
|
|
116
156
|
/**Set the message to send when the response times out! */
|
|
117
157
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODCommandResponderInstance,"slash"|"text">|null, ms:number|null){
|
|
118
|
-
this
|
|
119
|
-
this
|
|
158
|
+
this.timeoutErrorCallback = callback
|
|
159
|
+
this.timeoutMs = ms
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
add(data:ODCommandResponder<"slash"|"text",any>, overwrite?:boolean){
|
|
123
163
|
const res = super.add(data,overwrite)
|
|
124
164
|
|
|
125
165
|
//add the callback to the slash command manager
|
|
126
|
-
this
|
|
166
|
+
this.client.slashCommands.onInteraction(data.match,(interaction,cmd) => {
|
|
127
167
|
const newData = this.get(data.id)
|
|
128
168
|
if (!newData) return
|
|
129
|
-
newData.respond(new ODCommandResponderInstance(interaction,cmd,this
|
|
169
|
+
newData.respond(new ODCommandResponderInstance(interaction,cmd,this.timeoutErrorCallback,this.timeoutMs),"slash",{})
|
|
130
170
|
})
|
|
131
171
|
|
|
132
172
|
//add the callback to the text command manager
|
|
133
|
-
this
|
|
173
|
+
this.client.textCommands.onInteraction(data.prefix,data.match,(interaction,cmd,options) => {
|
|
134
174
|
const newData = this.get(data.id)
|
|
135
175
|
if (!newData) return
|
|
136
|
-
newData.respond(new ODCommandResponderInstance(interaction,cmd,this
|
|
176
|
+
newData.respond(new ODCommandResponderInstance(interaction,cmd,this.timeoutErrorCallback,this.timeoutMs,options),"text",{})
|
|
137
177
|
})
|
|
138
178
|
|
|
139
179
|
return res
|
|
@@ -168,31 +208,31 @@ export class ODCommandResponderManager<IdList extends ODCommandResponderManagerI
|
|
|
168
208
|
*/
|
|
169
209
|
export class ODCommandResponderInstanceOptions {
|
|
170
210
|
/**The interaction to get data from. */
|
|
171
|
-
|
|
211
|
+
private interaction: discord.ChatInputCommandInteraction|discord.Message
|
|
172
212
|
/**The command which is related to the interaction. */
|
|
173
|
-
|
|
213
|
+
private cmd:ODSlashCommand|ODTextCommand
|
|
174
214
|
/**A list of options which have been parsed by the text command parser. */
|
|
175
|
-
|
|
215
|
+
private options: ODTextCommandInteractionOption[]
|
|
176
216
|
|
|
177
217
|
constructor(interaction:discord.ChatInputCommandInteraction|discord.Message, cmd:ODSlashCommand|ODTextCommand, options?:ODTextCommandInteractionOption[]){
|
|
178
|
-
this
|
|
179
|
-
this
|
|
180
|
-
this
|
|
218
|
+
this.interaction = interaction
|
|
219
|
+
this.cmd = cmd
|
|
220
|
+
this.options = options ?? []
|
|
181
221
|
}
|
|
182
222
|
|
|
183
223
|
/**Get a string option. */
|
|
184
224
|
getString(name:string,required:true): string
|
|
185
225
|
getString(name:string,required:false): string|null
|
|
186
226
|
getString(name:string,required:boolean){
|
|
187
|
-
if (this
|
|
227
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
188
228
|
try {
|
|
189
|
-
return this
|
|
229
|
+
return this.interaction.options.getString(name,required)
|
|
190
230
|
}catch{
|
|
191
231
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getString() slash command option not found!")
|
|
192
232
|
}
|
|
193
233
|
|
|
194
|
-
}else if (this
|
|
195
|
-
const opt = this
|
|
234
|
+
}else if (this.interaction instanceof discord.Message){
|
|
235
|
+
const opt = this.options.find((opt) => opt.type == "string" && opt.name == name)
|
|
196
236
|
if (opt && typeof opt.value == "string") return opt.value
|
|
197
237
|
else return null
|
|
198
238
|
|
|
@@ -202,15 +242,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
202
242
|
getBoolean(name:string,required:true): boolean
|
|
203
243
|
getBoolean(name:string,required:false): boolean|null
|
|
204
244
|
getBoolean(name:string,required:boolean){
|
|
205
|
-
if (this
|
|
245
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
206
246
|
try {
|
|
207
|
-
return this
|
|
247
|
+
return this.interaction.options.getBoolean(name,required)
|
|
208
248
|
}catch{
|
|
209
249
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getBoolean() slash command option not found!")
|
|
210
250
|
}
|
|
211
251
|
|
|
212
|
-
}else if (this
|
|
213
|
-
const opt = this
|
|
252
|
+
}else if (this.interaction instanceof discord.Message){
|
|
253
|
+
const opt = this.options.find((opt) => opt.type == "boolean" && opt.name == name)
|
|
214
254
|
if (opt && typeof opt.value == "boolean") return opt.value
|
|
215
255
|
else return null
|
|
216
256
|
|
|
@@ -220,15 +260,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
220
260
|
getNumber(name:string,required:true): number
|
|
221
261
|
getNumber(name:string,required:false): number|null
|
|
222
262
|
getNumber(name:string,required:boolean){
|
|
223
|
-
if (this
|
|
263
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
224
264
|
try {
|
|
225
|
-
return this
|
|
265
|
+
return this.interaction.options.getNumber(name,required)
|
|
226
266
|
}catch{
|
|
227
267
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getNumber() slash command option not found!")
|
|
228
268
|
}
|
|
229
269
|
|
|
230
|
-
}else if (this
|
|
231
|
-
const opt = this
|
|
270
|
+
}else if (this.interaction instanceof discord.Message){
|
|
271
|
+
const opt = this.options.find((opt) => opt.type == "number" && opt.name == name)
|
|
232
272
|
if (opt && typeof opt.value == "number") return opt.value
|
|
233
273
|
else return null
|
|
234
274
|
|
|
@@ -238,15 +278,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
238
278
|
getChannel(name:string,required:true): discord.TextChannel|discord.VoiceChannel|discord.StageChannel|discord.NewsChannel|discord.MediaChannel|discord.ForumChannel|discord.CategoryChannel
|
|
239
279
|
getChannel(name:string,required:false): discord.TextChannel|discord.VoiceChannel|discord.StageChannel|discord.NewsChannel|discord.MediaChannel|discord.ForumChannel|discord.CategoryChannel|null
|
|
240
280
|
getChannel(name:string,required:boolean){
|
|
241
|
-
if (this
|
|
281
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
242
282
|
try {
|
|
243
|
-
return this
|
|
283
|
+
return this.interaction.options.getChannel(name,required)
|
|
244
284
|
}catch{
|
|
245
285
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getChannel() slash command option not found!")
|
|
246
286
|
}
|
|
247
287
|
|
|
248
|
-
}else if (this
|
|
249
|
-
const opt = this
|
|
288
|
+
}else if (this.interaction instanceof discord.Message){
|
|
289
|
+
const opt = this.options.find((opt) => opt.type == "channel" && opt.name == name)
|
|
250
290
|
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)) return opt.value
|
|
251
291
|
else return null
|
|
252
292
|
|
|
@@ -256,15 +296,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
256
296
|
getRole(name:string,required:true): discord.Role
|
|
257
297
|
getRole(name:string,required:false): discord.Role|null
|
|
258
298
|
getRole(name:string,required:boolean){
|
|
259
|
-
if (this
|
|
299
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
260
300
|
try {
|
|
261
|
-
return this
|
|
301
|
+
return this.interaction.options.getRole(name,required)
|
|
262
302
|
}catch{
|
|
263
303
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getRole() slash command option not found!")
|
|
264
304
|
}
|
|
265
305
|
|
|
266
|
-
}else if (this
|
|
267
|
-
const opt = this
|
|
306
|
+
}else if (this.interaction instanceof discord.Message){
|
|
307
|
+
const opt = this.options.find((opt) => opt.type == "role" && opt.name == name)
|
|
268
308
|
if (opt && opt.value instanceof discord.Role) return opt.value
|
|
269
309
|
else return null
|
|
270
310
|
|
|
@@ -274,15 +314,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
274
314
|
getUser(name:string,required:true): discord.User
|
|
275
315
|
getUser(name:string,required:false): discord.User|null
|
|
276
316
|
getUser(name:string,required:boolean){
|
|
277
|
-
if (this
|
|
317
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
278
318
|
try {
|
|
279
|
-
return this
|
|
319
|
+
return this.interaction.options.getUser(name,required)
|
|
280
320
|
}catch{
|
|
281
321
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getUser() slash command option not found!")
|
|
282
322
|
}
|
|
283
323
|
|
|
284
|
-
}else if (this
|
|
285
|
-
const opt = this
|
|
324
|
+
}else if (this.interaction instanceof discord.Message){
|
|
325
|
+
const opt = this.options.find((opt) => opt.type == "user" && opt.name == name)
|
|
286
326
|
if (opt && opt.value instanceof discord.User) return opt.value
|
|
287
327
|
else return null
|
|
288
328
|
|
|
@@ -292,17 +332,17 @@ export class ODCommandResponderInstanceOptions {
|
|
|
292
332
|
getGuildMember(name:string,required:true): discord.GuildMember
|
|
293
333
|
getGuildMember(name:string,required:false): discord.GuildMember|null
|
|
294
334
|
getGuildMember(name:string,required:boolean){
|
|
295
|
-
if (this
|
|
335
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
296
336
|
try {
|
|
297
|
-
const member = this
|
|
337
|
+
const member = this.interaction.options.getMember(name)
|
|
298
338
|
if (!member && required) throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!")
|
|
299
339
|
return member
|
|
300
340
|
}catch{
|
|
301
341
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!")
|
|
302
342
|
}
|
|
303
343
|
|
|
304
|
-
}else if (this
|
|
305
|
-
const opt = this
|
|
344
|
+
}else if (this.interaction instanceof discord.Message){
|
|
345
|
+
const opt = this.options.find((opt) => opt.type == "guildmember" && opt.name == name)
|
|
306
346
|
if (opt && opt.value instanceof discord.GuildMember) return opt.value
|
|
307
347
|
else return null
|
|
308
348
|
|
|
@@ -312,15 +352,15 @@ export class ODCommandResponderInstanceOptions {
|
|
|
312
352
|
getMentionable(name:string,required:true): discord.User|discord.GuildMember|discord.Role
|
|
313
353
|
getMentionable(name:string,required:false): discord.User|discord.GuildMember|discord.Role|null
|
|
314
354
|
getMentionable(name:string,required:boolean){
|
|
315
|
-
if (this
|
|
355
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
316
356
|
try {
|
|
317
|
-
return this
|
|
357
|
+
return this.interaction.options.getMentionable(name,required)
|
|
318
358
|
}catch{
|
|
319
359
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getGuildMember() slash command option not found!")
|
|
320
360
|
}
|
|
321
361
|
|
|
322
|
-
}else if (this
|
|
323
|
-
const opt = this
|
|
362
|
+
}else if (this.interaction instanceof discord.Message){
|
|
363
|
+
const opt = this.options.find((opt) => opt.type == "mentionable" && opt.name == name)
|
|
324
364
|
if (opt && (opt.value instanceof discord.User || opt.value instanceof discord.GuildMember || opt.value instanceof discord.Role)) return opt.value
|
|
325
365
|
else return null
|
|
326
366
|
|
|
@@ -329,16 +369,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
329
369
|
/**Get a subgroup. */
|
|
330
370
|
getSubGroup(): string|null
|
|
331
371
|
getSubGroup(){
|
|
332
|
-
if (this
|
|
372
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
333
373
|
try {
|
|
334
|
-
return this
|
|
374
|
+
return this.interaction.options.getSubcommandGroup(true)
|
|
335
375
|
}catch{
|
|
336
376
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getSubGroup() slash command option not found!")
|
|
337
377
|
}
|
|
338
378
|
|
|
339
|
-
}else if (this
|
|
379
|
+
}else if (this.interaction instanceof discord.Message && this.cmd instanceof ODTextCommand){
|
|
340
380
|
//0: name, 1:sub/group, 2:sub
|
|
341
|
-
const splittedName: string[] = this
|
|
381
|
+
const splittedName: string[] = this.cmd.builder.name.split(" ")
|
|
342
382
|
return splittedName[1] ?? null
|
|
343
383
|
|
|
344
384
|
}else return null
|
|
@@ -346,16 +386,16 @@ export class ODCommandResponderInstanceOptions {
|
|
|
346
386
|
/**Get a subcommand. */
|
|
347
387
|
getSubCommand(): string|null
|
|
348
388
|
getSubCommand(){
|
|
349
|
-
if (this
|
|
389
|
+
if (this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
350
390
|
try {
|
|
351
|
-
return this
|
|
391
|
+
return this.interaction.options.getSubcommand(true)
|
|
352
392
|
}catch{
|
|
353
393
|
throw new ODSystemError("ODCommandResponderInstanceOptions:getSubCommand() slash command option not found!")
|
|
354
394
|
}
|
|
355
395
|
|
|
356
|
-
}else if (this
|
|
396
|
+
}else if (this.interaction instanceof discord.Message && this.cmd instanceof ODTextCommand){
|
|
357
397
|
//0: name, 1:sub/group, 2:sub
|
|
358
|
-
const splittedName: string[] = this
|
|
398
|
+
const splittedName: string[] = this.cmd.builder.name.split(" ")
|
|
359
399
|
|
|
360
400
|
//return the second subcommand when there is a subgroup
|
|
361
401
|
if (splittedName.length > 2){
|
|
@@ -372,7 +412,7 @@ export class ODCommandResponderInstanceOptions {
|
|
|
372
412
|
*
|
|
373
413
|
* An instance is an active slash interaction or used text command. You can reply to the command using `reply()` for both slash & text commands.
|
|
374
414
|
*/
|
|
375
|
-
export class ODCommandResponderInstance {
|
|
415
|
+
export class ODCommandResponderInstance extends ODBaseResponderInstance {
|
|
376
416
|
/**The interaction which is the source of this instance. */
|
|
377
417
|
interaction: discord.ChatInputCommandInteraction|discord.Message
|
|
378
418
|
/**The command wich is the source of this instance. */
|
|
@@ -393,6 +433,7 @@ export class ODCommandResponderInstance {
|
|
|
393
433
|
channel: discord.TextBasedChannel
|
|
394
434
|
|
|
395
435
|
constructor(interaction:discord.ChatInputCommandInteraction|discord.Message, cmd:ODSlashCommand|ODTextCommand, errorCallback:ODResponderTimeoutErrorCallback<ODCommandResponderInstance,"slash"|"text">|null, timeoutMs:number|null, options?:ODTextCommandInteractionOption[]){
|
|
436
|
+
super()
|
|
396
437
|
if (!interaction.channel) throw new ODSystemError("ODCommandResponderInstance: Unable to find interaction channel!")
|
|
397
438
|
this.interaction = interaction
|
|
398
439
|
this.cmd = cmd
|
|
@@ -408,11 +449,16 @@ export class ODCommandResponderInstance {
|
|
|
408
449
|
if (!this.didReply){
|
|
409
450
|
try {
|
|
410
451
|
if (!errorCallback){
|
|
411
|
-
this.reply({id:new ODId("
|
|
452
|
+
this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
|
|
412
453
|
content:":x: **Something went wrong while replying to this command!**"
|
|
413
454
|
}})
|
|
414
455
|
}else{
|
|
415
|
-
await errorCallback(this,(this.type == "interaction") ? "slash" : "text")
|
|
456
|
+
const errorResponse = await errorCallback(this,(this.type == "interaction") ? "slash" : "text")
|
|
457
|
+
|
|
458
|
+
//auto-delete timeout error message after 5sec when text-based
|
|
459
|
+
if (errorResponse.success && this.type == "message") setTimeout(() => {
|
|
460
|
+
if (errorResponse.message?.deletable) errorResponse.message?.delete()
|
|
461
|
+
},5000)
|
|
416
462
|
}
|
|
417
463
|
|
|
418
464
|
}catch(err){
|
|
@@ -423,21 +469,21 @@ export class ODCommandResponderInstance {
|
|
|
423
469
|
}
|
|
424
470
|
|
|
425
471
|
/**Reply to this command. */
|
|
426
|
-
async reply(
|
|
472
|
+
async reply(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
427
473
|
try {
|
|
428
|
-
const
|
|
474
|
+
const finalMessage = this.getMessageFromBuildResult(build,this.type)
|
|
429
475
|
if (this.type == "interaction" && this.interaction instanceof discord.ChatInputCommandInteraction){
|
|
430
476
|
if (this.interaction.replied || this.interaction.deferred){
|
|
431
|
-
const sent = await this.interaction.editReply(
|
|
477
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
432
478
|
this.didReply = true
|
|
433
479
|
return {success:true,message:sent}
|
|
434
480
|
}else{
|
|
435
|
-
const sent = await this.interaction.reply(
|
|
481
|
+
const sent = await this.interaction.reply(finalMessage)
|
|
436
482
|
this.didReply = true
|
|
437
483
|
return {success:true,message:await sent.fetch()}
|
|
438
484
|
}
|
|
439
485
|
}else if (this.type == "message" && this.interaction instanceof discord.Message && this.interaction.channel.type != discord.ChannelType.GroupDM){
|
|
440
|
-
const sent = await this.interaction.channel.send(
|
|
486
|
+
const sent = await this.interaction.channel.send(finalMessage)
|
|
441
487
|
this.didReply = true
|
|
442
488
|
return {success:true,message:sent}
|
|
443
489
|
}else return {success:false,message:null}
|
|
@@ -505,37 +551,37 @@ export type ODButtonResponderManagerIdConstraint = Record<string,{origin:"button
|
|
|
505
551
|
*/
|
|
506
552
|
export class ODButtonResponderManager<IdList extends ODButtonResponderManagerIdConstraint = ODButtonResponderManagerIdConstraint> extends ODManager<ODButtonResponder<"button",any>> {
|
|
507
553
|
/**An alias to the Open Discord client manager. */
|
|
508
|
-
|
|
554
|
+
private client: ODClientManager
|
|
509
555
|
/**The callback executed when the default workers take too much time to reply. */
|
|
510
|
-
|
|
556
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODButtonResponderInstance,"button">|null = null
|
|
511
557
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
512
|
-
|
|
558
|
+
private timeoutMs: number|null = null
|
|
513
559
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
514
|
-
|
|
560
|
+
private listeners: ((interaction:discord.ButtonInteraction) => void)[] = []
|
|
515
561
|
|
|
516
562
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
517
563
|
super(debug,debugname)
|
|
518
|
-
this
|
|
564
|
+
this.client = client
|
|
519
565
|
|
|
520
|
-
this
|
|
566
|
+
this.client.client.on("interactionCreate",(interaction) => {
|
|
521
567
|
if (!interaction.isButton()) return
|
|
522
|
-
this
|
|
568
|
+
this.listeners.forEach((cb) => cb(interaction))
|
|
523
569
|
})
|
|
524
570
|
}
|
|
525
571
|
|
|
526
572
|
/**Set the message to send when the response times out! */
|
|
527
573
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODButtonResponderInstance,"button">|null, ms:number|null){
|
|
528
|
-
this
|
|
529
|
-
this
|
|
574
|
+
this.timeoutErrorCallback = callback
|
|
575
|
+
this.timeoutMs = ms
|
|
530
576
|
}
|
|
531
577
|
|
|
532
578
|
add(data:ODButtonResponder<"button",any>, overwrite?:boolean){
|
|
533
579
|
const res = super.add(data,overwrite)
|
|
534
580
|
|
|
535
|
-
this
|
|
581
|
+
this.listeners.push((interaction) => {
|
|
536
582
|
const newData = this.get(data.id)
|
|
537
583
|
if (!newData) return
|
|
538
|
-
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODButtonResponderInstance(interaction,this
|
|
584
|
+
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODButtonResponderInstance(interaction,this.timeoutErrorCallback,this.timeoutMs),"button",{})
|
|
539
585
|
})
|
|
540
586
|
|
|
541
587
|
return res
|
|
@@ -568,7 +614,7 @@ export class ODButtonResponderManager<IdList extends ODButtonResponderManagerIdC
|
|
|
568
614
|
*
|
|
569
615
|
* An instance is an active button interaction. You can reply to the button using `reply()`.
|
|
570
616
|
*/
|
|
571
|
-
export class ODButtonResponderInstance {
|
|
617
|
+
export class ODButtonResponderInstance extends ODBaseResponderInstance {
|
|
572
618
|
/**The interaction which is the source of this instance. */
|
|
573
619
|
interaction: discord.ButtonInteraction
|
|
574
620
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -585,6 +631,7 @@ export class ODButtonResponderInstance {
|
|
|
585
631
|
message: discord.Message
|
|
586
632
|
|
|
587
633
|
constructor(interaction:discord.ButtonInteraction, errorCallback:ODResponderTimeoutErrorCallback<ODButtonResponderInstance,"button">|null, timeoutMs:number|null){
|
|
634
|
+
super()
|
|
588
635
|
if (!interaction.channel) throw new ODSystemError("ODButtonResponderInstance: Unable to find interaction channel!")
|
|
589
636
|
this.interaction = interaction
|
|
590
637
|
this.user = interaction.user
|
|
@@ -597,7 +644,7 @@ export class ODButtonResponderInstance {
|
|
|
597
644
|
if (!this.didReply){
|
|
598
645
|
try {
|
|
599
646
|
if (!errorCallback){
|
|
600
|
-
this.reply({id:new ODId("
|
|
647
|
+
this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
|
|
601
648
|
content:":x: **Something went wrong while replying to this button!**"
|
|
602
649
|
}})
|
|
603
650
|
}else{
|
|
@@ -612,15 +659,15 @@ export class ODButtonResponderInstance {
|
|
|
612
659
|
}
|
|
613
660
|
|
|
614
661
|
/**Reply to this button. */
|
|
615
|
-
async reply(
|
|
616
|
-
try{
|
|
617
|
-
const
|
|
662
|
+
async reply(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
663
|
+
try {
|
|
664
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
618
665
|
if (this.interaction.replied || this.interaction.deferred){
|
|
619
|
-
const sent = await this.interaction.editReply(
|
|
666
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
620
667
|
this.didReply = true
|
|
621
668
|
return {success:true,message:sent}
|
|
622
669
|
}else{
|
|
623
|
-
const sent = await this.interaction.reply(
|
|
670
|
+
const sent = await this.interaction.reply(finalMessage)
|
|
624
671
|
this.didReply = true
|
|
625
672
|
return {success:true,message:await sent.fetch()}
|
|
626
673
|
}
|
|
@@ -629,15 +676,15 @@ export class ODButtonResponderInstance {
|
|
|
629
676
|
}
|
|
630
677
|
}
|
|
631
678
|
/**Update the message of this button. */
|
|
632
|
-
async update(
|
|
633
|
-
try{
|
|
634
|
-
const
|
|
679
|
+
async update(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
680
|
+
try {
|
|
681
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
635
682
|
if (this.interaction.replied || this.interaction.deferred){
|
|
636
|
-
const sent = await this.interaction.editReply(
|
|
683
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
637
684
|
this.didReply = true
|
|
638
685
|
return {success:true,message:await sent.fetch()}
|
|
639
686
|
}else{
|
|
640
|
-
const sent = await this.interaction.update(
|
|
687
|
+
const sent = await this.interaction.update(finalMessage)
|
|
641
688
|
this.didReply = true
|
|
642
689
|
return {success:true,message:await sent.fetch()}
|
|
643
690
|
}
|
|
@@ -729,37 +776,37 @@ export type ODDropdownResponderManagerIdConstraint = Record<string,{origin:"drop
|
|
|
729
776
|
*/
|
|
730
777
|
export class ODDropdownResponderManager<IdList extends ODDropdownResponderManagerIdConstraint = ODDropdownResponderManagerIdConstraint> extends ODManager<ODDropdownResponder<"dropdown",any>> {
|
|
731
778
|
/**An alias to the Open Discord client manager. */
|
|
732
|
-
|
|
779
|
+
private client: ODClientManager
|
|
733
780
|
/**The callback executed when the default workers take too much time to reply. */
|
|
734
|
-
|
|
781
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODDropdownResponderInstance,"dropdown">|null = null
|
|
735
782
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
736
|
-
|
|
783
|
+
private timeoutMs: number|null = null
|
|
737
784
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
738
|
-
|
|
785
|
+
private listeners: ((interaction:discord.AnySelectMenuInteraction) => void)[] = []
|
|
739
786
|
|
|
740
787
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
741
788
|
super(debug,debugname)
|
|
742
|
-
this
|
|
789
|
+
this.client = client
|
|
743
790
|
|
|
744
|
-
this
|
|
791
|
+
this.client.client.on("interactionCreate",(interaction) => {
|
|
745
792
|
if (!interaction.isAnySelectMenu()) return
|
|
746
|
-
this
|
|
793
|
+
this.listeners.forEach((cb) => cb(interaction))
|
|
747
794
|
})
|
|
748
795
|
}
|
|
749
796
|
|
|
750
797
|
/**Set the message to send when the response times out! */
|
|
751
798
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODDropdownResponderInstance,"dropdown">|null, ms:number|null){
|
|
752
|
-
this
|
|
753
|
-
this
|
|
799
|
+
this.timeoutErrorCallback = callback
|
|
800
|
+
this.timeoutMs = ms
|
|
754
801
|
}
|
|
755
802
|
|
|
756
803
|
add(data:ODDropdownResponder<"dropdown",any>, overwrite?:boolean){
|
|
757
804
|
const res = super.add(data,overwrite)
|
|
758
805
|
|
|
759
|
-
this
|
|
806
|
+
this.listeners.push((interaction) => {
|
|
760
807
|
const newData = this.get(data.id)
|
|
761
808
|
if (!newData) return
|
|
762
|
-
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODDropdownResponderInstance(interaction,this
|
|
809
|
+
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODDropdownResponderInstance(interaction,this.timeoutErrorCallback,this.timeoutMs),"dropdown",{})
|
|
763
810
|
})
|
|
764
811
|
|
|
765
812
|
return res
|
|
@@ -794,13 +841,13 @@ export class ODDropdownResponderManager<IdList extends ODDropdownResponderManage
|
|
|
794
841
|
*/
|
|
795
842
|
export class ODDropdownResponderInstanceValues {
|
|
796
843
|
/**The interaction to get data from. */
|
|
797
|
-
|
|
844
|
+
private interaction: discord.AnySelectMenuInteraction
|
|
798
845
|
/**The type of this dropdown. */
|
|
799
|
-
|
|
846
|
+
private type: ODDropdownData["type"]
|
|
800
847
|
|
|
801
848
|
constructor(interaction:discord.AnySelectMenuInteraction, type:ODDropdownData["type"]){
|
|
802
|
-
this
|
|
803
|
-
this
|
|
849
|
+
this.interaction = interaction
|
|
850
|
+
this.type = type
|
|
804
851
|
|
|
805
852
|
if (interaction.isChannelSelectMenu()){
|
|
806
853
|
interaction.values
|
|
@@ -810,19 +857,19 @@ export class ODDropdownResponderInstanceValues {
|
|
|
810
857
|
/**Get the selected values. */
|
|
811
858
|
getStringValues(): string[] {
|
|
812
859
|
try {
|
|
813
|
-
return this
|
|
860
|
+
return this.interaction.values
|
|
814
861
|
}catch{
|
|
815
862
|
throw new ODSystemError("ODDropdownResponderInstanceValues:getStringValues() invalid values!")
|
|
816
863
|
}
|
|
817
864
|
}
|
|
818
865
|
/**Get the selected roles. */
|
|
819
866
|
async getRoleValues(): Promise<discord.Role[]> {
|
|
820
|
-
if (this
|
|
867
|
+
if (this.type != "role") throw new ODSystemError("ODDropdownResponderInstanceValues:getRoleValues() dropdown type isn't role!")
|
|
821
868
|
try {
|
|
822
869
|
const result: discord.Role[] = []
|
|
823
|
-
for (const id of this
|
|
824
|
-
if (!this
|
|
825
|
-
const role = await this
|
|
870
|
+
for (const id of this.interaction.values){
|
|
871
|
+
if (!this.interaction.guild) break
|
|
872
|
+
const role = await this.interaction.guild.roles.fetch(id)
|
|
826
873
|
if (role) result.push(role)
|
|
827
874
|
}
|
|
828
875
|
return result
|
|
@@ -832,11 +879,11 @@ export class ODDropdownResponderInstanceValues {
|
|
|
832
879
|
}
|
|
833
880
|
/**Get the selected users. */
|
|
834
881
|
async getUserValues(): Promise<discord.User[]> {
|
|
835
|
-
if (this
|
|
882
|
+
if (this.type != "role") throw new ODSystemError("ODDropdownResponderInstanceValues:getUserValues() dropdown type isn't user!")
|
|
836
883
|
try {
|
|
837
884
|
const result: discord.User[] = []
|
|
838
|
-
for (const id of this
|
|
839
|
-
const user = await this
|
|
885
|
+
for (const id of this.interaction.values){
|
|
886
|
+
const user = await this.interaction.client.users.fetch(id)
|
|
840
887
|
if (user) result.push(user)
|
|
841
888
|
}
|
|
842
889
|
return result
|
|
@@ -846,12 +893,12 @@ export class ODDropdownResponderInstanceValues {
|
|
|
846
893
|
}
|
|
847
894
|
/**Get the selected channels. */
|
|
848
895
|
async getChannelValues(): Promise<discord.GuildBasedChannel[]> {
|
|
849
|
-
if (this
|
|
896
|
+
if (this.type != "role") throw new ODSystemError("ODDropdownResponderInstanceValues:getChannelValues() dropdown type isn't channel!")
|
|
850
897
|
try {
|
|
851
898
|
const result: discord.GuildBasedChannel[] = []
|
|
852
|
-
for (const id of this
|
|
853
|
-
if (!this
|
|
854
|
-
const guild = await this
|
|
899
|
+
for (const id of this.interaction.values){
|
|
900
|
+
if (!this.interaction.guild) break
|
|
901
|
+
const guild = await this.interaction.guild.channels.fetch(id)
|
|
855
902
|
if (guild) result.push(guild)
|
|
856
903
|
}
|
|
857
904
|
return result
|
|
@@ -866,7 +913,7 @@ export class ODDropdownResponderInstanceValues {
|
|
|
866
913
|
*
|
|
867
914
|
* An instance is an active dropdown interaction. You can reply to the dropdown using `reply()`.
|
|
868
915
|
*/
|
|
869
|
-
export class ODDropdownResponderInstance {
|
|
916
|
+
export class ODDropdownResponderInstance extends ODBaseResponderInstance {
|
|
870
917
|
/**The interaction which is the source of this instance. */
|
|
871
918
|
interaction: discord.AnySelectMenuInteraction
|
|
872
919
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -887,6 +934,7 @@ export class ODDropdownResponderInstance {
|
|
|
887
934
|
message: discord.Message
|
|
888
935
|
|
|
889
936
|
constructor(interaction:discord.AnySelectMenuInteraction, errorCallback:ODResponderTimeoutErrorCallback<ODDropdownResponderInstance,"dropdown">|null, timeoutMs:number|null){
|
|
937
|
+
super()
|
|
890
938
|
if (!interaction.channel) throw new ODSystemError("ODDropdownResponderInstance: Unable to find interaction channel!")
|
|
891
939
|
this.interaction = interaction
|
|
892
940
|
if (interaction.isStringSelectMenu()){
|
|
@@ -912,7 +960,7 @@ export class ODDropdownResponderInstance {
|
|
|
912
960
|
if (!this.didReply){
|
|
913
961
|
try {
|
|
914
962
|
if (!errorCallback){
|
|
915
|
-
this.reply({id:new ODId("
|
|
963
|
+
this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
|
|
916
964
|
content:":x: **Something went wrong while replying to this dropdown!**"
|
|
917
965
|
}})
|
|
918
966
|
}else{
|
|
@@ -927,15 +975,15 @@ export class ODDropdownResponderInstance {
|
|
|
927
975
|
}
|
|
928
976
|
|
|
929
977
|
/**Reply to this dropdown. */
|
|
930
|
-
async reply(
|
|
978
|
+
async reply(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
931
979
|
try {
|
|
932
|
-
const
|
|
980
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
933
981
|
if (this.interaction.replied || this.interaction.deferred){
|
|
934
|
-
const sent = await this.interaction.editReply(
|
|
982
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
935
983
|
this.didReply = true
|
|
936
984
|
return {success:true,message:sent}
|
|
937
985
|
}else{
|
|
938
|
-
const sent = await this.interaction.reply(
|
|
986
|
+
const sent = await this.interaction.reply(finalMessage)
|
|
939
987
|
this.didReply = true
|
|
940
988
|
return {success:true,message:await sent.fetch()}
|
|
941
989
|
}
|
|
@@ -944,15 +992,15 @@ export class ODDropdownResponderInstance {
|
|
|
944
992
|
}
|
|
945
993
|
}
|
|
946
994
|
/**Update the message of this dropdown. */
|
|
947
|
-
async update(
|
|
948
|
-
try{
|
|
949
|
-
const
|
|
995
|
+
async update(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
996
|
+
try {
|
|
997
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
950
998
|
if (this.interaction.replied || this.interaction.deferred){
|
|
951
|
-
const sent = await this.interaction.editReply(
|
|
999
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
952
1000
|
this.didReply = true
|
|
953
1001
|
return {success:true,message:await sent.fetch()}
|
|
954
1002
|
}else{
|
|
955
|
-
const sent = await this.interaction.update(
|
|
1003
|
+
const sent = await this.interaction.update(finalMessage)
|
|
956
1004
|
this.didReply = true
|
|
957
1005
|
return {success:true,message:await sent.fetch()}
|
|
958
1006
|
}
|
|
@@ -1044,37 +1092,37 @@ export type ODModalResponderManagerIdConstraint = Record<string,{origin:"modal",
|
|
|
1044
1092
|
*/
|
|
1045
1093
|
export class ODModalResponderManager<IdList extends ODModalResponderManagerIdConstraint = ODModalResponderManagerIdConstraint> extends ODManager<ODModalResponder<"modal",any>> {
|
|
1046
1094
|
/**An alias to the Open Discord client manager. */
|
|
1047
|
-
|
|
1095
|
+
private client: ODClientManager
|
|
1048
1096
|
/**The callback executed when the default workers take too much time to reply. */
|
|
1049
|
-
|
|
1097
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODModalResponderInstance,"modal">|null = null
|
|
1050
1098
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
1051
|
-
|
|
1099
|
+
private timeoutMs: number|null = null
|
|
1052
1100
|
/**A list of listeners which will listen to the raw interactionCreate event from discord.js */
|
|
1053
|
-
|
|
1101
|
+
private listeners: ((interaction:discord.ModalSubmitInteraction) => void)[] = []
|
|
1054
1102
|
|
|
1055
1103
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
1056
1104
|
super(debug,debugname)
|
|
1057
|
-
this
|
|
1105
|
+
this.client = client
|
|
1058
1106
|
|
|
1059
|
-
this
|
|
1107
|
+
this.client.client.on("interactionCreate",(interaction) => {
|
|
1060
1108
|
if (!interaction.isModalSubmit()) return
|
|
1061
|
-
this
|
|
1109
|
+
this.listeners.forEach((cb) => cb(interaction))
|
|
1062
1110
|
})
|
|
1063
1111
|
}
|
|
1064
1112
|
|
|
1065
1113
|
/**Set the message to send when the response times out! */
|
|
1066
1114
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODModalResponderInstance,"modal">|null, ms:number|null){
|
|
1067
|
-
this
|
|
1068
|
-
this
|
|
1115
|
+
this.timeoutErrorCallback = callback
|
|
1116
|
+
this.timeoutMs = ms
|
|
1069
1117
|
}
|
|
1070
1118
|
|
|
1071
1119
|
add(data:ODModalResponder<"modal",any>, overwrite?:boolean){
|
|
1072
1120
|
const res = super.add(data,overwrite)
|
|
1073
1121
|
|
|
1074
|
-
this
|
|
1122
|
+
this.listeners.push((interaction) => {
|
|
1075
1123
|
const newData = this.get(data.id)
|
|
1076
1124
|
if (!newData) return
|
|
1077
|
-
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODModalResponderInstance(interaction,this
|
|
1125
|
+
if ((typeof newData.match == "string") ? interaction.customId == newData.match : newData.match.test(interaction.customId)) newData.respond(new ODModalResponderInstance(interaction,this.timeoutErrorCallback,this.timeoutMs),"modal",{})
|
|
1078
1126
|
})
|
|
1079
1127
|
|
|
1080
1128
|
return res
|
|
@@ -1109,10 +1157,10 @@ export class ODModalResponderManager<IdList extends ODModalResponderManagerIdCon
|
|
|
1109
1157
|
*/
|
|
1110
1158
|
export class ODModalResponderInstanceValues {
|
|
1111
1159
|
/**The interaction to get data from. */
|
|
1112
|
-
|
|
1160
|
+
private interaction: discord.ModalSubmitInteraction
|
|
1113
1161
|
|
|
1114
1162
|
constructor(interaction:discord.ModalSubmitInteraction){
|
|
1115
|
-
this
|
|
1163
|
+
this.interaction = interaction
|
|
1116
1164
|
}
|
|
1117
1165
|
|
|
1118
1166
|
/**Get the value of a text field. */
|
|
@@ -1120,7 +1168,7 @@ export class ODModalResponderInstanceValues {
|
|
|
1120
1168
|
getTextField(name:string,required:false): string|null
|
|
1121
1169
|
getTextField(name:string,required:boolean){
|
|
1122
1170
|
try {
|
|
1123
|
-
const data = this
|
|
1171
|
+
const data = this.interaction.fields.getField(name,discord.ComponentType.TextInput)
|
|
1124
1172
|
if (!data && required) throw new ODSystemError("ODModalResponderInstanceValues:getTextField() field not found!")
|
|
1125
1173
|
return (data) ? data.value : null
|
|
1126
1174
|
}catch{
|
|
@@ -1134,7 +1182,7 @@ export class ODModalResponderInstanceValues {
|
|
|
1134
1182
|
*
|
|
1135
1183
|
* An instance is an active modal interaction. You can reply to the modal using `reply()`.
|
|
1136
1184
|
*/
|
|
1137
|
-
export class ODModalResponderInstance {
|
|
1185
|
+
export class ODModalResponderInstance extends ODBaseResponderInstance {
|
|
1138
1186
|
/**The interaction which is the source of this instance. */
|
|
1139
1187
|
interaction: discord.ModalSubmitInteraction
|
|
1140
1188
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -1151,6 +1199,7 @@ export class ODModalResponderInstance {
|
|
|
1151
1199
|
channel: discord.TextBasedChannel|null
|
|
1152
1200
|
|
|
1153
1201
|
constructor(interaction:discord.ModalSubmitInteraction, errorCallback:ODResponderTimeoutErrorCallback<ODModalResponderInstance,"modal">|null, timeoutMs:number|null){
|
|
1202
|
+
super()
|
|
1154
1203
|
this.interaction = interaction
|
|
1155
1204
|
this.values = new ODModalResponderInstanceValues(interaction)
|
|
1156
1205
|
this.user = interaction.user
|
|
@@ -1162,7 +1211,7 @@ export class ODModalResponderInstance {
|
|
|
1162
1211
|
if (!this.didReply){
|
|
1163
1212
|
try {
|
|
1164
1213
|
if (!errorCallback){
|
|
1165
|
-
this.reply({id:new ODId("
|
|
1214
|
+
this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
|
|
1166
1215
|
content:":x: **Something went wrong while replying to this modal!**"
|
|
1167
1216
|
}})
|
|
1168
1217
|
}else{
|
|
@@ -1177,10 +1226,10 @@ export class ODModalResponderInstance {
|
|
|
1177
1226
|
}
|
|
1178
1227
|
|
|
1179
1228
|
/**Reply to this modal. */
|
|
1180
|
-
async reply(
|
|
1181
|
-
try{
|
|
1182
|
-
const
|
|
1183
|
-
const sent = await this.interaction.followUp(
|
|
1229
|
+
async reply(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
1230
|
+
try {
|
|
1231
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
1232
|
+
const sent = await this.interaction.followUp(finalMessage)
|
|
1184
1233
|
this.didReply = true
|
|
1185
1234
|
return {success:true,message:sent}
|
|
1186
1235
|
}catch{
|
|
@@ -1188,15 +1237,15 @@ export class ODModalResponderInstance {
|
|
|
1188
1237
|
}
|
|
1189
1238
|
}
|
|
1190
1239
|
/**Update the message of this modal. */
|
|
1191
|
-
async update(
|
|
1192
|
-
try{
|
|
1193
|
-
const
|
|
1240
|
+
async update(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
1241
|
+
try {
|
|
1242
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
1194
1243
|
if (this.interaction.replied || this.interaction.deferred){
|
|
1195
|
-
const sent = await this.interaction.editReply(
|
|
1244
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
1196
1245
|
this.didReply = true
|
|
1197
1246
|
return {success:true,message:await sent.fetch()}
|
|
1198
1247
|
}else{
|
|
1199
|
-
const sent = await this.interaction.reply(
|
|
1248
|
+
const sent = await this.interaction.reply(finalMessage)
|
|
1200
1249
|
this.didReply = true
|
|
1201
1250
|
return {success:true,message:await sent.fetch()}
|
|
1202
1251
|
}
|
|
@@ -1251,30 +1300,30 @@ export type ODContextMenuResponderManagerIdConstraint = Record<string,{origin:"c
|
|
|
1251
1300
|
*/
|
|
1252
1301
|
export class ODContextMenuResponderManager<IdList extends ODContextMenuResponderManagerIdConstraint = ODContextMenuResponderManagerIdConstraint> extends ODManager<ODContextMenuResponder<"context-menu",any>> {
|
|
1253
1302
|
/**An alias to the Open Discord client manager. */
|
|
1254
|
-
|
|
1303
|
+
private client: ODClientManager
|
|
1255
1304
|
/**The callback executed when the default workers take too much time to reply. */
|
|
1256
|
-
|
|
1305
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODContextMenuResponderInstance,"context-menu">|null = null
|
|
1257
1306
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
1258
|
-
|
|
1307
|
+
private timeoutMs: number|null = null
|
|
1259
1308
|
|
|
1260
1309
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
1261
1310
|
super(debug,debugname)
|
|
1262
|
-
this
|
|
1311
|
+
this.client = client
|
|
1263
1312
|
}
|
|
1264
1313
|
|
|
1265
1314
|
/**Set the message to send when the response times out! */
|
|
1266
1315
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODContextMenuResponderInstance,"context-menu">|null, ms:number|null){
|
|
1267
|
-
this
|
|
1268
|
-
this
|
|
1316
|
+
this.timeoutErrorCallback = callback
|
|
1317
|
+
this.timeoutMs = ms
|
|
1269
1318
|
}
|
|
1270
1319
|
|
|
1271
1320
|
add(data:ODContextMenuResponder<"context-menu",any>, overwrite?:boolean){
|
|
1272
1321
|
const res = super.add(data,overwrite)
|
|
1273
1322
|
|
|
1274
|
-
this
|
|
1323
|
+
this.client.contextMenus.onInteraction(data.match,(interaction,cmd) => {
|
|
1275
1324
|
const newData = this.get(data.id)
|
|
1276
1325
|
if (!newData) return
|
|
1277
|
-
newData.respond(new ODContextMenuResponderInstance(interaction,cmd,this
|
|
1326
|
+
newData.respond(new ODContextMenuResponderInstance(interaction,cmd,this.timeoutErrorCallback,this.timeoutMs),"context-menu",{})
|
|
1278
1327
|
})
|
|
1279
1328
|
|
|
1280
1329
|
return res
|
|
@@ -1307,7 +1356,7 @@ export class ODContextMenuResponderManager<IdList extends ODContextMenuResponder
|
|
|
1307
1356
|
*
|
|
1308
1357
|
* An instance is an active context menu interaction. You can reply to the context menu using `reply()`.
|
|
1309
1358
|
*/
|
|
1310
|
-
export class ODContextMenuResponderInstance {
|
|
1359
|
+
export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
|
|
1311
1360
|
/**The interaction which is the source of this instance. */
|
|
1312
1361
|
interaction: discord.ContextMenuCommandInteraction
|
|
1313
1362
|
/**Did a worker already reply to this instance/interaction? */
|
|
@@ -1326,6 +1375,7 @@ export class ODContextMenuResponderInstance {
|
|
|
1326
1375
|
target: discord.Message|discord.User
|
|
1327
1376
|
|
|
1328
1377
|
constructor(interaction:discord.ContextMenuCommandInteraction, menu:ODContextMenu, errorCallback:ODResponderTimeoutErrorCallback<ODContextMenuResponderInstance,"context-menu">|null, timeoutMs:number|null){
|
|
1378
|
+
super()
|
|
1329
1379
|
if (!interaction.channel) throw new ODSystemError("ODContextMenuResponderInstance: Unable to find interaction channel!")
|
|
1330
1380
|
this.interaction = interaction
|
|
1331
1381
|
this.menu = menu
|
|
@@ -1341,7 +1391,7 @@ export class ODContextMenuResponderInstance {
|
|
|
1341
1391
|
if (!this.didReply){
|
|
1342
1392
|
try {
|
|
1343
1393
|
if (!errorCallback){
|
|
1344
|
-
this.reply({id:new ODId("
|
|
1394
|
+
this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
|
|
1345
1395
|
content:":x: **Something went wrong while replying to this context menu!**"
|
|
1346
1396
|
}})
|
|
1347
1397
|
}else{
|
|
@@ -1356,15 +1406,15 @@ export class ODContextMenuResponderInstance {
|
|
|
1356
1406
|
}
|
|
1357
1407
|
|
|
1358
1408
|
/**Reply to this context menu. */
|
|
1359
|
-
async reply(
|
|
1360
|
-
try{
|
|
1361
|
-
const
|
|
1409
|
+
async reply(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
1410
|
+
try {
|
|
1411
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
1362
1412
|
if (this.interaction.replied || this.interaction.deferred){
|
|
1363
|
-
const sent = await this.interaction.editReply(
|
|
1413
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
1364
1414
|
this.didReply = true
|
|
1365
1415
|
return {success:true,message:sent}
|
|
1366
1416
|
}else{
|
|
1367
|
-
const sent = await this.interaction.reply(
|
|
1417
|
+
const sent = await this.interaction.reply(finalMessage)
|
|
1368
1418
|
this.didReply = true
|
|
1369
1419
|
return {success:true,message:await sent.fetch()}
|
|
1370
1420
|
}
|
|
@@ -1373,11 +1423,11 @@ export class ODContextMenuResponderInstance {
|
|
|
1373
1423
|
}
|
|
1374
1424
|
}
|
|
1375
1425
|
/**Update the message of this context menu. */
|
|
1376
|
-
async update(
|
|
1377
|
-
try{
|
|
1378
|
-
const
|
|
1426
|
+
async update(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<boolean>> {
|
|
1427
|
+
try {
|
|
1428
|
+
const finalMessage = this.getMessageFromBuildResult(build,"interaction")
|
|
1379
1429
|
if (this.interaction.replied || this.interaction.deferred){
|
|
1380
|
-
const sent = await this.interaction.editReply(
|
|
1430
|
+
const sent = await this.interaction.editReply(finalMessage)
|
|
1381
1431
|
this.didReply = true
|
|
1382
1432
|
return {success:true,message:await sent.fetch()}
|
|
1383
1433
|
}else throw new ODSystemError("Unable to update context menu interaction!")
|
|
@@ -1437,30 +1487,30 @@ export type ODAutocompleteResponderManagerIdConstraint = Record<string,{origin:"
|
|
|
1437
1487
|
*/
|
|
1438
1488
|
export class ODAutocompleteResponderManager<IdList extends ODAutocompleteResponderManagerIdConstraint = ODAutocompleteResponderManagerIdConstraint> extends ODManager<ODAutocompleteResponder<"autocomplete",any>> {
|
|
1439
1489
|
/**An alias to the Open Discord client manager. */
|
|
1440
|
-
|
|
1490
|
+
private client: ODClientManager
|
|
1441
1491
|
/**The callback executed when the default workers take too much time to reply. */
|
|
1442
|
-
|
|
1492
|
+
private timeoutErrorCallback: ODResponderTimeoutErrorCallback<ODAutocompleteResponderInstance,"autocomplete">|null = null
|
|
1443
1493
|
/**The amount of milliseconds before the timeout error callback is executed. */
|
|
1444
|
-
|
|
1494
|
+
private timeoutMs: number|null = null
|
|
1445
1495
|
|
|
1446
1496
|
constructor(debug:ODDebugger, debugname:string, client:ODClientManager){
|
|
1447
1497
|
super(debug,debugname)
|
|
1448
|
-
this
|
|
1498
|
+
this.client = client
|
|
1449
1499
|
}
|
|
1450
1500
|
|
|
1451
1501
|
/**Set the message to send when the response times out! */
|
|
1452
1502
|
setTimeoutErrorCallback(callback:ODResponderTimeoutErrorCallback<ODAutocompleteResponderInstance,"autocomplete">|null, ms:number|null){
|
|
1453
|
-
this
|
|
1454
|
-
this
|
|
1503
|
+
this.timeoutErrorCallback = callback
|
|
1504
|
+
this.timeoutMs = ms
|
|
1455
1505
|
}
|
|
1456
1506
|
|
|
1457
1507
|
add(data:ODAutocompleteResponder<"autocomplete",any>, overwrite?:boolean){
|
|
1458
1508
|
const res = super.add(data,overwrite)
|
|
1459
1509
|
|
|
1460
|
-
this
|
|
1510
|
+
this.client.autocompletes.onInteraction(data.cmdMatch,data.match,(interaction) => {
|
|
1461
1511
|
const newData = this.get(data.id)
|
|
1462
1512
|
if (!newData) return
|
|
1463
|
-
newData.respond(new ODAutocompleteResponderInstance(interaction,this
|
|
1513
|
+
newData.respond(new ODAutocompleteResponderInstance(interaction,this.timeoutErrorCallback,this.timeoutMs),"autocomplete",{})
|
|
1464
1514
|
})
|
|
1465
1515
|
|
|
1466
1516
|
return res
|
|
@@ -1493,7 +1543,7 @@ export class ODAutocompleteResponderManager<IdList extends ODAutocompleteRespond
|
|
|
1493
1543
|
*
|
|
1494
1544
|
* An instance is an active autocomplete interaction. You can reply to the autocomplete using `reply()`.
|
|
1495
1545
|
*/
|
|
1496
|
-
export class ODAutocompleteResponderInstance {
|
|
1546
|
+
export class ODAutocompleteResponderInstance extends ODBaseResponderInstance {
|
|
1497
1547
|
/**The interaction which is the source of this instance. */
|
|
1498
1548
|
interaction: discord.AutocompleteInteraction
|
|
1499
1549
|
/**Did a worker already respond to this instance/interaction? */
|
|
@@ -1510,6 +1560,7 @@ export class ODAutocompleteResponderInstance {
|
|
|
1510
1560
|
target: discord.AutocompleteFocusedOption
|
|
1511
1561
|
|
|
1512
1562
|
constructor(interaction:discord.AutocompleteInteraction, errorCallback:ODResponderTimeoutErrorCallback<ODAutocompleteResponderInstance,"autocomplete">|null, timeoutMs:number|null){
|
|
1563
|
+
super()
|
|
1513
1564
|
if (!interaction.channel) throw new ODSystemError("ODAutocompleteResponderInstance: Unable to find interaction channel!")
|
|
1514
1565
|
this.interaction = interaction
|
|
1515
1566
|
this.user = interaction.user
|
|
@@ -1520,7 +1571,7 @@ export class ODAutocompleteResponderInstance {
|
|
|
1520
1571
|
|
|
1521
1572
|
setTimeout(async () => {
|
|
1522
1573
|
if (!this.didRespond){
|
|
1523
|
-
process.emit("uncaughtException",new ODSystemError("Autocomplete responder instance failed to respond
|
|
1574
|
+
process.emit("uncaughtException",new ODSystemError("Autocomplete responder instance failed to respond within 2.5sec!"))
|
|
1524
1575
|
}
|
|
1525
1576
|
},timeoutMs ?? 2500)
|
|
1526
1577
|
}
|