@open-discord-bots/framework 0.1.1 → 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 (78) 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/index.d.ts +1 -0
  50. package/dist/index.js +3 -1
  51. package/dist/utilities/index.js +1 -0
  52. package/package.json +1 -1
  53. package/src/api/main.ts +10 -10
  54. package/src/api/modules/action.ts +37 -4
  55. package/src/api/modules/base.ts +30 -3
  56. package/src/api/modules/builder.ts +226 -21
  57. package/src/api/modules/checker.ts +292 -17
  58. package/src/api/modules/client.ts +129 -43
  59. package/src/api/modules/code.ts +27 -1
  60. package/src/api/modules/config.ts +33 -7
  61. package/src/api/modules/console.ts +27 -1
  62. package/src/api/modules/cooldown.ts +27 -1
  63. package/src/api/modules/database.ts +55 -4
  64. package/src/api/modules/event.ts +24 -1
  65. package/src/api/modules/flag.ts +27 -1
  66. package/src/api/modules/helpmenu.ts +55 -2
  67. package/src/api/modules/language.ts +35 -1
  68. package/src/api/modules/permission.ts +27 -1
  69. package/src/api/modules/plugin.ts +55 -3
  70. package/src/api/modules/post.ts +27 -1
  71. package/src/api/modules/progressbar.ts +56 -3
  72. package/src/api/modules/responder.ts +184 -21
  73. package/src/api/modules/session.ts +27 -1
  74. package/src/api/modules/startscreen.ts +33 -7
  75. package/src/api/modules/stat.ts +79 -8
  76. package/src/api/modules/verifybar.ts +31 -5
  77. package/src/api/modules/worker.ts +22 -1
  78. package/src/utilities/index.ts +1 -0
@@ -4,6 +4,11 @@
4
4
  import { ODId, ODValidId, ODManager, ODSystemError, ODManagerData } from "./base"
5
5
  import { ODDebugger } from "./console"
6
6
 
7
+ /**## ODCooldownManagerIdConstraint `type`
8
+ * The constraint/layout for id mappings/interfaces of the `ODCooldownManager` class.
9
+ */
10
+ export type ODCooldownManagerIdConstraint = Record<string,ODCooldown<object>>
11
+
7
12
  /**## ODCooldownManager `class`
8
13
  * This is an Open Discord cooldown manager.
9
14
  *
@@ -11,7 +16,7 @@ import { ODDebugger } from "./console"
11
16
  *
12
17
  * There are many types of cooldowns available, but you can also create your own!
13
18
  */
14
- export class ODCooldownManager extends ODManager<ODCooldown<object>> {
19
+ export class ODCooldownManager<IdList extends ODCooldownManagerIdConstraint = ODCooldownManagerIdConstraint> extends ODManager<ODCooldown<object>> {
15
20
  constructor(debug:ODDebugger){
16
21
  super(debug,"cooldown")
17
22
  }
@@ -21,6 +26,27 @@ export class ODCooldownManager extends ODManager<ODCooldown<object>> {
21
26
  await cooldown.init()
22
27
  }
23
28
  }
29
+
30
+ get<CooldownId extends keyof IdList>(id:CooldownId): IdList[CooldownId]
31
+ get(id:ODValidId): ODCooldown<object>|null
32
+
33
+ get(id:ODValidId): ODCooldown<object>|null {
34
+ return super.get(id)
35
+ }
36
+
37
+ remove<CooldownId extends keyof IdList>(id:CooldownId): IdList[CooldownId]
38
+ remove(id:ODValidId): ODCooldown<object>|null
39
+
40
+ remove(id:ODValidId): ODCooldown<object>|null {
41
+ return super.remove(id)
42
+ }
43
+
44
+ exists(id:keyof IdList): boolean
45
+ exists(id:ODValidId): boolean
46
+
47
+ exists(id:ODValidId): boolean {
48
+ return super.exists(id)
49
+ }
24
50
  }
25
51
 
26
52
  /**## ODCooldownData `class`
@@ -7,6 +7,11 @@ import nodepath from "path"
7
7
  import { ODDebugger } from "./console"
8
8
  import * as fjs from "formatted-json-stringify"
9
9
 
10
+ /**## ODDatabaseManagerIdConstraint `type`
11
+ * The constraint/layout for id mappings/interfaces of the `ODDatabaseManager` class.
12
+ */
13
+ export type ODDatabaseManagerIdConstraint = Record<string,ODDatabase<{}>>
14
+
10
15
  /**## ODDatabaseManager `class`
11
16
  * This is an Open Discord database 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/add a database (`ODDatabase`) in your plugin!
16
21
  */
17
- export class ODDatabaseManager extends ODManager<ODDatabase> {
22
+ export class ODDatabaseManager<IdList extends ODDatabaseManagerIdConstraint = ODDatabaseManagerIdConstraint> extends ODManager<ODDatabase<{}>> {
18
23
  constructor(debug:ODDebugger){
19
24
  super(debug,"database")
20
25
  }
@@ -29,15 +34,43 @@ export class ODDatabaseManager extends ODManager<ODDatabase> {
29
34
  }
30
35
  }
31
36
  }
37
+
38
+ get<DatabaseId extends keyof IdList>(id:DatabaseId): IdList[DatabaseId]
39
+ get(id:ODValidId): ODDatabase<{}>|null
40
+
41
+ get(id:ODValidId): ODDatabase<{}>|null {
42
+ return super.get(id)
43
+ }
44
+
45
+ remove<DatabaseId extends keyof IdList>(id:DatabaseId): IdList[DatabaseId]
46
+ remove(id:ODValidId): ODDatabase<{}>|null
47
+
48
+ remove(id:ODValidId): ODDatabase<{}>|null {
49
+ return super.remove(id)
50
+ }
51
+
52
+ exists(id:keyof IdList): boolean
53
+ exists(id:ODValidId): boolean
54
+
55
+ exists(id:ODValidId): boolean {
56
+ return super.exists(id)
57
+ }
32
58
  }
33
59
 
60
+
61
+ /**## ODDatabaseIdConstraint `type`
62
+ * The constraint/layout for id mappings/interfaces of the `ODDatabase` class.
63
+ */
64
+ export type ODDatabaseIdConstraint = Record<string,ODValidJsonType>
65
+
66
+
34
67
  /**## ODDatabase `class`
35
68
  * This is an Open Discord database template.
36
69
  * This class doesn't do anything at all, it just gives a template & basic methods for a database. Use `ODJsonDatabase` instead!
37
70
  *
38
71
  * You can use this class if you want to create your own database implementation (e.g. `mongodb`, `mysql`,...)!
39
72
  */
40
- export class ODDatabase extends ODManagerData {
73
+ export class ODDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODManagerData {
41
74
  /**The name of the file with extension. */
42
75
  file: string = ""
43
76
  /**The path to the file relative to the main directory. */
@@ -48,22 +81,32 @@ export class ODDatabase extends ODManagerData {
48
81
  //nothing
49
82
  }
50
83
  /**Add/Overwrite a specific category & key in the database. Returns `true` when overwritten. */
84
+ set<CategoryId extends keyof IdList>(category:CategoryId, key:string, value:IdList[CategoryId]): ODOptionalPromise<boolean>
85
+ set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean>
51
86
  set(category:string, key:string, value:ODValidJsonType): ODOptionalPromise<boolean> {
52
87
  return false
53
88
  }
54
89
  /**Get a specific category & key in the database */
90
+ get<CategoryId extends keyof IdList>(category:CategoryId, key:string): ODOptionalPromise<IdList[CategoryId]|undefined>
91
+ get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
55
92
  get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
56
93
  return undefined
57
94
  }
58
95
  /**Delete a specific category & key in the database */
96
+ delete<CategoryId extends keyof IdList>(category:CategoryId, key:string): ODOptionalPromise<boolean>
97
+ delete(category:string, key:string): ODOptionalPromise<boolean>
59
98
  delete(category:string, key:string): ODOptionalPromise<boolean> {
60
99
  return false
61
100
  }
62
101
  /**Check if a specific category & key exists in the database */
102
+ exists(category:keyof IdList, key:string): ODOptionalPromise<boolean>
103
+ exists(category:string, key:string): ODOptionalPromise<boolean>
63
104
  exists(category:string, key:string): ODOptionalPromise<boolean> {
64
105
  return false
65
106
  }
66
107
  /**Get a specific category in the database */
108
+ getCategory<CategoryId extends keyof IdList>(category:CategoryId): ODOptionalPromise<{key:string, value:IdList[CategoryId]}[]|undefined>
109
+ getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
67
110
  getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
68
111
  return undefined
69
112
  }
@@ -85,7 +128,7 @@ export type ODJsonDatabaseStructure = {category:string, key:string, value:ODVali
85
128
  *
86
129
  * You can use this class if you want to add your own database or to use an existing one!
87
130
  */
88
- export class ODJsonDatabase extends ODDatabase {
131
+ export class ODJsonDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODDatabase<IdList> {
89
132
  constructor(id:ODValidId, file:string, customPath?:string){
90
133
  super(id)
91
134
  this.file = (file.endsWith(".json")) ? file : file+".json"
@@ -120,6 +163,8 @@ export class ODJsonDatabase extends ODDatabase {
120
163
  * const data = database.getData("category","key") //data will be the value
121
164
  * //You need an ODJsonDatabase class named "database" for this example to work!
122
165
  */
166
+ get<CategoryId extends keyof IdList>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>
167
+ get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
123
168
  get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
124
169
  const currentList = this.#system.getData()
125
170
  const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
@@ -145,6 +190,8 @@ export class ODJsonDatabase extends ODDatabase {
145
190
  return tempresult ? true : false
146
191
  }
147
192
  /**Get all values in `category`. Returns `undefined` when non-existent! */
193
+ getCategory<CategoryId extends keyof IdList>(category:CategoryId): ODOptionalPromise<{key:string, value:IdList[CategoryId]}[]|undefined>
194
+ getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
148
195
  getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
149
196
  const currentList = this.#system.getData()
150
197
  const tempresult = currentList.filter((d) => (d.category === category))
@@ -186,7 +233,7 @@ export class ODJsonDatabase extends ODDatabase {
186
233
  * This one is exactly the same as `ODJsonDatabase`, but it has a formatter from the `formatted-json-stringify` package.
187
234
  * This can help you organise it a little bit better!
188
235
  */
189
- export class ODFormattedJsonDatabase extends ODDatabase {
236
+ export class ODFormattedJsonDatabase<IdList extends ODDatabaseIdConstraint = ODDatabaseIdConstraint> extends ODDatabase<IdList> {
190
237
  /**The formatter to use on the database array */
191
238
  formatter: fjs.ArrayFormatter
192
239
 
@@ -225,6 +272,8 @@ export class ODFormattedJsonDatabase extends ODDatabase {
225
272
  * const data = database.getData("category","key") //data will be the value
226
273
  * //You need an ODFormattedJsonDatabase class named "database" for this example to work!
227
274
  */
275
+ get<CategoryId extends keyof IdList>(category: CategoryId, key: string): ODOptionalPromise<IdList[CategoryId] | undefined>
276
+ get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined>
228
277
  get(category:string, key:string): ODOptionalPromise<ODValidJsonType|undefined> {
229
278
  const currentList = this.#system.getData()
230
279
  const tempresult = currentList.find((d) => (d.category === category) && (d.key === key))
@@ -250,6 +299,8 @@ export class ODFormattedJsonDatabase extends ODDatabase {
250
299
  return tempresult ? true : false
251
300
  }
252
301
  /**Get all values in `category`. Returns `undefined` when non-existent! */
302
+ getCategory<CategoryId extends keyof IdList>(category:CategoryId): ODOptionalPromise<{key:string, value:IdList[CategoryId]}[]|undefined>
303
+ getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined>
253
304
  getCategory(category:string): ODOptionalPromise<{key:string, value:ODValidJsonType}[]|undefined> {
254
305
  const currentList = this.#system.getData()
255
306
  const tempresult = currentList.filter((d) => (d.category === category))
@@ -70,6 +70,11 @@ export class ODEvent extends ODManagerData {
70
70
  }
71
71
  }
72
72
 
73
+ /**## ODEventManagerIdConstraint `type`
74
+ * The constraint/layout for id mappings/interfaces of the `ODEventManager` class.
75
+ */
76
+ export type ODEventManagerIdConstraint = Record<string,ODEvent>
77
+
73
78
  /**## ODEventManager `class`
74
79
  * This is an Open Discord event manager.
75
80
  *
@@ -78,7 +83,7 @@ export class ODEvent extends ODManagerData {
78
83
  * It's not recommended to create this class yourself. Plugin events should be registered in their `plugin.json` file instead.
79
84
  * All events are available in the `opendiscord.events` global!
80
85
  */
81
- export class ODEventManager extends ODManager<ODEvent> {
86
+ export class ODEventManager<IdList extends ODEventManagerIdConstraint = ODEventManagerIdConstraint> extends ODManager<ODEvent> {
82
87
  /**Reference to the Open Discord debugger */
83
88
  #debug: ODDebugger
84
89
 
@@ -91,9 +96,27 @@ export class ODEventManager extends ODManager<ODEvent> {
91
96
  data.useDebug(this.#debug)
92
97
  return super.add(data,overwrite)
93
98
  }
99
+
100
+ get<EventId extends keyof IdList>(id:EventId): IdList[EventId]
101
+ get(id:ODValidId): ODEvent|null
102
+
103
+ get(id:ODValidId): ODEvent|null {
104
+ return super.get(id)
105
+ }
106
+
107
+ remove<EventId extends keyof IdList>(id:EventId): IdList[EventId]
108
+ remove(id:ODValidId): ODEvent|null
109
+
94
110
  remove(id:ODValidId): ODEvent|null {
95
111
  const data = super.remove(id)
96
112
  if (data) data.useDebug(null)
97
113
  return data
98
114
  }
115
+
116
+ exists(id:keyof IdList): boolean
117
+ exists(id:ODValidId): boolean
118
+
119
+ exists(id:ODValidId): boolean {
120
+ return super.exists(id)
121
+ }
99
122
  }
@@ -53,13 +53,18 @@ export class ODFlag extends ODManagerData {
53
53
  }
54
54
  }
55
55
 
56
+ /**## ODFlagManagerIdConstraint `type`
57
+ * The constraint/layout for id mappings/interfaces of the `ODFlagManager` class.
58
+ */
59
+ export type ODFlagManagerIdConstraint = Record<string,ODFlag>
60
+
56
61
  /**## ODFlagManager `class`
57
62
  * This is an Open Discord flag manager.
58
63
  *
59
64
  * This class is responsible for managing & initiating all flags of the bot.
60
65
  * It also contains a shortcut for initiating all flags.
61
66
  */
62
- export class ODFlagManager extends ODManager<ODFlag> {
67
+ export class ODFlagManager<IdList extends ODFlagManagerIdConstraint = ODFlagManagerIdConstraint> extends ODManager<ODFlag> {
63
68
  constructor(debug:ODDebugger){
64
69
  super(debug,"flag")
65
70
  }
@@ -70,4 +75,25 @@ export class ODFlagManager extends ODManager<ODFlag> {
70
75
  flag.detectProcessParams(false)
71
76
  })
72
77
  }
78
+
79
+ get<FlagId extends keyof IdList>(id:FlagId): IdList[FlagId]
80
+ get(id:ODValidId): ODFlag|null
81
+
82
+ get(id:ODValidId): ODFlag|null {
83
+ return super.get(id)
84
+ }
85
+
86
+ remove<FlagId extends keyof IdList>(id:FlagId): IdList[FlagId]
87
+ remove(id:ODValidId): ODFlag|null
88
+
89
+ remove(id:ODValidId): ODFlag|null {
90
+ return super.remove(id)
91
+ }
92
+
93
+ exists(id:keyof IdList): boolean
94
+ exists(id:ODValidId): boolean
95
+
96
+ exists(id:ODValidId): boolean {
97
+ return super.exists(id)
98
+ }
73
99
  }
@@ -92,13 +92,18 @@ export class ODHelpMenuCommandComponent extends ODHelpMenuComponent {
92
92
  }
93
93
  }
94
94
 
95
+ /**## ODHelpMenuCategoryIdConstraint `type`
96
+ * The constraint/layout for id mappings/interfaces of the `ODHelpMenuCategory` class.
97
+ */
98
+ export type ODHelpMenuCategoryIdConstraint = Record<string,ODHelpMenuComponent>
99
+
95
100
  /**## ODHelpMenuCategory `class`
96
101
  * This is an Open Discord help menu category.
97
102
  *
98
103
  * Every category in the help menu is an embed field by default.
99
104
  * Try to limit the amount of components per category.
100
105
  */
101
- export class ODHelpMenuCategory extends ODManager<ODHelpMenuComponent> {
106
+ export class ODHelpMenuCategory<IdList extends ODHelpMenuCategoryIdConstraint = ODHelpMenuCategoryIdConstraint> extends ODManager<ODHelpMenuComponent> {
102
107
  /**The id of this category. */
103
108
  id: ODId
104
109
  /**The priority of this category. The higher, the earlier it will appear in the menu. */
@@ -138,6 +143,27 @@ export class ODHelpMenuCategory extends ODManager<ODHelpMenuComponent> {
138
143
  //only return the non-empty components
139
144
  return result.filter((component) => component !== "").join("\n\n")
140
145
  }
146
+
147
+ get<HelpMenuComponentId extends keyof IdList>(id:HelpMenuComponentId): IdList[HelpMenuComponentId]
148
+ get(id:ODValidId): ODHelpMenuComponent|null
149
+
150
+ get(id:ODValidId): ODHelpMenuComponent|null {
151
+ return super.get(id)
152
+ }
153
+
154
+ remove<HelpMenuComponentId extends keyof IdList>(id:HelpMenuComponentId): IdList[HelpMenuComponentId]
155
+ remove(id:ODValidId): ODHelpMenuComponent|null
156
+
157
+ remove(id:ODValidId): ODHelpMenuComponent|null {
158
+ return super.remove(id)
159
+ }
160
+
161
+ exists(id:keyof IdList): boolean
162
+ exists(id:ODValidId): boolean
163
+
164
+ exists(id:ODValidId): boolean {
165
+ return super.exists(id)
166
+ }
141
167
  }
142
168
 
143
169
  /**## ODHelpMenuRenderResult `type`
@@ -147,6 +173,12 @@ export class ODHelpMenuCategory extends ODManager<ODHelpMenuComponent> {
147
173
  */
148
174
  export type ODHelpMenuRenderResult = {name:string, value:string}[][]
149
175
 
176
+
177
+ /**## ODHelpMenuManagerIdConstraint `type`
178
+ * The constraint/layout for id mappings/interfaces of the `ODHelpMenuManager` class.
179
+ */
180
+ export type ODHelpMenuManagerIdConstraint = Record<string,ODHelpMenuCategory>
181
+
150
182
  /**## ODHelpMenuManager `class`
151
183
  * This is an Open Discord help menu manager.
152
184
  *
@@ -155,7 +187,7 @@ export type ODHelpMenuRenderResult = {name:string, value:string}[][]
155
187
  *
156
188
  * Fewer Categories == More Clean Menu
157
189
  */
158
- export class ODHelpMenuManager extends ODManager<ODHelpMenuCategory> {
190
+ export class ODHelpMenuManager<IdList extends ODHelpMenuManagerIdConstraint = ODHelpMenuManagerIdConstraint> extends ODManager<ODHelpMenuCategory> {
159
191
  /**Alias to Open Discord debugger. */
160
192
  #debug: ODDebugger
161
193
  /**The amount of categories per-page. */
@@ -213,4 +245,25 @@ export class ODHelpMenuManager extends ODManager<ODHelpMenuCategory> {
213
245
 
214
246
  return result
215
247
  }
248
+
249
+ get<HelpMenuCategoryId extends keyof IdList>(id:HelpMenuCategoryId): IdList[HelpMenuCategoryId]
250
+ get(id:ODValidId): ODHelpMenuCategory|null
251
+
252
+ get(id:ODValidId): ODHelpMenuCategory|null {
253
+ return super.get(id)
254
+ }
255
+
256
+ remove<HelpMenuCategoryId extends keyof IdList>(id:HelpMenuCategoryId): IdList[HelpMenuCategoryId]
257
+ remove(id:ODValidId): ODHelpMenuCategory|null
258
+
259
+ remove(id:ODValidId): ODHelpMenuCategory|null {
260
+ return super.remove(id)
261
+ }
262
+
263
+ exists(id:keyof IdList): boolean
264
+ exists(id:ODValidId): boolean
265
+
266
+ exists(id:ODValidId): boolean {
267
+ return super.exists(id)
268
+ }
216
269
  }
@@ -22,6 +22,11 @@ export interface ODLanguageMetadata {
22
22
  automated:boolean
23
23
  }
24
24
 
25
+ /**## ODLanguageManagerIdConstraint `type`
26
+ * The constraint/layout for id mappings/interfaces of the `ODLanguageManager` class.
27
+ */
28
+ export type ODLanguageManagerIdConstraint = Record<string,ODLanguage>
29
+
25
30
  /**## ODLanguageManager `class`
26
31
  * This is an Open Discord language manager.
27
32
  *
@@ -30,7 +35,7 @@ export interface ODLanguageMetadata {
30
35
  *
31
36
  * Add new languages using the `ODlanguage` class in your plugin!
32
37
  */
33
- export class ODLanguageManager extends ODManager<ODLanguage> {
38
+ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = ODLanguageManagerIdConstraint,TranslationIds extends string = string> extends ODManager<ODLanguage> {
34
39
  /**The currently selected language. */
35
40
  current: ODLanguage|null = null
36
41
  /**The currently selected backup language. (used when translation missing in current language) */
@@ -47,6 +52,8 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
47
52
  }
48
53
 
49
54
  /**Set the current language by providing the ID of a language which is registered in this manager. */
55
+ setCurrentLanguage(id:keyof IdList): void
56
+ setCurrentLanguage(id:ODValidId): void
50
57
  setCurrentLanguage(id:ODValidId){
51
58
  this.current = this.get(id)
52
59
  const languageId = this.current?.id.value ?? "<unknown-id>"
@@ -61,6 +68,8 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
61
68
  return (this.current) ? this.current : null
62
69
  }
63
70
  /**Set the backup language by providing the ID of a language which is registered in this manager. */
71
+ setBackupLanguage(id:keyof IdList): void
72
+ setBackupLanguage(id:ODValidId): void
64
73
  setBackupLanguage(id:ODValidId){
65
74
  this.backup = this.get(id)
66
75
  const languageId = this.backup?.id.value ?? "<unknown-id>"
@@ -84,6 +93,8 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
84
93
  return (this.current) ? this.current.id.value : ""
85
94
  }
86
95
  /**Get a translation string by JSON location. (e.g. `"checker.system.typeError"`) */
96
+ getTranslation(id:TranslationIds): string
97
+ getTranslation(id:string): string|null
87
98
  getTranslation(id:string): string|null {
88
99
  if (!this.current) return this.#getBackupTranslation(id)
89
100
 
@@ -120,6 +131,8 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
120
131
  else return null
121
132
  }
122
133
  /**Get a backup translation string by JSON location and replace `{0}`,`{1}`,`{2}`,... with the provided parameters. */
134
+ getTranslationWithParams(id:TranslationIds, params:string[]): string
135
+ getTranslationWithParams(id:string, params:string[]): string|null
123
136
  getTranslationWithParams(id:string, params:string[]): string|null {
124
137
  let translation = this.getTranslation(id)
125
138
  if (!translation) return translation
@@ -141,6 +154,27 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
141
154
  }
142
155
  }
143
156
  }
157
+
158
+ get<LanguageId extends keyof IdList>(id:LanguageId): IdList[LanguageId]
159
+ get(id:ODValidId): ODLanguage|null
160
+
161
+ get(id:ODValidId): ODLanguage|null {
162
+ return super.get(id)
163
+ }
164
+
165
+ remove<LanguageId extends keyof IdList>(id:LanguageId): IdList[LanguageId]
166
+ remove(id:ODValidId): ODLanguage|null
167
+
168
+ remove(id:ODValidId): ODLanguage|null {
169
+ return super.remove(id)
170
+ }
171
+
172
+ exists(id:keyof IdList): boolean
173
+ exists(id:ODValidId): boolean
174
+
175
+ exists(id:ODValidId): boolean {
176
+ return super.exists(id)
177
+ }
144
178
  }
145
179
 
146
180
  /**## ODLanguage `class`
@@ -115,6 +115,11 @@ export type ODPermissionCommandResult = {
115
115
  isAdmin:boolean
116
116
  }
117
117
 
118
+ /**## ODPermissionManagerIdConstraint `type`
119
+ * The constraint/layout for id mappings/interfaces of the `ODPermissionManager` class.
120
+ */
121
+ export type ODPermissionManagerIdConstraint = Record<string,ODPermission>
122
+
118
123
  /**## ODPermissionManager `class`
119
124
  * This is an Open Discord permission manager.
120
125
  *
@@ -123,7 +128,7 @@ export type ODPermissionCommandResult = {
123
128
  *
124
129
  * Add new permissions using the `ODPermission` class in your plugin!
125
130
  */
126
- export class ODPermissionManager extends ODManager<ODPermission> {
131
+ export class ODPermissionManager<IdList extends ODPermissionManagerIdConstraint = ODPermissionManagerIdConstraint> extends ODManager<ODPermission> {
127
132
  /**Alias for Open Discord debugger. */
128
133
  #debug: ODDebugger
129
134
  /**The function for calculating permissions in this manager. */
@@ -337,4 +342,25 @@ export class ODPermissionManager extends ODManager<ODPermission> {
337
342
  return {hasPerms:true,isAdmin}
338
343
  }
339
344
  }
345
+
346
+ get<PermissionId extends keyof IdList>(id:PermissionId): IdList[PermissionId]
347
+ get(id:ODValidId): ODPermission|null
348
+
349
+ get(id:ODValidId): ODPermission|null {
350
+ return super.get(id)
351
+ }
352
+
353
+ remove<PermissionId extends keyof IdList>(id:PermissionId): IdList[PermissionId]
354
+ remove(id:ODValidId): ODPermission|null
355
+
356
+ remove(id:ODValidId): ODPermission|null {
357
+ return super.remove(id)
358
+ }
359
+
360
+ exists(id:keyof IdList): boolean
361
+ exists(id:ODValidId): boolean
362
+
363
+ exists(id:ODValidId): boolean {
364
+ return super.exists(id)
365
+ }
340
366
  }
@@ -15,6 +15,11 @@ export interface ODUnknownCrashedPlugin {
15
15
  description:string
16
16
  }
17
17
 
18
+ /**## ODPluginManagerIdConstraint `type`
19
+ * The constraint/layout for id mappings/interfaces of the `ODPluginManager` class.
20
+ */
21
+ export type ODPluginManagerIdConstraint = Record<string,ODPlugin>
22
+
18
23
  /**## ODPluginManager `class`
19
24
  * This is an Open Discord plugin manager.
20
25
  *
@@ -24,9 +29,9 @@ export interface ODUnknownCrashedPlugin {
24
29
  *
25
30
  * Use `isPluginLoaded()` to check if a plugin has been loaded.
26
31
  */
27
- export class ODPluginManager extends ODManager<ODPlugin> {
32
+ export class ODPluginManager<IdList extends ODPluginManagerIdConstraint = ODPluginManagerIdConstraint,PluginClassIdList extends ODPluginClassManagerIdConstraint = ODPluginClassManagerIdConstraint> extends ODManager<ODPlugin> {
28
33
  /**A manager for all custom managers registered by plugins. */
29
- classes: ODPluginClassManager
34
+ classes: ODPluginClassManager<PluginClassIdList>
30
35
  /**A list of basic details from all plugins that crashed while loading the `plugin.json` file. */
31
36
  unknownCrashedPlugins: ODUnknownCrashedPlugin[] = []
32
37
 
@@ -41,6 +46,27 @@ export class ODPluginManager extends ODManager<ODPlugin> {
41
46
  const plugin = this.get(newId)
42
47
  return (plugin !== null && plugin.executed)
43
48
  }
49
+
50
+ get<PluginId extends keyof IdList>(id:PluginId): IdList[PluginId]
51
+ get(id:ODValidId): ODPlugin|null
52
+
53
+ get(id:ODValidId): ODPlugin|null {
54
+ return super.get(id)
55
+ }
56
+
57
+ remove<PluginId extends keyof IdList>(id:PluginId): IdList[PluginId]
58
+ remove(id:ODValidId): ODPlugin|null
59
+
60
+ remove(id:ODValidId): ODPlugin|null {
61
+ return super.remove(id)
62
+ }
63
+
64
+ exists(id:keyof IdList): boolean
65
+ exists(id:ODValidId): boolean
66
+
67
+ exists(id:ODValidId): boolean {
68
+ return super.exists(id)
69
+ }
44
70
  }
45
71
 
46
72
  /**## ODPluginData `interface`
@@ -225,6 +251,11 @@ export class ODPlugin extends ODManagerData {
225
251
  }
226
252
  }
227
253
 
254
+ /**## ODPluginClassManagerIdConstraint `type`
255
+ * The constraint/layout for id mappings/interfaces of the `ODPluginClassManager` class.
256
+ */
257
+ export type ODPluginClassManagerIdConstraint = Record<string,ODManagerData>
258
+
228
259
  /**## ODPluginClassManager `class`
229
260
  * This is an Open Discord plugin class manager.
230
261
  *
@@ -235,8 +266,29 @@ export class ODPlugin extends ODManagerData {
235
266
  *
236
267
  * Use `isPluginLoaded()` to check if a plugin has been loaded before trying to access the manager.
237
268
  */
238
- export class ODPluginClassManager extends ODManager<ODManagerData> {
269
+ export class ODPluginClassManager<IdList extends ODPluginClassManagerIdConstraint = ODPluginClassManagerIdConstraint> extends ODManager<ODManagerData> {
239
270
  constructor(debug:ODDebugger){
240
271
  super(debug,"plugin class")
241
272
  }
273
+
274
+ get<PluginClassId extends keyof IdList>(id:PluginClassId): IdList[PluginClassId]
275
+ get(id:ODValidId): ODManagerData|null
276
+
277
+ get(id:ODValidId): ODManagerData|null {
278
+ return super.get(id)
279
+ }
280
+
281
+ remove<PluginClassId extends keyof IdList>(id:PluginClassId): IdList[PluginClassId]
282
+ remove(id:ODValidId): ODManagerData|null
283
+
284
+ remove(id:ODValidId): ODManagerData|null {
285
+ return super.remove(id)
286
+ }
287
+
288
+ exists(id:keyof IdList): boolean
289
+ exists(id:ODValidId): boolean
290
+
291
+ exists(id:ODValidId): boolean {
292
+ return super.exists(id)
293
+ }
242
294
  }
@@ -6,6 +6,11 @@ import { ODMessageBuildResult, ODMessageBuildSentResult } from "./builder"
6
6
  import { ODDebugger } from "./console"
7
7
  import * as discord from "discord.js"
8
8
 
9
+ /**## ODPostManagerIdConstraint `type`
10
+ * The constraint/layout for id mappings/interfaces of the `ODPostManager` class.
11
+ */
12
+ export type ODPostManagerIdConstraint = Record<string,ODPost<discord.GuildBasedChannel>>
13
+
9
14
  /**## ODPostManager `class`
10
15
  * This is an Open Discord post manager.
11
16
  *
@@ -13,7 +18,7 @@ import * as discord from "discord.js"
13
18
  *
14
19
  * You can use this to get the logs channel of the bot (or some other static channel/category).
15
20
  */
16
- export class ODPostManager extends ODManager<ODPost<discord.GuildBasedChannel>> {
21
+ export class ODPostManager<IdList extends ODPostManagerIdConstraint = ODPostManagerIdConstraint> extends ODManager<ODPost<discord.GuildBasedChannel>> {
17
22
  /**A reference to the main server of the bot */
18
23
  #guild: discord.Guild|null = null
19
24
 
@@ -33,6 +38,27 @@ export class ODPostManager extends ODManager<ODPost<discord.GuildBasedChannel>>
33
38
  await post.init()
34
39
  }
35
40
  }
41
+
42
+ get<PostId extends keyof IdList>(id:PostId): IdList[PostId]
43
+ get(id:ODValidId): ODPost<discord.GuildBasedChannel>|null
44
+
45
+ get(id:ODValidId): ODPost<discord.GuildBasedChannel>|null {
46
+ return super.get(id)
47
+ }
48
+
49
+ remove<PostId extends keyof IdList>(id:PostId): IdList[PostId]
50
+ remove(id:ODValidId): ODPost<discord.GuildBasedChannel>|null
51
+
52
+ remove(id:ODValidId): ODPost<discord.GuildBasedChannel>|null {
53
+ return super.remove(id)
54
+ }
55
+
56
+ exists(id:keyof IdList): boolean
57
+ exists(id:ODValidId): boolean
58
+
59
+ exists(id:ODValidId): boolean {
60
+ return super.exists(id)
61
+ }
36
62
  }
37
63
 
38
64
  /**## ODPost `class`