@open-discord-bots/framework 0.2.11 → 0.2.12

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 (46) hide show
  1. package/dist/api/main.js +1 -1
  2. package/dist/api/modules/action.d.ts +9 -9
  3. package/dist/api/modules/action.js +3 -3
  4. package/dist/api/modules/base.d.ts +5 -3
  5. package/dist/api/modules/base.js +8 -4
  6. package/dist/api/modules/builder.d.ts +41 -41
  7. package/dist/api/modules/builder.js +20 -20
  8. package/dist/api/modules/checker.d.ts +3 -3
  9. package/dist/api/modules/client.js +2 -2
  10. package/dist/api/modules/console.d.ts +15 -15
  11. package/dist/api/modules/console.js +31 -31
  12. package/dist/api/modules/event.js +2 -2
  13. package/dist/api/modules/helpmenu.js +1 -1
  14. package/dist/api/modules/progressbar.js +1 -0
  15. package/dist/api/modules/responder.d.ts +37 -37
  16. package/dist/api/modules/responder.js +13 -13
  17. package/dist/api/modules/statistic.js +0 -2
  18. package/dist/api/modules/worker.d.ts +14 -14
  19. package/dist/api/modules/worker.js +9 -9
  20. package/dist/cli/editConfig.js +6 -20
  21. package/dist/startup/pluginLauncher.js +6 -4
  22. package/dist/utilities/index.d.ts +2 -2
  23. package/package.json +4 -4
  24. package/src/api/main.ts +1 -1
  25. package/src/api/modules/action.ts +10 -10
  26. package/src/api/modules/base.ts +12 -8
  27. package/src/api/modules/builder.ts +53 -53
  28. package/src/api/modules/checker.ts +3 -3
  29. package/src/api/modules/client.ts +15 -15
  30. package/src/api/modules/component.txt +350 -0
  31. package/src/api/modules/config.ts +1 -1
  32. package/src/api/modules/console.ts +26 -26
  33. package/src/api/modules/database.ts +1 -1
  34. package/src/api/modules/event.ts +5 -5
  35. package/src/api/modules/helpmenu.ts +3 -3
  36. package/src/api/modules/language.ts +1 -1
  37. package/src/api/modules/plugin.ts +1 -1
  38. package/src/api/modules/progressbar.ts +3 -1
  39. package/src/api/modules/responder.ts +43 -43
  40. package/src/api/modules/statistic.ts +0 -1
  41. package/src/api/modules/worker.ts +25 -25
  42. package/src/cli/editConfig.ts +20 -34
  43. package/src/startup/compilation.ts +2 -2
  44. package/src/startup/pluginLauncher.ts +9 -6
  45. package/src/utilities/index.ts +3 -3
  46. package/tsconfig.json +1 -0
@@ -0,0 +1,350 @@
1
+ ///////////////////////////////////////
2
+ //COMPONENTS MODULE
3
+ ///////////////////////////////////////
4
+ import { ODId, ODValidId, ODSystemError, ODManagerData, ODNoGeneric, ODManager } from "./base"
5
+ import * as discord from "discord.js"
6
+ import { ODWorkerManager, ODWorkerCallback, ODWorker } from "./worker"
7
+ import { ODDebugger } from "./console"
8
+
9
+ /**## ODComponentFactoryInstance `class`
10
+ * An Open Discord component factory instance.
11
+ *
12
+ * It will contain the final root component which is returned by an `ODComponentFactory`.
13
+ * This component can be used in another `ODComponentFactory` or rendered to a message/modal.
14
+ */
15
+ export class ODComponentFactoryInstance<Component extends ODComponent<object,any>> {
16
+ /**The root component of this factory. */
17
+ #rootComponent: Component|null = null
18
+
19
+ /**The root component of this factory. */
20
+ getComponent(){
21
+ return this.#rootComponent
22
+ }
23
+ /**Set the root component of this factory. */
24
+ setComponent(c:Component|null){
25
+ this.#rootComponent = c
26
+ }
27
+ }
28
+
29
+ /**## ODComponentFactory `class`
30
+ * An Open Discord component factory.
31
+ *
32
+ * It is a collection of functions/workers/hooks which will build a Discord message/modal component from scratch.
33
+ * Plugins can intercept and modify these workers to replace default behaviour or layout.
34
+ */
35
+ export class ODComponentFactory<Component extends ODComponent<object,any>,Origin extends string,Params,WorkerIds extends string = string> extends ODManagerData {
36
+ /**A collection of all workers for this component factory. */
37
+ workers: ODWorkerManager<ODComponentFactoryInstance<Component>,Origin,Params,WorkerIds>
38
+
39
+ constructor(id:ODValidId, callback?:ODWorkerCallback<ODComponentFactoryInstance<Component>,Origin,Params>, priority?:number, callbackId?:ODValidId){
40
+ super(id)
41
+ this.workers = new ODWorkerManager("ascending")
42
+ if (callback) this.workers.add(new ODWorker(callbackId ? callbackId : id,priority ?? 0,callback))
43
+ }
44
+ /**Run all workers and return the resulting component. */
45
+ async build(origin:Origin, params:Params): Promise<ODComponentInferBuildResult<Component>> {
46
+ const instance = new ODComponentFactoryInstance<Component>()
47
+ await this.workers.executeWorkers(instance,origin,params)
48
+ const rootComponent = instance.getComponent()
49
+ if (!rootComponent) throw new ODSystemError("ODComponentFactory.build() --> Failed to build component! (id: "+this.id.value+")")
50
+ return rootComponent.build()
51
+ }
52
+ }
53
+
54
+ /**## ODComponentManagerIdConstraint `type`
55
+ * The constraint/layout for id mappings/interfaces of the `ODComponentManager` class.
56
+ */
57
+ export type ODComponentManagerIdConstraint = Record<string,{origin:string,params:object,workers:string}>
58
+
59
+ /**## ODBaseComponentManager `class`
60
+ * A generic Open Discord component manager.
61
+ *
62
+ * It contains a collection of all Open Discord component factories. You can:
63
+ * - Add your own message/modal component factories
64
+ * - Modify existing message/modal component factories
65
+ *
66
+ * Messages created using this system are not compatible with `ODBuilder` messages!
67
+ */
68
+ export class ODBaseComponentManager<IdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint,Component extends ODComponent<object,any> = ODComponent<object,any>> extends ODManager<ODComponentFactory<Component,string,{},string>> {
69
+ get<FactoryId extends keyof ODNoGeneric<IdList>>(id:FactoryId): ODComponentFactory<Component,IdList[FactoryId]["origin"],IdList[FactoryId]["params"],IdList[FactoryId]["workers"]>
70
+ get(id:ODValidId): ODComponentFactory<Component,string,{},string>|null
71
+
72
+ get(id:ODValidId): ODComponentFactory<Component,string,{},string>|null {
73
+ return super.get(id)
74
+ }
75
+
76
+ remove<FactoryId extends keyof ODNoGeneric<IdList>>(id:FactoryId): ODComponentFactory<Component,IdList[FactoryId]["origin"],IdList[FactoryId]["params"],IdList[FactoryId]["workers"]>
77
+ remove(id:ODValidId): ODComponentFactory<Component,string,{},string>|null
78
+
79
+ remove(id:ODValidId): ODComponentFactory<Component,string,{},string>|null {
80
+ return super.remove(id)
81
+ }
82
+
83
+ exists(id:keyof ODNoGeneric<IdList>): boolean
84
+ exists(id:ODValidId): boolean
85
+
86
+ exists(id:ODValidId): boolean {
87
+ return super.exists(id)
88
+ }
89
+ }
90
+
91
+ /**## ODSharedComponentManager `class
92
+ * A special class with types for shared message/modal `ODComponent`'s.
93
+ * Create button, dropdown or any other layout component template to use them in messages & modals.
94
+ */
95
+ export class ODSharedComponentManager<IdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint> extends ODBaseComponentManager<IdList,ODComponent<object,any>> {
96
+ constructor(debug:ODDebugger){
97
+ super(debug,"shared component")
98
+ }
99
+ }
100
+
101
+ /**## ODMessageComponentManager `class
102
+ * A special class with types for `ODMessageComponent`'s.
103
+ * Create message templates to use as replies and make use of shared components.
104
+ */
105
+ export class ODMessageComponentManager<IdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint> extends ODBaseComponentManager<IdList,TODO> {
106
+ constructor(debug:ODDebugger){
107
+ super(debug,"message component")
108
+ }
109
+ }
110
+
111
+ /**## ODModalComponentManager `class
112
+ * A special class with types for `ODModalComponent`'s.
113
+ * Create modal templates to use as forms and make use of shared components.
114
+ */
115
+ export class ODModalComponentManager<IdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint> extends ODBaseComponentManager<IdList,TODO> {
116
+ constructor(debug:ODDebugger){
117
+ super(debug,"modal component")
118
+ }
119
+ }
120
+
121
+ /**## ODComponentManager `class`
122
+ * An Open Discord component manager.
123
+ *
124
+ * Create message & modal templates, re-use components and design all visual elements of the bot.
125
+ *
126
+ * Using the Open Discord component system has many advantages compared to vanilla `discord.js`:
127
+ * - Plugins can extend, edit & replace messages & components
128
+ * - Includes automatic error handling
129
+ * - Independent workers/hooks (with priority)
130
+ * - Fail-safe design using try-catch
131
+ * - Automatic switch between components v2 and legacy components depending on message requirements
132
+ * - Get to know the origin of the request (e.g. button, dropdown, modal, ...)
133
+ * - And so much more!
134
+ */
135
+ export class ODComponentManager<
136
+ SharedIdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint,
137
+ MessageIdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint,
138
+ ModalIdList extends ODComponentManagerIdConstraint = ODComponentManagerIdConstraint
139
+ > {
140
+ /**The manager for all shared components. */
141
+ shared: ODSharedComponentManager<SharedIdList>
142
+ /**The manager for all messages components. */
143
+ messages: ODMessageComponentManager<MessageIdList>
144
+ /**The manager for all modals components. */
145
+ modals: ODModalComponentManager<ModalIdList>
146
+
147
+ constructor(debug:ODDebugger){
148
+ this.shared = new ODSharedComponentManager(debug)
149
+ this.messages = new ODMessageComponentManager(debug)
150
+ this.modals = new ODModalComponentManager(debug)
151
+ }
152
+ }
153
+
154
+ ///////////////////////////////////////
155
+ // GENERIC COMPONENT DEFINITIONS //
156
+ ///////////////////////////////////////
157
+
158
+ /**## ODComponentBuilderFunc `type`
159
+ * The builder function of a component.
160
+ */
161
+ export type ODComponentBuilderFunc<BuildResult> = () => Promise<BuildResult|null>|BuildResult|null
162
+
163
+ /**## ODComponentInferBuildResult `type`
164
+ * Infer the build result of a certain component.
165
+ */
166
+ export type ODComponentInferBuildResult<Component> = Component extends ODComponent<object,infer BuildResult> ? BuildResult : never
167
+
168
+ /**## ODComponent `class`
169
+ * An Open Discord message/modal component.
170
+ *
171
+ * This class itself doesn't do anything, but is a blueprint for other
172
+ * `ODComponent` classes which represent the new Discord message/modal components.
173
+ */
174
+ export class ODComponent<Data extends object,BuildResult> {
175
+ /**The id of this message/modal component. */
176
+ id: ODId
177
+ /** */
178
+ /**The data or configuration of this message/modal component. */
179
+ readonly data: Data
180
+ /**Build this component. Returns `null` when invalid. */
181
+ readonly build: ODComponentBuilderFunc<BuildResult>
182
+
183
+ constructor(id:ODValidId,data:Data,build:ODComponentBuilderFunc<BuildResult>){
184
+ this.id = new ODId(id)
185
+ this.data = data
186
+ this.build = build
187
+ }
188
+ }
189
+
190
+ /**## ODGroupComponent `class`
191
+ * An Open Discord message/modal component with children.
192
+ *
193
+ * This class itself doesn't do anything, but is a blueprint for other
194
+ * `ODGroupComponent` classes which represent the new Discord message/modal components.
195
+ */
196
+ export class ODGroupComponent<Data extends object,ChildComponent extends ODComponent<object,any>,BuildResult> extends ODComponent<Data,BuildResult> {
197
+ /**The collection of child components. */
198
+ readonly children: ChildComponent[] = []
199
+
200
+ /**Add a new component to this group. There are multiple modes available:
201
+ * - `start`: insert at the start of the list.
202
+ * - `end`: insert at the end of the list.
203
+ * - `before`: insert before an existing component `referenceId` (`start` if `referenceId` is invalid)
204
+ * - `after`: insert after an existing component `referenceId` (`end` if `referenceId` is invalid)
205
+ * - `index`: insert at a certain index `referenceIndex` (`end` if `referenceIndex` is invalid)
206
+ */
207
+ addComponent(c:ChildComponent,mode:"start"|"end"): void
208
+ addComponent(c:ChildComponent,mode:"before"|"after",referenceId:ODValidId): void
209
+ addComponent(c:ChildComponent,mode:"index",referenceIndex:number): void
210
+ addComponent(c:ChildComponent,mode:"start"|"end"|"before"|"after"|"index" = "start",reference?:ODValidId|number){
211
+ if (mode == "start") this.children.unshift(c)
212
+ else if (mode == "end") this.children.push(c)
213
+ else if (mode == "before"){
214
+ if (!reference || !this.children.find((c) => c.id.value === new ODId(reference).value)) this.children.unshift(c)
215
+ else{
216
+ const referenceIndex = this.children.findIndex((c) => c.id.value === new ODId(reference).value)
217
+ this.children.splice(referenceIndex,0,c) //insert at position 'referenceIndex' (before)
218
+ }
219
+ }else if (mode == "after"){
220
+ if (!reference || !this.children.find((c) => c.id.value === new ODId(reference).value)) this.children.push(c)
221
+ else{
222
+ const referenceIndex = this.children.findIndex((c) => c.id.value === new ODId(reference).value)
223
+ this.children.splice(referenceIndex+1,0,c) //insert at position 'referenceIndex+1' (after)
224
+ }
225
+ }else if (mode == "index"){
226
+ if (!reference || typeof reference !== "number") this.children.push(c)
227
+ else{
228
+ this.children.splice(reference,0,c) //insert at position 'reference'
229
+ }
230
+ }
231
+ }
232
+ /**Get a component with a certain ID in this group. Returns `null` if non-existent. */
233
+ getComponent(id:ODValidId){
234
+ const component = this.children.find((c) => c.id.value === new ODId(id).value)
235
+ return component ?? null
236
+ }
237
+ /**Get the position of a component with a certain ID in this group. Returns `-1` if non-existent. */
238
+ getComponentPosition(id:ODValidId){
239
+ return this.children.findIndex((c) => c.id.value === new ODId(id).value)
240
+ }
241
+ /**Returns if a component with a certain ID exists in this group. */
242
+ existsComponent(id:ODValidId){
243
+ const component = this.children.find((c) => c.id.value === new ODId(id).value)
244
+ return component ? true : false
245
+ }
246
+ /**Remove a component with a certain ID from this group. Returns the removed component or `null if non-existent. */
247
+ removeComponent(id:ODValidId){
248
+ const index = this.children.findIndex((c) => c.id.value === new ODId(id).value)
249
+ if (index < 0) return null
250
+ else return this.children.splice(index,1)[0]
251
+ }
252
+ /**Moves an existing component to a new location in this group. There are multiple modes available:
253
+ * - `start`: move to the start of the list.
254
+ * - `end`: move to the end of the list.
255
+ * - `before`: move before an existing component `referenceId` (`start` if `referenceId` is invalid)
256
+ * - `after`: move after an existing component `referenceId` (`end` if `referenceId` is invalid)
257
+ * - `index`: move to a certain index `referenceIndex` (`end` if `referenceIndex` is invalid)
258
+ */
259
+ moveComponent(id:ODValidId,mode:"start"|"end"): void
260
+ moveComponent(id:ODValidId,mode:"before"|"after",referenceId:ODValidId): void
261
+ moveComponent(id:ODValidId,mode:"index",referenceIndex:number): void
262
+ moveComponent(id:ODValidId,mode:"start"|"end"|"before"|"after"|"index" = "start",reference?:ODValidId|number){
263
+ const component = this.removeComponent(id)
264
+ if (component){
265
+ if (mode == "start" || mode == "end") this.addComponent(component,mode)
266
+ if ((mode == "before" || mode == "after") && reference) this.addComponent(component,mode,reference)
267
+ if (mode == "index" && typeof reference == "number") this.addComponent(component,mode,reference)
268
+ return
269
+ }
270
+ }
271
+ }
272
+
273
+ /**## ODParentComponent `class`
274
+ * An Open Discord message/modal component with a single child.
275
+ *
276
+ * This class itself doesn't do anything, but is a blueprint for other
277
+ * `ODParentComponent` classes which represent the new Discord message/modal components.
278
+ */
279
+ export class ODParentComponent<Data extends object,ChildComponent extends ODComponent<object,any>,BuildResult> extends ODComponent<Data,BuildResult> {
280
+ /**The child component of this parent. */
281
+ #child: ChildComponent|null = null
282
+
283
+ /**The child component of this parent. */
284
+ get child(){
285
+ return this.#child
286
+ }
287
+ /**Set the child component of this parent. */
288
+ setComponent(c:ChildComponent|null){
289
+ this.#child = c
290
+ }
291
+ }
292
+
293
+ //////////////////////////////////////
294
+ // GLOBAL COMPONENT DEFINITIONS //
295
+ //////////////////////////////////////
296
+
297
+
298
+
299
+ //////////////////////////////////////
300
+ // LAYOUT COMPONENT DEFINITIONS //
301
+ //////////////////////////////////////
302
+
303
+
304
+
305
+ ///////////////////////////////////////
306
+ // CONTENT COMPONENT DEFINITIONS //
307
+ ///////////////////////////////////////
308
+
309
+ /**## ODTextComponentData `type`
310
+ * The configurable settings/options for the `ODTextComponent`.
311
+ */
312
+ export interface ODTextComponentData {
313
+ /**The text to display. */
314
+ content:string
315
+ }
316
+
317
+ /**## ODTextComponent `class`
318
+ * A text component which renders markdown text in a message.
319
+ */
320
+ export class ODTextComponent extends ODComponent<ODTextComponentData,discord.TextDisplayBuilder> {
321
+ constructor(id:ODValidId,data:Partial<ODTextComponentData>){
322
+ const initData: ODTextComponentData = {content:"",...data}
323
+ super(id,initData,() => {
324
+ if (this.data.content.length < 1) return null
325
+ return new discord.TextDisplayBuilder({
326
+ content:this.data.content
327
+ })
328
+ })
329
+ }
330
+
331
+ /**Set the text to display. */
332
+ setContent(value:string){
333
+ this.data.content = value
334
+ }
335
+ }
336
+
337
+ /* TODO
338
+ * 🔴 ODFileComponent
339
+ * 🔴 ODGalleryComponent
340
+ * 🔴 ODThumbnailComponent
341
+ * 🔴 ODContentComponent (simple msg)
342
+ * 🔴 ODPollComponent (simple msg)
343
+ * 🔴 ODEmbedComponent (simple msg)
344
+ * 🔴 ODStickerComponent (simple msg)
345
+ */
346
+
347
+ ///////////////////////////////////////////
348
+ // INTERACTIVE COMPONENT DEFINITIONS //
349
+ ///////////////////////////////////////////
350
+
@@ -37,7 +37,7 @@ export class ODConfigManager<IdList extends ODConfigManagerIdConstraint = ODConf
37
37
  for (const config of this.getAll()){
38
38
  try{
39
39
  await config.init()
40
- }catch(err){
40
+ }catch(err:any){
41
41
  process.emit("uncaughtException",new ODSystemError(err))
42
42
  }
43
43
  }
@@ -116,67 +116,67 @@ export class ODConsoleMessage {
116
116
  }
117
117
  }
118
118
 
119
- /**## ODConsoleInfoMessage `class`
119
+ /**## ODInfoConsoleMessage `class`
120
120
  * This is an Open Discord console info message.
121
121
  *
122
122
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "INFO" messages!
123
123
  */
124
- export class ODConsoleInfoMessage extends ODConsoleMessage {
124
+ export class ODInfoConsoleMessage extends ODConsoleMessage {
125
125
  constructor(message:string,params?:ODConsoleMessageParam[]){
126
126
  super(message,"INFO","blue",params)
127
127
  }
128
128
  }
129
129
 
130
- /**## ODConsoleSystemMessage `class`
130
+ /**## ODSystemConsoleMessage `class`
131
131
  * This is an Open Discord console system message.
132
132
  *
133
133
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "SYSTEM" messages!
134
134
  */
135
- export class ODConsoleSystemMessage extends ODConsoleMessage {
135
+ export class ODSystemConsoleMessage extends ODConsoleMessage {
136
136
  constructor(message:string,params?:ODConsoleMessageParam[]){
137
137
  super(message,"SYSTEM","green",params)
138
138
  }
139
139
  }
140
140
 
141
- /**## ODConsolePluginMessage `class`
141
+ /**## ODPluginConsoleMessage `class`
142
142
  * This is an Open Discord console plugin message.
143
143
  *
144
144
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "PLUGIN" messages!
145
145
  */
146
- export class ODConsolePluginMessage extends ODConsoleMessage {
146
+ export class ODPluginConsoleMessage extends ODConsoleMessage {
147
147
  constructor(message:string,params?:ODConsoleMessageParam[]){
148
148
  super(message,"PLUGIN","magenta",params)
149
149
  }
150
150
  }
151
151
 
152
- /**## ODConsoleDebugMessage `class`
152
+ /**## ODDebugConsoleMessage `class`
153
153
  * This is an Open Discord console debug message.
154
154
  *
155
155
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "DEBUG" messages!
156
156
  */
157
- export class ODConsoleDebugMessage extends ODConsoleMessage {
157
+ export class ODDebugConsoleMessage extends ODConsoleMessage {
158
158
  constructor(message:string,params?:ODConsoleMessageParam[]){
159
159
  super(message,"DEBUG","cyan",params)
160
160
  }
161
161
  }
162
162
 
163
- /**## ODConsoleWarningMessage `class`
163
+ /**## ODWarningConsoleMessage `class`
164
164
  * This is an Open Discord console warning message.
165
165
  *
166
166
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "WARNING" messages!
167
167
  */
168
- export class ODConsoleWarningMessage extends ODConsoleMessage {
168
+ export class ODWarningConsoleMessage extends ODConsoleMessage {
169
169
  constructor(message:string,params?:ODConsoleMessageParam[]){
170
170
  super(message,"WARNING","yellow",params)
171
171
  }
172
172
  }
173
173
 
174
- /**## ODConsoleErrorMessage `class`
174
+ /**## ODErrorConsoleMessage `class`
175
175
  * This is an Open Discord console error message.
176
176
  *
177
177
  * It is the same as a normal `ODConsoleMessage`, but it has a predefined prefix & color scheme for the "ERROR" messages!
178
178
  */
179
- export class ODConsoleErrorMessage extends ODConsoleMessage {
179
+ export class ODErrorConsoleMessage extends ODConsoleMessage {
180
180
  constructor(message:string,params?:ODConsoleMessageParam[]){
181
181
  super(message,"ERROR","red",params)
182
182
  }
@@ -189,11 +189,11 @@ export class ODConsoleErrorMessage extends ODConsoleMessage {
189
189
  */
190
190
  export class ODError {
191
191
  /**The original error that this class wraps around */
192
- error: Error|ODSystemError|ODPluginError
192
+ error: any
193
193
  /**The origin of the original error */
194
194
  origin: NodeJS.UncaughtExceptionOrigin
195
195
 
196
- constructor(error:Error|ODSystemError|ODPluginError, origin:NodeJS.UncaughtExceptionOrigin){
196
+ constructor(error:any, origin:NodeJS.UncaughtExceptionOrigin){
197
197
  this.error = error
198
198
  this.origin = origin
199
199
  }
@@ -201,7 +201,7 @@ export class ODError {
201
201
  /**Render this error to the console using `console.log`! Returns `false` when something went wrong. */
202
202
  render(){
203
203
  try {
204
- let prefix = (this.error["_ODErrorType"] == "plugin") ? "PLUGIN ERROR" : ((this.error["_ODErrorType"] == "system") ? "OPENTICKET ERROR" : "UNKNOWN ERROR")
204
+ let prefix = (this.error["_ODErrorType"] && this.error["_ODErrorType"] == "plugin") ? "PLUGIN ERROR" : ((this.error["_ODErrorType"] == "system") ? "OPENTICKET ERROR" : "UNKNOWN ERROR")
205
205
  //title
206
206
  console.log(ansis.red("["+prefix+"]: ")+this.error.message+" | origin: "+this.origin)
207
207
  //stack trace
@@ -266,13 +266,13 @@ export class ODConsoleManager {
266
266
 
267
267
  }else if (["string","number","boolean","object"].includes(typeof message)){
268
268
  let newMessage: ODConsoleMessage
269
- if (type == "info") newMessage = new ODConsoleInfoMessage(message,params)
270
- else if (type == "system") newMessage = new ODConsoleSystemMessage(message,params)
271
- else if (type == "plugin") newMessage = new ODConsolePluginMessage(message,params)
272
- else if (type == "debug") newMessage = new ODConsoleDebugMessage(message,params)
273
- else if (type == "warning") newMessage = new ODConsoleWarningMessage(message,params)
274
- else if (type == "error") newMessage = new ODConsoleErrorMessage(message,params)
275
- else newMessage = new ODConsoleSystemMessage(message,params)
269
+ if (type == "info") newMessage = new ODInfoConsoleMessage(message,params)
270
+ else if (type == "system") newMessage = new ODSystemConsoleMessage(message,params)
271
+ else if (type == "plugin") newMessage = new ODPluginConsoleMessage(message,params)
272
+ else if (type == "debug") newMessage = new ODDebugConsoleMessage(message,params)
273
+ else if (type == "warning") newMessage = new ODWarningConsoleMessage(message,params)
274
+ else if (type == "error") newMessage = new ODErrorConsoleMessage(message,params)
275
+ else newMessage = new ODSystemConsoleMessage(message,params)
276
276
 
277
277
  if (!this.silent) newMessage.render()
278
278
  if (this.debugfile) this.debugfile.writeConsoleMessage(newMessage)
@@ -422,10 +422,10 @@ export class ODDebugger {
422
422
  /**Create a debug message. This will always be logged to `debug.txt` & sometimes to the console (when enabled). Returns `true` when visible */
423
423
  debug(message:string, params?:{key:string,value:string}[]): boolean {
424
424
  if (this.visible){
425
- this.console.log(new ODConsoleDebugMessage(message,params))
425
+ this.console.log(new ODDebugConsoleMessage(message,params))
426
426
  return true
427
427
  }else{
428
- this.console.debugfile.writeConsoleMessage(new ODConsoleDebugMessage(message,params))
428
+ this.console.debugfile.writeConsoleMessage(new ODDebugConsoleMessage(message,params))
429
429
  return false
430
430
  }
431
431
  }
@@ -678,9 +678,9 @@ export class ODLiveStatusRenderer {
678
678
 
679
679
 
680
680
  if (!["red","yellow","green","blue","gray","magenta","cyan"].includes(titleColor)) var finalTitle = ansis.white(title)
681
- else var finalTitle = ansis[titleColor](title)
681
+ else var finalTitle = ansis[(titleColor == "normal" ? "white" : titleColor)](title)
682
682
  if (!["red","yellow","green","blue","gray","magenta","cyan"].includes(descriptionColor)) var finalDescription = ansis.white(description)
683
- else var finalDescription = ansis[descriptionColor](description)
683
+ else var finalDescription = ansis[(descriptionColor == "normal" ? "white" : descriptionColor)](description)
684
684
 
685
685
  final.push(finalTitle+finalDescription)
686
686
  })
@@ -29,7 +29,7 @@ export class ODDatabaseManager<IdList extends ODDatabaseManagerIdConstraint = OD
29
29
  for (const database of this.getAll()){
30
30
  try{
31
31
  await database.init()
32
- }catch(err){
32
+ }catch(err:any){
33
33
  process.emit("uncaughtException",new ODSystemError(err))
34
34
  }
35
35
  }
@@ -1,8 +1,8 @@
1
1
  ///////////////////////////////////////
2
2
  //EVENT MODULE
3
3
  ///////////////////////////////////////
4
- import { ODManagerData, ODManager, ODValidId, ODPromiseVoid, ODNoGeneric } from "./base"
5
- import { ODConsoleWarningMessage, ODDebugger } from "./console"
4
+ import { ODManagerData, ODManager, ODValidId, ODPromiseVoid, ODNoGeneric, ODSystemError } from "./base"
5
+ import { ODWarningConsoleMessage, ODDebugger } from "./console"
6
6
 
7
7
  /**## ODEventCallback `type`
8
8
  * The base callback function for events.
@@ -47,7 +47,7 @@ export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends
47
47
  this.listeners.push(callback)
48
48
 
49
49
  if (this.listeners.length > this.listenerLimit){
50
- if (this.#debug) this.#debug.console.log(new ODConsoleWarningMessage("Possible event memory leak detected!",[
50
+ if (this.#debug) this.#debug.console.log(new ODWarningConsoleMessage("Possible event memory leak detected!",[
51
51
  {key:"event",value:this.id.value},
52
52
  {key:"listeners",value:this.listeners.length.toString()}
53
53
  ]))
@@ -68,8 +68,8 @@ export class ODEvent<Callback extends ODEventCallback = ODEventCallback> extends
68
68
  for (const listener of this.#getCurrentListeners()){
69
69
  try{
70
70
  await listener(...params)
71
- }catch(err){
72
- process.emit("uncaughtException",err)
71
+ }catch(err:any){
72
+ process.emit("uncaughtException",new ODSystemError(err))
73
73
  }
74
74
  }
75
75
  }
@@ -1,7 +1,7 @@
1
1
  ///////////////////////////////////////
2
2
  //HELP MODULE
3
3
  ///////////////////////////////////////
4
- import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base"
4
+ import { ODId, ODManager, ODManagerData, ODNoGeneric, ODSystemError, ODValidId } from "./base"
5
5
  import { ODDebugger } from "./console"
6
6
 
7
7
  /**## ODHelpMenuComponentRenderer `type`
@@ -134,8 +134,8 @@ export class ODHelpMenuCategory<IdList extends ODHelpMenuCategoryIdConstraint =
134
134
  for (const component of derefArray){
135
135
  try {
136
136
  result.push(await component.render(page,category,i,mode))
137
- }catch(err){
138
- process.emit("uncaughtException",err)
137
+ }catch(err:any){
138
+ process.emit("uncaughtException",new ODSystemError(err))
139
139
  }
140
140
  i++
141
141
  }
@@ -149,7 +149,7 @@ export class ODLanguageManager<IdList extends ODLanguageManagerIdConstraint = OD
149
149
  for (const language of this.getAll()){
150
150
  try{
151
151
  await language.init()
152
- }catch(err){
152
+ }catch(err:any){
153
153
  process.emit("uncaughtException",new ODSystemError(err))
154
154
  }
155
155
  }
@@ -185,7 +185,7 @@ export class ODPlugin extends ODManagerData {
185
185
  debug.console.log("Plugin \""+this.id.value+"\" loaded successfully!","plugin")
186
186
  this.executed = true
187
187
  return true
188
- }catch(error){
188
+ }catch(error:any){
189
189
  this.crashed = true
190
190
  this.crashReason = "executed"
191
191
 
@@ -122,9 +122,11 @@ export class ODProgressBarRenderer<Settings extends {}> extends ODManagerData {
122
122
 
123
123
  withAdditionalSettings(settings:Partial<Settings>): ODProgressBarRenderer<Settings> {
124
124
  const newSettings: Settings = {...this.settings}
125
- for (const key of Object.keys(settings)){
125
+ for (const key of Object.keys(settings) as (keyof Partial<Settings>)[]){
126
126
  if (typeof settings[key] != "undefined") newSettings[key] = settings[key]
127
127
  }
128
+
129
+ const idk = Object.keys(settings)
128
130
  return new ODProgressBarRenderer(this.id,this.#render,newSettings)
129
131
  }
130
132
  }