@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
@@ -3,7 +3,7 @@
3
3
  ///////////////////////////////////////
4
4
  import { ODId, ODManager, ODManagerData, ODSystemError, ODValidId } from "./base"
5
5
  import { ODDebugger } from "./console"
6
- import { ODDatabase, ODJsonDatabaseStructure } from "./database"
6
+ import { ODDatabase, ODDatabaseIdConstraint, ODJsonDatabaseStructure } from "./database"
7
7
  import * as discord from "discord.js"
8
8
 
9
9
  /**## ODValidStatValue `type`
@@ -23,6 +23,11 @@ export type ODStatsManagerInitCallback = (database:ODJsonDatabaseStructure, dele
23
23
  */
24
24
  export type ODStatScopeSetMode = "set"|"increase"|"decrease"
25
25
 
26
+ /**## ODStatsManagerIdConstraint `type`
27
+ * The constraint/layout for id mappings/interfaces of the `ODStatsManager` class.
28
+ */
29
+ export type ODStatsManagerIdConstraint = Record<string,ODStatScope>
30
+
26
31
  /**## ODStatsManager `class`
27
32
  * This is an Open Discord stats manager.
28
33
  *
@@ -31,11 +36,11 @@ export type ODStatScopeSetMode = "set"|"increase"|"decrease"
31
36
  *
32
37
  * Stats can be accessed in the individual scopes.
33
38
  */
34
- export class ODStatsManager extends ODManager<ODStatScope> {
39
+ export class ODStatsManager<IdList extends ODStatsManagerIdConstraint = ODStatsManagerIdConstraint> extends ODManager<ODStatScope> {
35
40
  /**Alias to Open Discord debugger. */
36
41
  #debug: ODDebugger
37
42
  /**Alias to Open Discord stats database. */
38
- database: ODDatabase|null = null
43
+ database: ODDatabase<ODDatabaseIdConstraint>|null = null
39
44
  /**All the listeners for the init event. */
40
45
  #initListeners: ODStatsManagerInitCallback[] = []
41
46
 
@@ -45,7 +50,7 @@ export class ODStatsManager extends ODManager<ODStatScope> {
45
50
  }
46
51
 
47
52
  /**Select the database to use to read/write all stats from/to. */
48
- useDatabase(database:ODDatabase){
53
+ useDatabase(database:ODDatabase<ODDatabaseIdConstraint>){
49
54
  this.database = database
50
55
  }
51
56
  add(data:ODStatScope, overwrite?:boolean): boolean {
@@ -94,7 +99,32 @@ export class ODStatsManager extends ODManager<ODStatScope> {
94
99
  onInit(callback:ODStatsManagerInitCallback){
95
100
  this.#initListeners.push(callback)
96
101
  }
102
+
103
+ get<StatsId extends keyof IdList>(id:StatsId): IdList[StatsId]
104
+ get(id:ODValidId): ODStatScope|null
105
+
106
+ get(id:ODValidId): ODStatScope|null {
107
+ return super.get(id)
108
+ }
109
+
110
+ remove<StatsId extends keyof IdList>(id:StatsId): IdList[StatsId]
111
+ remove(id:ODValidId): ODStatScope|null
112
+
113
+ remove(id:ODValidId): ODStatScope|null {
114
+ return super.remove(id)
115
+ }
116
+
117
+ exists(id:keyof IdList): boolean
118
+ exists(id:ODValidId): boolean
119
+
120
+ exists(id:ODValidId): boolean {
121
+ return super.exists(id)
122
+ }
97
123
  }
124
+ /**## ODStatScopeIdConstraint `type`
125
+ * The constraint/layout for id mappings/interfaces of the `ODStatScope` class.
126
+ */
127
+ export type ODStatScopeIdConstraint = Record<string,ODStat>
98
128
 
99
129
  /**## ODStatScope `class`
100
130
  * This is an Open Discord stat scope.
@@ -104,13 +134,13 @@ export class ODStatsManager extends ODManager<ODStatScope> {
104
134
  *
105
135
  * The built-in Open Discord scopes are: `global`, `user`, `ticket`
106
136
  */
107
- export class ODStatScope extends ODManager<ODStat> {
137
+ export class ODStatScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdConstraint> extends ODManager<ODStat> {
108
138
  /**The id of this statistics scope. */
109
139
  id: ODId
110
140
  /**Is this stat scope already initialized? */
111
141
  ready: boolean = false
112
142
  /**Alias to Open Discord stats database. */
113
- database: ODDatabase|null = null
143
+ database: ODDatabase<ODDatabaseIdConstraint>|null = null
114
144
  /**The name of this scope (used in embed title) */
115
145
  name:string
116
146
 
@@ -121,10 +151,12 @@ export class ODStatScope extends ODManager<ODStat> {
121
151
  }
122
152
 
123
153
  /**Select the database to use to read/write all stats from/to. (Automatically assigned when used in `ODStatsManager`) */
124
- useDatabase(database:ODDatabase){
154
+ useDatabase(database:ODDatabase<ODDatabaseIdConstraint>){
125
155
  this.database = database
126
156
  }
127
157
  /**Get the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
158
+ getStat<StatsId extends keyof IdList>(id:StatsId, scopeId:string): Promise<ODValidStatValue|null>
159
+ getStat(id:ODValidId, scopeId:string): Promise<ODValidStatValue|null>
128
160
  async getStat(id:ODValidId, scopeId:string): Promise<ODValidStatValue|null> {
129
161
  if (!this.database) return null
130
162
  const newId = new ODId(id)
@@ -141,6 +173,8 @@ export class ODStatScope extends ODManager<ODStat> {
141
173
  return null
142
174
  }
143
175
  /**Get the value of a statistic for all `scopeId`'s. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
176
+ getAllStats<StatsId extends keyof IdList>(id:StatsId): Promise<{id:string,value:ODValidStatValue}[]>
177
+ getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatValue}[]>
144
178
  async getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatValue}[]> {
145
179
  if (!this.database) return []
146
180
  const newId = new ODId(id)
@@ -158,6 +192,8 @@ export class ODStatScope extends ODManager<ODStat> {
158
192
  return output
159
193
  }
160
194
  /**Set, increase or decrease the value of a statistic. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
195
+ setStat<StatsId extends keyof IdList>(id:StatsId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean>
196
+ setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean>
161
197
  async setStat(id:ODValidId, scopeId:string, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean> {
162
198
  if (!this.database) return false
163
199
  const stat = this.get(id)
@@ -176,6 +212,8 @@ export class ODStatScope extends ODManager<ODStat> {
176
212
  return true
177
213
  }
178
214
  /**Reset the value of a statistic to the initial value. The `scopeId` is the unique id of the user, channel, role, etc that the stats are related to. */
215
+ resetStat<StatsId extends keyof IdList>(id:ODValidId, scopeId:string): Promise<ODValidStatValue|null>
216
+ resetStat(id:ODValidId, scopeId:string): Promise<ODValidStatValue|null>
179
217
  async resetStat(id:ODValidId, scopeId:string): Promise<ODValidStatValue|null> {
180
218
  if (!this.database) return null
181
219
  const stat = this.get(id)
@@ -216,6 +254,27 @@ export class ODStatScope extends ODManager<ODStat> {
216
254
 
217
255
  return result.filter((stat) => stat !== "").join("\n")
218
256
  }
257
+
258
+ get<StatsId extends keyof IdList>(id:StatsId): IdList[StatsId]
259
+ get(id:ODValidId): ODStat|null
260
+
261
+ get(id:ODValidId): ODStat|null {
262
+ return super.get(id)
263
+ }
264
+
265
+ remove<StatsId extends keyof IdList>(id:StatsId): IdList[StatsId]
266
+ remove(id:ODValidId): ODStat|null
267
+
268
+ remove(id:ODValidId): ODStat|null {
269
+ return super.remove(id)
270
+ }
271
+
272
+ exists(id:keyof IdList): boolean
273
+ exists(id:ODValidId): boolean
274
+
275
+ exists(id:ODValidId): boolean {
276
+ return super.exists(id)
277
+ }
219
278
  }
220
279
 
221
280
  /**## ODStatGlobalScope `class`
@@ -226,19 +285,31 @@ export class ODStatScope extends ODManager<ODStat> {
226
285
  *
227
286
  * This scope is made specifically for the global stats of Open Discord.
228
287
  */
229
- export class ODStatGlobalScope extends ODStatScope {
288
+ export class ODStatGlobalScope<IdList extends ODStatScopeIdConstraint = ODStatScopeIdConstraint> extends ODStatScope<IdList> {
289
+ getStat<StatsId extends keyof IdList>(id:StatsId): Promise<ODValidStatValue|null>
290
+ getStat(id:ODValidId): Promise<ODValidStatValue|null>
230
291
  getStat(id:ODValidId): Promise<ODValidStatValue|null> {
231
292
  return super.getStat(id,"GLOBAL")
232
293
  }
294
+
295
+ getAllStats<StatsId extends keyof IdList>(id:StatsId): Promise<{id:string,value:ODValidStatValue}[]>
296
+ getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatValue}[]>
233
297
  getAllStats(id:ODValidId): Promise<{id:string,value:ODValidStatValue}[]> {
234
298
  return super.getAllStats(id)
235
299
  }
300
+
301
+ setStat<StatsId extends keyof IdList>(id:StatsId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean>
302
+ setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean>
236
303
  setStat(id:ODValidId, value:ODValidStatValue, mode:ODStatScopeSetMode): Promise<boolean> {
237
304
  return super.setStat(id,"GLOBAL",value,mode)
238
305
  }
306
+
307
+ resetStat<StatsId extends keyof IdList>(id:ODValidId): Promise<ODValidStatValue|null>
308
+ resetStat(id:ODValidId): Promise<ODValidStatValue|null>
239
309
  resetStat(id:ODValidId): Promise<ODValidStatValue|null> {
240
310
  return super.resetStat(id,"GLOBAL")
241
311
  }
312
+
242
313
  render(scopeId:"GLOBAL", guild:discord.Guild, channel:discord.TextBasedChannel, user: discord.User): Promise<string> {
243
314
  return super.render("GLOBAL",guild,channel,user)
244
315
  }
@@ -15,17 +15,17 @@ import { ODWorkerManager } from "./worker"
15
15
  *
16
16
  * It doesn't contain the code which activates or spawns the verifybars!
17
17
  */
18
- export class ODVerifyBar extends ODManagerData {
18
+ export class ODVerifyBar<SuccessWorkerIds extends string = string,FailureWorkerIds extends string = string,> extends ODManagerData {
19
19
  /**All workers that will run when the verifybar is accepted. */
20
- success: ODWorkerManager<ODButtonResponderInstance,"verifybar",{data:string|null,verifybarMessage:discord.Message<boolean>|null}>
20
+ success: ODWorkerManager<ODButtonResponderInstance,"verifybar",{data:string|null,verifybarMessage:discord.Message<boolean>|null},SuccessWorkerIds>
21
21
  /**All workers that will run when the verifybar is stopped. */
22
- failure: ODWorkerManager<ODButtonResponderInstance,"verifybar",{data:string|null,verifybarMessage:discord.Message<boolean>|null}>
22
+ failure: ODWorkerManager<ODButtonResponderInstance,"verifybar",{data:string|null,verifybarMessage:discord.Message<boolean>|null},FailureWorkerIds>
23
23
  /**The message that will be built wen activating this verifybar. */
24
24
  message: ODMessage<"verifybar",{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,verifybar:ODVerifyBar,originalMessage:discord.Message<boolean>}>
25
25
  /**When disabled, it will skip the verifybar and instantly fire the `success` workers. */
26
26
  enabled: boolean
27
27
 
28
- constructor(id:ODValidId, message:ODMessage<"verifybar",{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalMessage:discord.Message<boolean>}>, enabled?:boolean){
28
+ constructor(id:ODValidId, message:ODMessage<"verifybar",{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,verifybar:ODVerifyBar,originalMessage:discord.Message<boolean>}>, enabled?:boolean){
29
29
  super(id)
30
30
  this.success = new ODWorkerManager("descending")
31
31
  this.failure = new ODWorkerManager("descending")
@@ -46,6 +46,11 @@ export class ODVerifyBar extends ODManagerData {
46
46
  }
47
47
  }
48
48
 
49
+ /**## ODVerifyBarManagerIdConstraint `type`
50
+ * The constraint/layout for id mappings/interfaces of the `ODVerifyBarManager` class.
51
+ */
52
+ export type ODVerifyBarManagerIdConstraint = Record<string,{successWorkerIds:string,failureWorkerIds:string}>
53
+
49
54
  /**## ODVerifyBarManager `class`
50
55
  * This is an Open Discord verifybar manager.
51
56
  *
@@ -54,8 +59,29 @@ export class ODVerifyBar extends ODManagerData {
54
59
  *
55
60
  * It doesn't contain the code which activates the verifybars! This should be implemented by your own.
56
61
  */
57
- export class ODVerifyBarManager extends ODManager<ODVerifyBar> {
62
+ export class ODVerifyBarManager<IdList extends ODVerifyBarManagerIdConstraint = ODVerifyBarManagerIdConstraint> extends ODManager<ODVerifyBar> {
58
63
  constructor(debug:ODDebugger){
59
64
  super(debug,"verifybar")
60
65
  }
66
+
67
+ get<VerifyBarId extends keyof IdList>(id:VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"],IdList[VerifyBarId]["failureWorkerIds"]>
68
+ get(id:ODValidId): ODVerifyBar|null
69
+
70
+ get(id:ODValidId): ODVerifyBar|null {
71
+ return super.get(id)
72
+ }
73
+
74
+ remove<VerifyBarId extends keyof IdList>(id:VerifyBarId): ODVerifyBar<IdList[VerifyBarId]["successWorkerIds"],IdList[VerifyBarId]["failureWorkerIds"]>
75
+ remove(id:ODValidId): ODVerifyBar|null
76
+
77
+ remove(id:ODValidId): ODVerifyBar|null {
78
+ return super.remove(id)
79
+ }
80
+
81
+ exists(id:keyof IdList): boolean
82
+ exists(id:ODValidId): boolean
83
+
84
+ exists(id:ODValidId): boolean {
85
+ return super.exists(id)
86
+ }
61
87
  }
@@ -38,7 +38,7 @@ export class ODWorker<Instance, Source extends string, Params> extends ODManager
38
38
  *
39
39
  * You can register a custom worker in this class to create a message or button.
40
40
  */
41
- export class ODWorkerManager<Instance, Source extends string, Params> extends ODManager<ODWorker<Instance,Source,Params>> {
41
+ export class ODWorkerManager<Instance, Source extends string, Params,WorkerIds extends string = string> extends ODManager<ODWorker<Instance,Source,Params>> {
42
42
  /**The order of execution for workers inside this manager. */
43
43
  #priorityOrder: "ascending"|"descending"
44
44
  /**The backup worker will be executed when one of the workers fails or cancels execution. */
@@ -90,4 +90,25 @@ export class ODWorkerManager<Instance, Source extends string, Params> extends OD
90
90
  }
91
91
  }
92
92
  }
93
+
94
+ get(id:WorkerIds): ODWorker<Instance,Source,Params>
95
+ get(id:ODValidId): ODWorker<Instance,Source,Params>|null
96
+
97
+ get(id:ODValidId): ODWorker<Instance,Source,Params>|null {
98
+ return super.get(id)
99
+ }
100
+
101
+ remove(id:WorkerIds): ODWorker<Instance,Source,Params>
102
+ remove(id:ODValidId): ODWorker<Instance,Source,Params>|null
103
+
104
+ remove(id:ODValidId): ODWorker<Instance,Source,Params>|null {
105
+ return super.remove(id)
106
+ }
107
+
108
+ exists(id:WorkerIds): boolean
109
+ exists(id:ODValidId): boolean
110
+
111
+ exists(id:ODValidId): boolean {
112
+ return super.exists(id)
113
+ }
93
114
  }
@@ -51,6 +51,7 @@ export function initialStartupLogs(opendiscord:api.ODMain,project:api.ODProjectT
51
51
  opendiscord.debug.debug("Using formatted-json-stringify "+packageJson.dependencies["formatted-json-stringify"]+"!")
52
52
  opendiscord.debug.debug("Using terminal-kit "+packageJson.dependencies["terminal-kit"]+"!")
53
53
  opendiscord.debug.debug("Using typescript "+packageJson.dependencies["typescript"]+"!")
54
+ opendiscord.debug.debug("Using @open-discord-bots/framework "+packageJson.dependencies["@open-discord-bots/framework"]+"!")
54
55
  }catch{
55
56
  opendiscord.debug.debug("Failed to fetch module versions!")
56
57
  }