@open-discord-bots/framework 0.3.2 → 0.3.4

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.
@@ -47,9 +47,7 @@ export type ODResponderSendResult<InGuild extends boolean> = {
47
47
  message:discord.Message<InGuild>
48
48
  } | {
49
49
  /**Did the message get sent successfully? */
50
- success:boolean,
51
- /**The message that got sent. */
52
- message:null
50
+ success:false
53
51
  }
54
52
 
55
53
  /**## ODResponderManager `class`
@@ -419,8 +417,8 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
419
417
  cmd:ODSlashCommand|ODTextCommand
420
418
  /**The type/source of instance. (from text or slash command) */
421
419
  type: "message"|"interaction"
422
- /**Did a worker already reply to this instance/interaction? */
423
- didReply: boolean = false
420
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
421
+ protected ignoreResponderTimeout: boolean = false
424
422
  /**The manager for all options of this command. */
425
423
  options: ODCommandResponderInstanceOptions
426
424
  /**The user who triggered this command. */
@@ -446,24 +444,23 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
446
444
 
447
445
 
448
446
  setTimeout(async () => {
449
- if (!this.didReply){
450
- try {
451
- if (!errorCallback){
452
- this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
453
- content:":x: **Something went wrong while replying to this command!**"
454
- }})
455
- }else{
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)
462
- }
447
+ if (this.ignoreResponderTimeout) return
448
+ try {
449
+ if (!errorCallback){
450
+ this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
451
+ content:":x: **Something went wrong while replying to this command!**"
452
+ }})
453
+ }else{
454
+ const errorResponse = await errorCallback(this,(this.type == "interaction") ? "slash" : "text")
463
455
 
464
- }catch(err){
465
- process.emit("uncaughtException",err)
456
+ //auto-delete timeout error message after 5sec when text-based
457
+ if (errorResponse.success && this.type == "message") setTimeout(() => {
458
+ if (errorResponse.message?.deletable) errorResponse.message?.delete()
459
+ },5000)
466
460
  }
461
+
462
+ }catch(err){
463
+ process.emit("uncaughtException",err)
467
464
  }
468
465
  },timeoutMs ?? 2500)
469
466
  }
@@ -475,37 +472,37 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
475
472
  if (this.type == "interaction" && this.interaction instanceof discord.ChatInputCommandInteraction){
476
473
  if (this.interaction.replied || this.interaction.deferred){
477
474
  const sent = await this.interaction.editReply(finalMessage)
478
- this.didReply = true
475
+ this.ignoreResponderTimeout = true
479
476
  return {success:true,message:sent}
480
477
  }else{
481
478
  const sent = await this.interaction.reply(finalMessage)
482
- this.didReply = true
479
+ this.ignoreResponderTimeout = true
483
480
  return {success:true,message:await sent.fetch()}
484
481
  }
485
482
  }else if (this.type == "message" && this.interaction instanceof discord.Message && this.interaction.channel.type != discord.ChannelType.GroupDM){
486
483
  const sent = await this.interaction.channel.send(finalMessage)
487
- this.didReply = true
484
+ this.ignoreResponderTimeout = true
488
485
  return {success:true,message:sent}
489
- }else return {success:false,message:null}
486
+ }else return {success:false}
490
487
  }catch{
491
- return {success:false,message:null}
488
+ return {success:false}
492
489
  }
493
490
  }
494
491
  /**Defer this command. */
495
492
  async defer(ephemeral:boolean){
493
+ this.ignoreResponderTimeout = true
496
494
  if (this.type != "interaction" || !(this.interaction instanceof discord.ChatInputCommandInteraction)) return false
497
495
  if (this.interaction.deferred || this.interaction.replied) return false
498
496
  const msgFlags: number[] = ephemeral ? [discord.MessageFlags.Ephemeral] : []
499
497
  await this.interaction.deferReply({flags:msgFlags})
500
- this.didReply = true
501
498
  return true
502
499
  }
503
500
  /**Show a modal as reply to this command. */
504
501
  async modal(modal:ODModalBuildResult){
502
+ this.ignoreResponderTimeout = true
505
503
  if (this.type != "interaction" || !(this.interaction instanceof discord.ChatInputCommandInteraction)) return false
506
504
  if (this.interaction.deferred || this.interaction.replied) return false
507
505
  await this.interaction.showModal(modal.modal)
508
- this.didReply = true
509
506
  return true
510
507
  }
511
508
  }
@@ -617,8 +614,8 @@ export class ODButtonResponderManager<IdList extends ODButtonResponderManagerIdC
617
614
  export class ODButtonResponderInstance extends ODBaseResponderInstance {
618
615
  /**The interaction which is the source of this instance. */
619
616
  interaction: discord.ButtonInteraction
620
- /**Did a worker already reply to this instance/interaction? */
621
- didReply: boolean = false
617
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
618
+ protected ignoreResponderTimeout: boolean = false
622
619
  /**The user who triggered this button. */
623
620
  user: discord.User
624
621
  /**The guild member who triggered this button. */
@@ -641,19 +638,18 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
641
638
  this.message = interaction.message
642
639
 
643
640
  setTimeout(async () => {
644
- if (!this.didReply){
645
- try {
646
- if (!errorCallback){
647
- this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
648
- content:":x: **Something went wrong while replying to this button!**"
649
- }})
650
- }else{
651
- await errorCallback(this,"button")
652
- }
653
-
654
- }catch(err){
655
- process.emit("uncaughtException",err)
641
+ if (this.ignoreResponderTimeout) return
642
+ try {
643
+ if (!errorCallback){
644
+ this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
645
+ content:":x: **Something went wrong while replying to this button!**"
646
+ }})
647
+ }else{
648
+ await errorCallback(this,"button")
656
649
  }
650
+
651
+ }catch(err){
652
+ process.emit("uncaughtException",err)
657
653
  }
658
654
  },timeoutMs ?? 2500)
659
655
  }
@@ -664,15 +660,15 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
664
660
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
665
661
  if (this.interaction.replied || this.interaction.deferred){
666
662
  const sent = await this.interaction.editReply(finalMessage)
667
- this.didReply = true
663
+ this.ignoreResponderTimeout = true
668
664
  return {success:true,message:sent}
669
665
  }else{
670
666
  const sent = await this.interaction.reply(finalMessage)
671
- this.didReply = true
667
+ this.ignoreResponderTimeout = true
672
668
  return {success:true,message:await sent.fetch()}
673
669
  }
674
670
  }catch{
675
- return {success:false,message:null}
671
+ return {success:false}
676
672
  }
677
673
  }
678
674
  /**Update the message of this button. */
@@ -681,19 +677,20 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
681
677
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
682
678
  if (this.interaction.replied || this.interaction.deferred){
683
679
  const sent = await this.interaction.editReply(finalMessage)
684
- this.didReply = true
680
+ this.ignoreResponderTimeout = true
685
681
  return {success:true,message:await sent.fetch()}
686
682
  }else{
687
683
  const sent = await this.interaction.update(finalMessage)
688
- this.didReply = true
684
+ this.ignoreResponderTimeout = true
689
685
  return {success:true,message:await sent.fetch()}
690
686
  }
691
687
  }catch{
692
- return {success:false,message:null}
688
+ return {success:false}
693
689
  }
694
690
  }
695
691
  /**Defer this button. */
696
692
  async defer(type:"reply"|"update", ephemeral:boolean){
693
+ this.ignoreResponderTimeout = true
697
694
  if (this.interaction.deferred || this.interaction.replied) return false
698
695
  if (type == "reply"){
699
696
  const msgFlags: number[] = ephemeral ? [discord.MessageFlags.Ephemeral] : []
@@ -701,14 +698,13 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
701
698
  }else{
702
699
  await this.interaction.deferUpdate()
703
700
  }
704
- this.didReply = true
705
701
  return true
706
702
  }
707
703
  /**Show a modal as reply to this button. */
708
704
  async modal(modal:ODModalBuildResult){
705
+ this.ignoreResponderTimeout = true
709
706
  if (this.interaction.deferred || this.interaction.replied) return false
710
707
  await this.interaction.showModal(modal.modal)
711
- this.didReply = true
712
708
  return true
713
709
  }
714
710
 
@@ -916,8 +912,8 @@ export class ODDropdownResponderInstanceValues {
916
912
  export class ODDropdownResponderInstance extends ODBaseResponderInstance {
917
913
  /**The interaction which is the source of this instance. */
918
914
  interaction: discord.AnySelectMenuInteraction
919
- /**Did a worker already reply to this instance/interaction? */
920
- didReply: boolean = false
915
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
916
+ protected ignoreResponderTimeout: boolean = false
921
917
  /**The dropdown type. */
922
918
  type: ODDropdownData["type"]
923
919
  /**The manager for all values of this dropdown. */
@@ -957,19 +953,18 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
957
953
  this.message = interaction.message
958
954
 
959
955
  setTimeout(async () => {
960
- if (!this.didReply){
961
- try {
962
- if (!errorCallback){
963
- this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
964
- content:":x: **Something went wrong while replying to this dropdown!**"
965
- }})
966
- }else{
967
- await errorCallback(this,"dropdown")
968
- }
969
-
970
- }catch(err){
971
- process.emit("uncaughtException",err)
956
+ if (this.ignoreResponderTimeout) return
957
+ try {
958
+ if (!errorCallback){
959
+ this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
960
+ content:":x: **Something went wrong while replying to this dropdown!**"
961
+ }})
962
+ }else{
963
+ await errorCallback(this,"dropdown")
972
964
  }
965
+
966
+ }catch(err){
967
+ process.emit("uncaughtException",err)
973
968
  }
974
969
  },timeoutMs ?? 2500)
975
970
  }
@@ -980,15 +975,15 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
980
975
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
981
976
  if (this.interaction.replied || this.interaction.deferred){
982
977
  const sent = await this.interaction.editReply(finalMessage)
983
- this.didReply = true
978
+ this.ignoreResponderTimeout = true
984
979
  return {success:true,message:sent}
985
980
  }else{
986
981
  const sent = await this.interaction.reply(finalMessage)
987
- this.didReply = true
982
+ this.ignoreResponderTimeout = true
988
983
  return {success:true,message:await sent.fetch()}
989
984
  }
990
985
  }catch{
991
- return {success:false,message:null}
986
+ return {success:false}
992
987
  }
993
988
  }
994
989
  /**Update the message of this dropdown. */
@@ -997,19 +992,20 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
997
992
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
998
993
  if (this.interaction.replied || this.interaction.deferred){
999
994
  const sent = await this.interaction.editReply(finalMessage)
1000
- this.didReply = true
995
+ this.ignoreResponderTimeout = true
1001
996
  return {success:true,message:await sent.fetch()}
1002
997
  }else{
1003
998
  const sent = await this.interaction.update(finalMessage)
1004
- this.didReply = true
999
+ this.ignoreResponderTimeout = true
1005
1000
  return {success:true,message:await sent.fetch()}
1006
1001
  }
1007
1002
  }catch{
1008
- return {success:false,message:null}
1003
+ return {success:false}
1009
1004
  }
1010
1005
  }
1011
1006
  /**Defer this dropdown. */
1012
1007
  async defer(type:"reply"|"update", ephemeral:boolean){
1008
+ this.ignoreResponderTimeout = true
1013
1009
  if (this.interaction.deferred || this.interaction.replied) return false
1014
1010
  if (type == "reply"){
1015
1011
  const msgFlags: number[] = ephemeral ? [discord.MessageFlags.Ephemeral] : []
@@ -1017,14 +1013,13 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
1017
1013
  }else{
1018
1014
  await this.interaction.deferUpdate()
1019
1015
  }
1020
- this.didReply = true
1021
1016
  return true
1022
1017
  }
1023
1018
  /**Show a modal as reply to this dropdown. */
1024
1019
  async modal(modal:ODModalBuildResult){
1020
+ this.ignoreResponderTimeout = true
1025
1021
  if (this.interaction.deferred || this.interaction.replied) return false
1026
1022
  await this.interaction.showModal(modal.modal)
1027
- this.didReply = true
1028
1023
  return true
1029
1024
  }
1030
1025
 
@@ -1185,8 +1180,8 @@ export class ODModalResponderInstanceValues {
1185
1180
  export class ODModalResponderInstance extends ODBaseResponderInstance {
1186
1181
  /**The interaction which is the source of this instance. */
1187
1182
  interaction: discord.ModalSubmitInteraction
1188
- /**Did a worker already reply to this instance/interaction? */
1189
- didReply: boolean = false
1183
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
1184
+ protected ignoreResponderTimeout: boolean = false
1190
1185
  /**The manager for all fields of this modal. */
1191
1186
  values: ODModalResponderInstanceValues
1192
1187
  /**The user who triggered this modal. */
@@ -1208,19 +1203,18 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1208
1203
  this.channel = interaction.channel
1209
1204
 
1210
1205
  setTimeout(async () => {
1211
- if (!this.didReply){
1212
- try {
1213
- if (!errorCallback){
1214
- this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
1215
- content:":x: **Something went wrong while replying to this modal!**"
1216
- }})
1217
- }else{
1218
- await errorCallback(this,"modal")
1219
- }
1220
-
1221
- }catch(err){
1222
- process.emit("uncaughtException",err)
1206
+ if (this.ignoreResponderTimeout) return
1207
+ try {
1208
+ if (!errorCallback){
1209
+ this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
1210
+ content:":x: **Something went wrong while replying to this modal!**"
1211
+ }})
1212
+ }else{
1213
+ await errorCallback(this,"modal")
1223
1214
  }
1215
+
1216
+ }catch(err){
1217
+ process.emit("uncaughtException",err)
1224
1218
  }
1225
1219
  },timeoutMs ?? 2500)
1226
1220
  }
@@ -1230,10 +1224,10 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1230
1224
  try {
1231
1225
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
1232
1226
  const sent = await this.interaction.followUp(finalMessage)
1233
- this.didReply = true
1227
+ this.ignoreResponderTimeout = true
1234
1228
  return {success:true,message:sent}
1235
1229
  }catch{
1236
- return {success:false,message:null}
1230
+ return {success:false}
1237
1231
  }
1238
1232
  }
1239
1233
  /**Update the message of this modal. */
@@ -1242,19 +1236,20 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1242
1236
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
1243
1237
  if (this.interaction.replied || this.interaction.deferred){
1244
1238
  const sent = await this.interaction.editReply(finalMessage)
1245
- this.didReply = true
1239
+ this.ignoreResponderTimeout = true
1246
1240
  return {success:true,message:await sent.fetch()}
1247
1241
  }else{
1248
1242
  const sent = await this.interaction.reply(finalMessage)
1249
- this.didReply = true
1243
+ this.ignoreResponderTimeout = true
1250
1244
  return {success:true,message:await sent.fetch()}
1251
1245
  }
1252
1246
  }catch{
1253
- return {success:false,message:null}
1247
+ return {success:false}
1254
1248
  }
1255
1249
  }
1256
1250
  /**Defer this modal. */
1257
1251
  async defer(type:"reply"|"update", ephemeral:boolean){
1252
+ this.ignoreResponderTimeout = true
1258
1253
  if (this.interaction.deferred || this.interaction.replied) return false
1259
1254
  if (type == "reply"){
1260
1255
  const msgFlags: number[] = ephemeral ? [discord.MessageFlags.Ephemeral] : []
@@ -1262,7 +1257,6 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1262
1257
  }else{
1263
1258
  await this.interaction.deferUpdate()
1264
1259
  }
1265
- this.didReply = true
1266
1260
  return true
1267
1261
  }
1268
1262
  }
@@ -1359,8 +1353,8 @@ export class ODContextMenuResponderManager<IdList extends ODContextMenuResponder
1359
1353
  export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1360
1354
  /**The interaction which is the source of this instance. */
1361
1355
  interaction: discord.ContextMenuCommandInteraction
1362
- /**Did a worker already reply to this instance/interaction? */
1363
- didReply: boolean = false
1356
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
1357
+ protected ignoreResponderTimeout: boolean = false
1364
1358
  /**The context menu wich is the source of this instance. */
1365
1359
  menu:ODContextMenu
1366
1360
  /**The user who triggered this context menu. */
@@ -1388,19 +1382,18 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1388
1382
  else throw new ODSystemError("ODContextMenuResponderInstance: Invalid context menu type. Should be of the type User/Message!")
1389
1383
 
1390
1384
  setTimeout(async () => {
1391
- if (!this.didReply){
1392
- try {
1393
- if (!errorCallback){
1394
- this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
1395
- content:":x: **Something went wrong while replying to this context menu!**"
1396
- }})
1397
- }else{
1398
- await errorCallback(this,"context-menu")
1399
- }
1400
-
1401
- }catch(err){
1402
- process.emit("uncaughtException",err)
1385
+ if (this.ignoreResponderTimeout) return
1386
+ try {
1387
+ if (!errorCallback){
1388
+ this.reply({id:new ODId("opendiscord:unknown-error"), ephemeral:true, message:{
1389
+ content:":x: **Something went wrong while replying to this context menu!**"
1390
+ }})
1391
+ }else{
1392
+ await errorCallback(this,"context-menu")
1403
1393
  }
1394
+
1395
+ }catch(err){
1396
+ process.emit("uncaughtException",err)
1404
1397
  }
1405
1398
  },timeoutMs ?? 2500)
1406
1399
  }
@@ -1411,15 +1404,15 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1411
1404
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
1412
1405
  if (this.interaction.replied || this.interaction.deferred){
1413
1406
  const sent = await this.interaction.editReply(finalMessage)
1414
- this.didReply = true
1407
+ this.ignoreResponderTimeout = true
1415
1408
  return {success:true,message:sent}
1416
1409
  }else{
1417
1410
  const sent = await this.interaction.reply(finalMessage)
1418
- this.didReply = true
1411
+ this.ignoreResponderTimeout = true
1419
1412
  return {success:true,message:await sent.fetch()}
1420
1413
  }
1421
1414
  }catch{
1422
- return {success:false,message:null}
1415
+ return {success:false}
1423
1416
  }
1424
1417
  }
1425
1418
  /**Update the message of this context menu. */
@@ -1428,28 +1421,28 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1428
1421
  const finalMessage = this.getMessageFromBuildResult(build,"interaction")
1429
1422
  if (this.interaction.replied || this.interaction.deferred){
1430
1423
  const sent = await this.interaction.editReply(finalMessage)
1431
- this.didReply = true
1424
+ this.ignoreResponderTimeout = true
1432
1425
  return {success:true,message:await sent.fetch()}
1433
1426
  }else throw new ODSystemError("Unable to update context menu interaction!")
1434
1427
  }catch{
1435
- return {success:false,message:null}
1428
+ return {success:false}
1436
1429
  }
1437
1430
  }
1438
1431
  /**Defer this context menu. */
1439
1432
  async defer(type:"reply", ephemeral:boolean){
1433
+ this.ignoreResponderTimeout = true
1440
1434
  if (this.interaction.deferred || this.interaction.replied) return false
1441
1435
  if (type == "reply"){
1442
1436
  const msgFlags: number[] = ephemeral ? [discord.MessageFlags.Ephemeral] : []
1443
1437
  await this.interaction.deferReply({flags:msgFlags})
1444
1438
  }
1445
- this.didReply = true
1446
1439
  return true
1447
1440
  }
1448
1441
  /**Show a modal as reply to this context menu. */
1449
1442
  async modal(modal:ODModalBuildResult){
1443
+ this.ignoreResponderTimeout = true
1450
1444
  if (this.interaction.deferred || this.interaction.replied) return false
1451
1445
  await this.interaction.showModal(modal.modal)
1452
- this.didReply = true
1453
1446
  return true
1454
1447
  }
1455
1448
  }