@open-discord-bots/framework 0.1.2 → 0.2.0

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/modules/action.d.ts +26 -4
  2. package/dist/api/modules/action.js +16 -0
  3. package/dist/api/modules/base.d.ts +12 -2
  4. package/dist/api/modules/base.js +11 -1
  5. package/dist/api/modules/builder.d.ts +117 -21
  6. package/dist/api/modules/builder.js +72 -0
  7. package/dist/api/modules/checker.d.ts +111 -15
  8. package/dist/api/modules/checker.js +201 -9
  9. package/dist/api/modules/client.d.ts +45 -22
  10. package/dist/api/modules/client.js +58 -34
  11. package/dist/api/modules/code.d.ts +11 -1
  12. package/dist/api/modules/code.js +9 -0
  13. package/dist/api/modules/config.d.ts +15 -5
  14. package/dist/api/modules/config.js +9 -0
  15. package/dist/api/modules/console.d.ts +11 -1
  16. package/dist/api/modules/console.js +9 -0
  17. package/dist/api/modules/cooldown.d.ts +11 -1
  18. package/dist/api/modules/cooldown.js +9 -0
  19. package/dist/api/modules/database.d.ts +36 -4
  20. package/dist/api/modules/database.js +9 -17
  21. package/dist/api/modules/event.d.ts +10 -1
  22. package/dist/api/modules/event.js +6 -0
  23. package/dist/api/modules/flag.d.ts +11 -1
  24. package/dist/api/modules/flag.js +9 -0
  25. package/dist/api/modules/helpmenu.d.ts +22 -2
  26. package/dist/api/modules/helpmenu.js +18 -0
  27. package/dist/api/modules/language.d.ts +15 -1
  28. package/dist/api/modules/language.js +9 -4
  29. package/dist/api/modules/permission.d.ts +11 -1
  30. package/dist/api/modules/permission.js +9 -0
  31. package/dist/api/modules/plugin.d.ts +23 -3
  32. package/dist/api/modules/plugin.js +18 -0
  33. package/dist/api/modules/post.d.ts +11 -1
  34. package/dist/api/modules/post.js +9 -0
  35. package/dist/api/modules/progressbar.d.ts +24 -3
  36. package/dist/api/modules/progressbar.js +19 -0
  37. package/dist/api/modules/responder.d.ts +105 -21
  38. package/dist/api/modules/responder.js +54 -0
  39. package/dist/api/modules/session.d.ts +11 -1
  40. package/dist/api/modules/session.js +9 -0
  41. package/dist/api/modules/startscreen.d.ts +17 -7
  42. package/dist/api/modules/startscreen.js +9 -0
  43. package/dist/api/modules/stat.d.ts +42 -8
  44. package/dist/api/modules/stat.js +18 -4
  45. package/dist/api/modules/verifybar.d.ts +18 -4
  46. package/dist/api/modules/verifybar.js +9 -0
  47. package/dist/api/modules/worker.d.ts +7 -1
  48. package/dist/api/modules/worker.js +9 -0
  49. package/dist/utilities/index.js +1 -0
  50. package/package.json +1 -1
  51. package/src/api/main.ts +10 -10
  52. package/src/api/modules/action.ts +37 -4
  53. package/src/api/modules/base.ts +30 -3
  54. package/src/api/modules/builder.ts +226 -21
  55. package/src/api/modules/checker.ts +292 -17
  56. package/src/api/modules/client.ts +129 -43
  57. package/src/api/modules/code.ts +27 -1
  58. package/src/api/modules/config.ts +33 -7
  59. package/src/api/modules/console.ts +27 -1
  60. package/src/api/modules/cooldown.ts +27 -1
  61. package/src/api/modules/database.ts +55 -4
  62. package/src/api/modules/event.ts +24 -1
  63. package/src/api/modules/flag.ts +27 -1
  64. package/src/api/modules/helpmenu.ts +55 -2
  65. package/src/api/modules/language.ts +35 -1
  66. package/src/api/modules/permission.ts +27 -1
  67. package/src/api/modules/plugin.ts +55 -3
  68. package/src/api/modules/post.ts +27 -1
  69. package/src/api/modules/progressbar.ts +56 -3
  70. package/src/api/modules/responder.ts +184 -21
  71. package/src/api/modules/session.ts +27 -1
  72. package/src/api/modules/startscreen.ts +33 -7
  73. package/src/api/modules/stat.ts +79 -8
  74. package/src/api/modules/verifybar.ts +31 -5
  75. package/src/api/modules/worker.ts +22 -1
  76. package/src/utilities/index.ts +1 -0
@@ -32,7 +32,7 @@ export type ODClientPermissions = ("CreateInstantInvite"|"KickMembers"|"BanMembe
32
32
  *
33
33
  * If you want, you can also listen for custom events on the `ODClientManager.client` variable (`discord.Client`)
34
34
  */
35
- export class ODClientManager {
35
+ export class ODClientManager<SlashIdList extends ODSlashCommandManagerIdConstraint = ODSlashCommandManagerIdConstraint,TextIdList extends ODTextCommandManagerIdConstraint = ODTextCommandManagerIdConstraint,ContextMenuIdList extends ODContextMenuManagerIdConstraint = ODContextMenuManagerIdConstraint> {
36
36
  /**Alias to Open Discord debugger. */
37
37
  #debug: ODDebugger
38
38
 
@@ -73,11 +73,11 @@ export class ODClientManager {
73
73
  /**The status manager is responsible for setting the bot status. */
74
74
  activity: ODClientActivityManager
75
75
  /**The slash command manager is responsible for all slash commands & their events inside the bot. */
76
- slashCommands: ODSlashCommandManager
76
+ slashCommands: ODSlashCommandManager<SlashIdList>
77
77
  /**The text command manager is responsible for all text commands & their events inside the bot. */
78
- textCommands: ODTextCommandManager
78
+ textCommands: ODTextCommandManager<TextIdList>
79
79
  /**The context menu manager is responsible for all context menus & their events inside the bot. */
80
- contextMenus: ODContextMenuManager
80
+ contextMenus: ODContextMenuManager<ContextMenuIdList>
81
81
  /**The autocomplete manager is responsible for all autocomplete events inside the bot. */
82
82
  autocompletes: ODAutocompleteManager
83
83
 
@@ -353,7 +353,7 @@ export class ODClientActivityManager {
353
353
  #debug: ODDebugger
354
354
 
355
355
  /**Copy of discord.js client */
356
- manager: ODClientManager
356
+ #manager: ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>
357
357
  /**The current status type */
358
358
  type: ODClientActivityType = false
359
359
  /**The current status text */
@@ -370,9 +370,9 @@ export class ODClientActivityManager {
370
370
  /**Is the status already initiated? */
371
371
  initiated: boolean = false
372
372
 
373
- constructor(debug:ODDebugger, manager:ODClientManager){
373
+ constructor(debug:ODDebugger, manager:ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>){
374
374
  this.#debug = debug
375
- this.manager = manager
375
+ this.#manager = manager
376
376
  }
377
377
 
378
378
  /**Update the status. When already initiated, it can take up to 10min to see the updated status in discord. */
@@ -386,7 +386,7 @@ export class ODClientActivityManager {
386
386
 
387
387
  /**When initiating the status, the bot starts updating the status using `discord.js`. Returns `true` when successfull. */
388
388
  initStatus(): boolean {
389
- if (this.initiated || !this.manager.ready) return false
389
+ if (this.initiated || !this.#manager.ready) return false
390
390
  this.#updateClientActivity(this.type,this.text)
391
391
  this.interval = setInterval(() => {
392
392
  this.#updateClientActivity(this.type,this.text)
@@ -399,12 +399,12 @@ export class ODClientActivityManager {
399
399
 
400
400
  /**Update the client status */
401
401
  #updateClientActivity(type:ODClientActivityType,text:string){
402
- if (!this.manager.client.user) throw new ODSystemError("Couldn't set client status: client.user == undefined")
402
+ if (!this.#manager.client.user) throw new ODSystemError("Couldn't set client status: client.user == undefined")
403
403
  if (type == false){
404
- this.manager.client.user.setActivity()
404
+ this.#manager.client.user.setActivity()
405
405
  return
406
406
  }
407
- this.manager.client.user.setPresence({
407
+ this.#manager.client.user.setPresence({
408
408
  activities:[{
409
409
  type:this.#getStatusTypeEnum(type),
410
410
  state:this.state ? this.state : undefined,
@@ -777,6 +777,11 @@ export type ODSlashCommandRegisteredResult = {
777
777
  }[]
778
778
  }
779
779
 
780
+ /**## ODSlashCommandManagerIdConstraint `type`
781
+ * The constraint/layout for id mappings/interfaces of the `ODSlashCommandManager` class.
782
+ */
783
+ export type ODSlashCommandManagerIdConstraint = Record<string,ODSlashCommand>
784
+
780
785
  /**## ODSlashCommandManager `class`
781
786
  * This is an Open Discord client slash manager.
782
787
  *
@@ -784,12 +789,12 @@ export type ODSlashCommandRegisteredResult = {
784
789
  *
785
790
  * Here, you can add & remove slash commands & the bot will do the (de)registering.
786
791
  */
787
- export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
792
+ export class ODSlashCommandManager<IdList extends ODSlashCommandManagerIdConstraint = ODSlashCommandManagerIdConstraint> extends ODManager<ODSlashCommand> {
788
793
  /**Alias to Open Discord debugger. */
789
794
  #debug: ODDebugger
790
795
 
791
796
  /**Refrerence to discord.js client. */
792
- manager: ODClientManager
797
+ #manager: ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>
793
798
  /**Discord.js application commands manager. */
794
799
  commandManager: discord.ApplicationCommandManager|null
795
800
  /**Collection of all interaction listeners. */
@@ -799,10 +804,10 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
799
804
  /**A utility class used to compare 2 slash commands with each other. */
800
805
  comparator: ODSlashCommandComparator = new ODSlashCommandComparator()
801
806
 
802
- constructor(debug:ODDebugger, manager:ODClientManager){
807
+ constructor(debug:ODDebugger, manager:ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>){
803
808
  super(debug,"slash command")
804
809
  this.#debug = debug
805
- this.manager = manager
810
+ this.#manager = manager
806
811
  this.commandManager = (manager.client.application) ? manager.client.application.commands : null
807
812
  }
808
813
 
@@ -848,7 +853,7 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
848
853
  }
849
854
  /**Create all commands that are not registered yet.*/
850
855
  async createNewCommands(instances:ODSlashCommand[],progress?:ODManualProgressBar){
851
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
856
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
852
857
  if (instances.length > 0 && progress){
853
858
  progress.max = instances.length
854
859
  progress.start()
@@ -865,7 +870,7 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
865
870
  }
866
871
  /**Update all commands that are already registered. */
867
872
  async updateExistingCommands(instances:ODSlashCommand[],progress?:ODManualProgressBar){
868
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
873
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
869
874
  if (instances.length > 0 && progress){
870
875
  progress.max = instances.length
871
876
  progress.start()
@@ -879,7 +884,7 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
879
884
  }
880
885
  /**Remove all commands that are registered but unused by Open Discord. */
881
886
  async removeUnusedCommands(instances:ODSlashCommandUniversalCommand[],guildId?:string,progress?:ODManualProgressBar){
882
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
887
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register slash commands!")
883
888
  if (!this.commandManager) throw new ODSystemError("Couldn't get client application to register slash commands!")
884
889
  if (instances.length > 0 && progress){
885
890
  progress.max = instances.length
@@ -914,9 +919,9 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
914
919
  }
915
920
  /**Start listening to the discord.js client `interactionCreate` event. */
916
921
  startListeningToInteractions(){
917
- this.manager.client.on("interactionCreate",(interaction) => {
922
+ this.#manager.client.on("interactionCreate",(interaction) => {
918
923
  //return when not in main server or DM
919
- if (!this.manager.mainServer || (interaction.guild && interaction.guild.id != this.manager.mainServer.id)) return
924
+ if (!this.#manager.mainServer || (interaction.guild && interaction.guild.id != this.#manager.mainServer.id)) return
920
925
 
921
926
  if (!interaction.isChatInputCommand()) return
922
927
  const cmd = this.getFiltered((cmd) => cmd.name == interaction.commandName)[0]
@@ -932,6 +937,8 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
932
937
  })
933
938
  }
934
939
  /**Callback on interaction from one or multiple slash commands. */
940
+ onInteraction(commandName:Extract<keyof IdList,string>, callback:ODSlashCommandInteractionCallback): void
941
+ onInteraction(commandName:string|RegExp, callback:ODSlashCommandInteractionCallback): void
935
942
  onInteraction(commandName:string|RegExp, callback:ODSlashCommandInteractionCallback){
936
943
  this.#interactionListeners.push({
937
944
  name:commandName,
@@ -944,6 +951,27 @@ export class ODSlashCommandManager extends ODManager<ODSlashCommand> {
944
951
  ]))
945
952
  }
946
953
  }
954
+
955
+ get<SlashCommandId extends keyof IdList>(id:SlashCommandId): IdList[SlashCommandId]
956
+ get(id:ODValidId): ODSlashCommand|null
957
+
958
+ get(id:ODValidId): ODSlashCommand|null {
959
+ return super.get(id)
960
+ }
961
+
962
+ remove<SlashCommandId extends keyof IdList>(id:SlashCommandId): IdList[SlashCommandId]
963
+ remove(id:ODValidId): ODSlashCommand|null
964
+
965
+ remove(id:ODValidId): ODSlashCommand|null {
966
+ return super.remove(id)
967
+ }
968
+
969
+ exists(id:keyof IdList): boolean
970
+ exists(id:ODValidId): boolean
971
+
972
+ exists(id:ODValidId): boolean {
973
+ return super.exists(id)
974
+ }
947
975
  }
948
976
 
949
977
  /**## ODSlashCommandUpdateFunction `type`
@@ -1281,6 +1309,11 @@ export type ODTextCommandError = (
1281
1309
  */
1282
1310
  export type ODTextCommandErrorCallback = (error:ODTextCommandError) => void
1283
1311
 
1312
+ /**## ODTextCommandManagerIdConstraint `type`
1313
+ * The constraint/layout for id mappings/interfaces of the `ODTextCommandManager` class.
1314
+ */
1315
+ export type ODTextCommandManagerIdConstraint = Record<string,ODTextCommand>
1316
+
1284
1317
  /**## ODTextCommandManager `class`
1285
1318
  * This is an Open Discord client text manager.
1286
1319
  *
@@ -1288,11 +1321,11 @@ export type ODTextCommandErrorCallback = (error:ODTextCommandError) => void
1288
1321
  *
1289
1322
  * Here, you can add & remove text commands & the bot will do the (de)registering.
1290
1323
  */
1291
- export class ODTextCommandManager extends ODManager<ODTextCommand> {
1324
+ export class ODTextCommandManager<IdList extends ODTextCommandManagerIdConstraint = ODTextCommandManagerIdConstraint> extends ODManager<ODTextCommand> {
1292
1325
  /**Alias to Open Discord debugger. */
1293
1326
  #debug: ODDebugger
1294
1327
  /**Copy of discord.js client. */
1295
- manager: ODClientManager
1328
+ #manager: ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>
1296
1329
  /**Collection of all interaction listeners. */
1297
1330
  #interactionListeners: {prefix:string, name:string|RegExp, callback:ODTextCommandInteractionCallback}[] = []
1298
1331
  /**Collection of all error listeners. */
@@ -1300,15 +1333,15 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1300
1333
  /**Set the soft limit for maximum amount of listeners. A warning will be shown when there are more listeners than this limit. */
1301
1334
  listenerLimit: number = 100
1302
1335
 
1303
- constructor(debug:ODDebugger, manager:ODClientManager){
1336
+ constructor(debug:ODDebugger, manager:ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>){
1304
1337
  super(debug,"text command")
1305
1338
  this.#debug = debug
1306
- this.manager = manager
1339
+ this.#manager = manager
1307
1340
  }
1308
1341
 
1309
1342
  /*Check if a message is a registered command. */
1310
1343
  async #checkMessage(msg:discord.Message){
1311
- if (this.manager.client.user && msg.author.id == this.manager.client.user.id) return false
1344
+ if (this.#manager.client.user && msg.author.id == this.#manager.client.user.id) return false
1312
1345
 
1313
1346
  //filter commands for correct prefix
1314
1347
  const validPrefixCommands: {cmd:ODTextCommand,newContent:string}[] = []
@@ -1671,7 +1704,7 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1671
1704
  const userId = res[1]
1672
1705
 
1673
1706
  try{
1674
- const user = await this.manager.client.users.fetch(userId)
1707
+ const user = await this.#manager.client.users.fetch(userId)
1675
1708
  if (!user){
1676
1709
  optionError("invalid_option",option,location,value,"user_not_found")
1677
1710
  }else{
@@ -1722,7 +1755,7 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1722
1755
  }
1723
1756
  }else if (type == "user"){
1724
1757
  try{
1725
- const user = await this.manager.client.users.fetch(mentionableId)
1758
+ const user = await this.#manager.client.users.fetch(mentionableId)
1726
1759
  if (!user){
1727
1760
  optionError("invalid_option",option,location,value,"mentionable_not_found")
1728
1761
  }else{
@@ -1750,9 +1783,9 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1750
1783
  }
1751
1784
  /**Start listening to the discord.js client `messageCreate` event. */
1752
1785
  startListeningToInteractions(){
1753
- this.manager.client.on("messageCreate",(msg) => {
1786
+ this.#manager.client.on("messageCreate",(msg) => {
1754
1787
  //return when not in main server or DM
1755
- if (!this.manager.mainServer || (msg.guild && msg.guild.id != this.manager.mainServer.id)) return
1788
+ if (!this.#manager.mainServer || (msg.guild && msg.guild.id != this.#manager.mainServer.id)) return
1756
1789
  this.#checkMessage(msg)
1757
1790
  })
1758
1791
  }
@@ -1778,6 +1811,8 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1778
1811
  return {valid,reason}
1779
1812
  }
1780
1813
  /**Callback on interaction from one of the registered text commands */
1814
+ onInteraction(commandPrefix:string,commandName:Extract<keyof IdList,string>, callback:ODTextCommandInteractionCallback): void
1815
+ onInteraction(commandPrefix:string,commandName:string|RegExp, callback:ODTextCommandInteractionCallback): void
1781
1816
  onInteraction(commandPrefix:string,commandName:string|RegExp, callback:ODTextCommandInteractionCallback){
1782
1817
  this.#interactionListeners.push({
1783
1818
  prefix:commandPrefix,
@@ -1796,6 +1831,27 @@ export class ODTextCommandManager extends ODManager<ODTextCommand> {
1796
1831
  this.#errorListeners.push(callback)
1797
1832
  }
1798
1833
 
1834
+ get<TextCommandId extends keyof IdList>(id:TextCommandId): IdList[TextCommandId]
1835
+ get(id:ODValidId): ODTextCommand|null
1836
+
1837
+ get(id:ODValidId): ODTextCommand|null {
1838
+ return super.get(id)
1839
+ }
1840
+
1841
+ remove<TextCommandId extends keyof IdList>(id:TextCommandId): IdList[TextCommandId]
1842
+ remove(id:ODValidId): ODTextCommand|null
1843
+
1844
+ remove(id:ODValidId): ODTextCommand|null {
1845
+ return super.remove(id)
1846
+ }
1847
+
1848
+ exists(id:keyof IdList): boolean
1849
+ exists(id:ODValidId): boolean
1850
+
1851
+ exists(id:ODValidId): boolean {
1852
+ return super.exists(id)
1853
+ }
1854
+
1799
1855
  add(data:ODTextCommand, overwrite?:boolean): boolean {
1800
1856
  const checkResult = this.#checkBuilderOptions(data.builder)
1801
1857
  if (!checkResult.valid && checkResult.reason == "required_after_optional") throw new ODSystemError("Invalid text command '"+data.id.value+"' => optional options are only allowed at the end of a command!")
@@ -1964,6 +2020,12 @@ export type ODContextMenuRegisteredResult = {
1964
2020
  }[]
1965
2021
  }
1966
2022
 
2023
+ /**## ODContextMenuManagerIdConstraint `type`
2024
+ * The constraint/layout for id mappings/interfaces of the `ODContextMenuManager` class.
2025
+ */
2026
+ export type ODContextMenuManagerIdConstraint = Record<string,ODContextMenu>
2027
+
2028
+
1967
2029
  /**## ODContextMenuManager `class`
1968
2030
  * This is an Open Discord client context menu manager.
1969
2031
  *
@@ -1971,12 +2033,12 @@ export type ODContextMenuRegisteredResult = {
1971
2033
  *
1972
2034
  * Here, you can add & remove context interactions & the bot will do the (de)registering.
1973
2035
  */
1974
- export class ODContextMenuManager extends ODManager<ODContextMenu> {
2036
+ export class ODContextMenuManager<IdList extends ODContextMenuManagerIdConstraint = ODContextMenuManagerIdConstraint> extends ODManager<ODContextMenu> {
1975
2037
  /**Alias to Open Discord debugger. */
1976
2038
  #debug: ODDebugger
1977
2039
 
1978
2040
  /**Refrerence to discord.js client. */
1979
- manager: ODClientManager
2041
+ #manager: ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>
1980
2042
  /**Discord.js application commands manager. */
1981
2043
  commandManager: discord.ApplicationCommandManager|null
1982
2044
  /**Collection of all interaction listeners. */
@@ -1986,10 +2048,10 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
1986
2048
  /**A utility class used to compare 2 context menus with each other. */
1987
2049
  comparator: ODContextMenuComparator = new ODContextMenuComparator()
1988
2050
 
1989
- constructor(debug:ODDebugger, manager:ODClientManager){
2051
+ constructor(debug:ODDebugger, manager:ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>){
1990
2052
  super(debug,"context menu")
1991
2053
  this.#debug = debug
1992
- this.manager = manager
2054
+ this.#manager = manager
1993
2055
  this.commandManager = (manager.client.application) ? manager.client.application.commands : null
1994
2056
  }
1995
2057
 
@@ -2035,7 +2097,7 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2035
2097
  }
2036
2098
  /**Create all context menus that are not registered yet.*/
2037
2099
  async createNewMenus(instances:ODContextMenu[],progress?:ODManualProgressBar){
2038
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2100
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2039
2101
  if (instances.length > 0 && progress){
2040
2102
  progress.max = instances.length
2041
2103
  progress.start()
@@ -2053,7 +2115,7 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2053
2115
  }
2054
2116
  /**Update all context menus that are already registered. */
2055
2117
  async updateExistingMenus(instances:ODContextMenu[],progress?:ODManualProgressBar){
2056
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2118
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2057
2119
  if (instances.length > 0 && progress){
2058
2120
  progress.max = instances.length
2059
2121
  progress.start()
@@ -2071,7 +2133,7 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2071
2133
  }
2072
2134
  /**Remove all context menus that are registered but unused by Open Discord. */
2073
2135
  async removeUnusedMenus(instances:ODContextMenuUniversalMenu[],guildId?:string,progress?:ODManualProgressBar){
2074
- if (!this.manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2136
+ if (!this.#manager.ready) throw new ODSystemError("Client isn't ready yet! Unable to register context menus!")
2075
2137
  if (!this.commandManager) throw new ODSystemError("Couldn't get client application to register context menus!")
2076
2138
  if (instances.length > 0 && progress){
2077
2139
  progress.max = instances.length
@@ -2110,9 +2172,9 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2110
2172
  }
2111
2173
  /**Start listening to the discord.js client `interactionCreate` event. */
2112
2174
  startListeningToInteractions(){
2113
- this.manager.client.on("interactionCreate",(interaction) => {
2175
+ this.#manager.client.on("interactionCreate",(interaction) => {
2114
2176
  //return when not in main server or DM
2115
- if (!this.manager.mainServer || (interaction.guild && interaction.guild.id != this.manager.mainServer.id)) return
2177
+ if (!this.#manager.mainServer || (interaction.guild && interaction.guild.id != this.#manager.mainServer.id)) return
2116
2178
 
2117
2179
  if (!interaction.isContextMenuCommand()) return
2118
2180
  const menu = this.getFiltered((menu) => menu.name == interaction.commandName)[0]
@@ -2128,6 +2190,9 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2128
2190
  })
2129
2191
  }
2130
2192
  /**Callback on interaction from one or multiple context menu's. */
2193
+ onInteraction(menuName:Extract<keyof IdList,string>, callback:ODContextMenuInteractionCallback): void
2194
+ onInteraction(menuName:string|RegExp, callback:ODContextMenuInteractionCallback): void
2195
+
2131
2196
  onInteraction(menuName:string|RegExp, callback:ODContextMenuInteractionCallback){
2132
2197
  this.#interactionListeners.push({
2133
2198
  name:menuName,
@@ -2140,6 +2205,27 @@ export class ODContextMenuManager extends ODManager<ODContextMenu> {
2140
2205
  ])
2141
2206
  }
2142
2207
  }
2208
+
2209
+ get<ContextMenuId extends keyof IdList>(id:ContextMenuId): IdList[ContextMenuId]
2210
+ get(id:ODValidId): ODContextMenu|null
2211
+
2212
+ get(id:ODValidId): ODContextMenu|null {
2213
+ return super.get(id)
2214
+ }
2215
+
2216
+ remove<ContextMenuId extends keyof IdList>(id:ContextMenuId): IdList[ContextMenuId]
2217
+ remove(id:ODValidId): ODContextMenu|null
2218
+
2219
+ remove(id:ODValidId): ODContextMenu|null {
2220
+ return super.remove(id)
2221
+ }
2222
+
2223
+ exists(id:keyof IdList): boolean
2224
+ exists(id:ODValidId): boolean
2225
+
2226
+ exists(id:ODValidId): boolean {
2227
+ return super.exists(id)
2228
+ }
2143
2229
  }
2144
2230
 
2145
2231
  /**## ODContextMenuUpdateFunction `type`
@@ -2199,7 +2285,7 @@ export class ODAutocompleteManager {
2199
2285
  #debug: ODDebugger
2200
2286
 
2201
2287
  /**Refrerence to discord.js client. */
2202
- manager: ODClientManager
2288
+ #manager: ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>
2203
2289
  /**Discord.js application commands manager. */
2204
2290
  commandManager: discord.ApplicationCommandManager|null
2205
2291
  /**Collection of all interaction listeners. */
@@ -2207,17 +2293,17 @@ export class ODAutocompleteManager {
2207
2293
  /**Set the soft limit for maximum amount of listeners. A warning will be shown when there are more listeners than this limit. */
2208
2294
  listenerLimit: number = 100
2209
2295
 
2210
- constructor(debug:ODDebugger, manager:ODClientManager){
2296
+ constructor(debug:ODDebugger, manager:ODClientManager<ODSlashCommandManagerIdConstraint,ODTextCommandManagerIdConstraint,ODContextMenuManagerIdConstraint>){
2211
2297
  this.#debug = debug
2212
- this.manager = manager
2298
+ this.#manager = manager
2213
2299
  this.commandManager = (manager.client.application) ? manager.client.application.commands : null
2214
2300
  }
2215
2301
 
2216
2302
  /**Start listening to the discord.js client `interactionCreate` event. */
2217
2303
  startListeningToInteractions(){
2218
- this.manager.client.on("interactionCreate",(interaction) => {
2304
+ this.#manager.client.on("interactionCreate",(interaction) => {
2219
2305
  //return when not in main server or DM
2220
- if (!this.manager.mainServer || (interaction.guild && interaction.guild.id != this.manager.mainServer.id)) return
2306
+ if (!this.#manager.mainServer || (interaction.guild && interaction.guild.id != this.#manager.mainServer.id)) return
2221
2307
 
2222
2308
  if (!interaction.isAutocomplete()) return
2223
2309
  this.#interactionListeners.forEach((listener) => {
@@ -30,6 +30,11 @@ export class ODCode extends ODManagerData {
30
30
  }
31
31
  }
32
32
 
33
+ /**## ODCodeManagerIdConstraint `type`
34
+ * The constraint/layout for id mappings/interfaces of the `ODCodeManager` class.
35
+ */
36
+ export type ODCodeManagerIdConstraint = Record<string,ODCode>
37
+
33
38
  /**## ODCodeManager `class`
34
39
  * This is an Open Discord code manager.
35
40
  *
@@ -37,7 +42,7 @@ export class ODCode extends ODManagerData {
37
42
  *
38
43
  * Use this to register a function/code which executes just before the startup screen. (90% is already loaded)
39
44
  */
40
- export class ODCodeManager extends ODManager<ODCode> {
45
+ export class ODCodeManager<IdList extends ODCodeManagerIdConstraint = ODCodeManagerIdConstraint> extends ODManager<ODCode> {
41
46
  constructor(debug:ODDebugger){
42
47
  super(debug,"code")
43
48
  }
@@ -55,4 +60,25 @@ export class ODCodeManager extends ODManager<ODCode> {
55
60
  }
56
61
  }
57
62
  }
63
+
64
+ get<CodeId extends keyof IdList>(id:CodeId): IdList[CodeId]
65
+ get(id:ODValidId): ODCode|null
66
+
67
+ get(id:ODValidId): ODCode|null {
68
+ return super.get(id)
69
+ }
70
+
71
+ remove<CodeId extends keyof IdList>(id:CodeId): IdList[CodeId]
72
+ remove(id:ODValidId): ODCode|null
73
+
74
+ remove(id:ODValidId): ODCode|null {
75
+ return super.remove(id)
76
+ }
77
+
78
+ exists(id:keyof IdList): boolean
79
+ exists(id:ODValidId): boolean
80
+
81
+ exists(id:ODValidId): boolean {
82
+ return super.exists(id)
83
+ }
58
84
  }
@@ -1,12 +1,17 @@
1
1
  ///////////////////////////////////////
2
2
  //CONFIG MODULE
3
3
  ///////////////////////////////////////
4
- import { ODId, ODManager, ODManagerData, ODPromiseVoid, ODSystemError, ODValidId } from "./base"
4
+ import { ODId, ODManager, ODManagerData, ODPromiseVoid, ODSystemError, ODValidId, ODValidJsonType } from "./base"
5
5
  import nodepath from "path"
6
6
  import { ODDebugger } from "./console"
7
7
  import fs from "fs"
8
8
  import * as fjs from "formatted-json-stringify"
9
9
 
10
+ /**## ODConfigManagerIdConstraint `type`
11
+ * The constraint/layout for id mappings/interfaces of the `ODConfigManager` class.
12
+ */
13
+ export type ODConfigManagerIdConstraint = Record<string,ODConfig<any>>
14
+
10
15
  /**## ODConfigManager `class`
11
16
  * This is an Open Discord config manager.
12
17
  *
@@ -14,7 +19,7 @@ import * as fjs from "formatted-json-stringify"
14
19
  *
15
20
  * You can use this class to get/change/add a config file (`ODConfig`) in your plugin!
16
21
  */
17
- export class ODConfigManager extends ODManager<ODConfig> {
22
+ export class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConfigManagerIdConstraint> extends ODManager<ODConfig<any>> {
18
23
  /**Alias to Open Discord debugger. */
19
24
  #debug: ODDebugger
20
25
 
@@ -22,7 +27,7 @@ export class ODConfigManager extends ODManager<ODConfig> {
22
27
  super(debug,"config")
23
28
  this.#debug = debug
24
29
  }
25
- add(data:ODConfig|ODConfig[],overwrite?:boolean): boolean {
30
+ add(data:ODConfig<any>|ODConfig<any>[],overwrite?:boolean): boolean {
26
31
  if (Array.isArray(data)) data.forEach((d) => d.useDebug(this.#debug))
27
32
  else data.useDebug(this.#debug)
28
33
  return super.add(data,overwrite)
@@ -37,6 +42,27 @@ export class ODConfigManager extends ODManager<ODConfig> {
37
42
  }
38
43
  }
39
44
  }
45
+
46
+ get<ConfigId extends keyof IdList>(id:ConfigId): IdList[ConfigId]
47
+ get(id:ODValidId): ODConfig<any>|null
48
+
49
+ get(id:ODValidId): ODConfig<any>|null {
50
+ return super.get(id)
51
+ }
52
+
53
+ remove<ConfigId extends keyof IdList>(id:ConfigId): IdList[ConfigId]
54
+ remove(id:ODValidId): ODConfig<any>|null
55
+
56
+ remove(id:ODValidId): ODConfig<any>|null {
57
+ return super.remove(id)
58
+ }
59
+
60
+ exists(id:keyof IdList): boolean
61
+ exists(id:ODValidId): boolean
62
+
63
+ exists(id:ODValidId): boolean {
64
+ return super.exists(id)
65
+ }
40
66
  }
41
67
 
42
68
  /**## ODConfig `class`
@@ -45,13 +71,13 @@ export class ODConfigManager extends ODManager<ODConfig> {
45
71
  *
46
72
  * You can use this class if you want to create your own config implementation (e.g. `yml`, `xml`,...)!
47
73
  */
48
- export class ODConfig extends ODManagerData {
74
+ export class ODConfig<Data extends any> extends ODManagerData {
49
75
  /**The name of the file with extension. */
50
76
  file: string = ""
51
77
  /**The path to the file relative to the main directory. */
52
78
  path: string = ""
53
79
  /**An object/array of the entire config file! Variables inside it can be edited while the bot is running! */
54
- data: any
80
+ data: Data
55
81
  /**Is this config already initiated? */
56
82
  initiated: boolean = false
57
83
  /**An array of listeners to run when the config gets reloaded. These are not executed on the initial loading. */
@@ -104,7 +130,7 @@ export class ODConfig extends ODManagerData {
104
130
  * //create a config with custom dir: ./plugins/testplugin/test.json
105
131
  * const config = new api.ODJsonConfig("plugin-config","test.json","./plugins/testplugin/")
106
132
  */
107
- export class ODJsonConfig extends ODConfig {
133
+ export class ODJsonConfig<Data extends any> extends ODConfig<Data> {
108
134
  formatter: fjs.custom.BaseFormatter
109
135
 
110
136
  constructor(id:ODValidId, file:string, customPath?:string, formatter?:fjs.custom.BaseFormatter){
@@ -148,7 +174,7 @@ export class ODJsonConfig extends ODConfig {
148
174
  save(): ODPromiseVoid {
149
175
  if (!this.initiated) throw new ODSystemError("Unable to save config \""+nodepath.join("./",this.path)+"\", the file hasn't been initiated yet!")
150
176
  try{
151
- const contents = this.formatter.stringify(this.data)
177
+ const contents = this.formatter.stringify(this.data as ODValidJsonType)
152
178
  fs.writeFileSync(this.path,contents)
153
179
  super.save()
154
180
  }catch(err){
@@ -580,6 +580,11 @@ export class ODLiveStatusUrlSource extends ODLiveStatusSource {
580
580
  }
581
581
  }
582
582
 
583
+ /**## ODLiveStatusManagerIdConstraint `type`
584
+ * The constraint/layout for id mappings/interfaces of the `ODLiveStatusManager` class.
585
+ */
586
+ export type ODLiveStatusManagerIdConstraint = Record<string,ODLiveStatusSource>
587
+
583
588
  /**## ODLiveStatusManager `class`
584
589
  * This is the Open Discord livestatus manager.
585
590
  *
@@ -588,7 +593,7 @@ export class ODLiveStatusUrlSource extends ODLiveStatusSource {
588
593
  * You can use this to customise or add stuff to the LiveStatus system.
589
594
  * Access it in the global `opendiscord.startscreen.livestatus` variable!
590
595
  */
591
- export class ODLiveStatusManager extends ODManager<ODLiveStatusSource> {
596
+ export class ODLiveStatusManager<IdList extends ODLiveStatusManagerIdConstraint = ODLiveStatusManagerIdConstraint> extends ODManager<ODLiveStatusSource> {
592
597
  /**The class responsible for rendering the livestatus messages. */
593
598
  renderer: ODLiveStatusRenderer
594
599
  /**A reference to the ODMain or "opendiscord" global variable */
@@ -614,6 +619,27 @@ export class ODLiveStatusManager extends ODManager<ODLiveStatusSource> {
614
619
  useMain(main:ODMain){
615
620
  this.#main = main
616
621
  }
622
+
623
+ get<LiveStatusId extends keyof IdList>(id:LiveStatusId): IdList[LiveStatusId]
624
+ get(id:ODValidId): ODLiveStatusSource|null
625
+
626
+ get(id:ODValidId): ODLiveStatusSource|null {
627
+ return super.get(id)
628
+ }
629
+
630
+ remove<LiveStatusId extends keyof IdList>(id:LiveStatusId): IdList[LiveStatusId]
631
+ remove(id:ODValidId): ODLiveStatusSource|null
632
+
633
+ remove(id:ODValidId): ODLiveStatusSource|null {
634
+ return super.remove(id)
635
+ }
636
+
637
+ exists(id:keyof IdList): boolean
638
+ exists(id:ODValidId): boolean
639
+
640
+ exists(id:ODValidId): boolean {
641
+ return super.exists(id)
642
+ }
617
643
  }
618
644
 
619
645
  /**## ODLiveStatusRenderer `class`