@open-discord-bots/framework 0.2.17 → 0.3.1

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