@open-discord-bots/framework 0.0.1 → 0.0.2

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 (103) hide show
  1. package/LICENSE.md +713 -0
  2. package/README.md +104 -0
  3. package/dist/api/api.d.ts +26 -0
  4. package/dist/api/api.js +44 -0
  5. package/dist/api/main.d.ts +133 -0
  6. package/dist/api/main.js +87 -0
  7. package/dist/api/modules/action.d.ts +34 -0
  8. package/dist/api/modules/action.js +58 -0
  9. package/dist/api/modules/base.d.ts +329 -0
  10. package/dist/api/modules/base.js +804 -0
  11. package/dist/api/modules/builder.d.ts +647 -0
  12. package/dist/api/modules/builder.js +1441 -0
  13. package/dist/api/modules/checker.d.ts +648 -0
  14. package/dist/api/modules/checker.js +1324 -0
  15. package/dist/api/modules/client.d.ts +768 -0
  16. package/dist/api/modules/client.js +1859 -0
  17. package/dist/api/modules/code.d.ts +33 -0
  18. package/dist/api/modules/code.js +57 -0
  19. package/dist/api/modules/config.d.ts +70 -0
  20. package/dist/api/modules/config.js +206 -0
  21. package/dist/api/modules/console.d.ts +305 -0
  22. package/dist/api/modules/console.js +598 -0
  23. package/dist/api/modules/cooldown.d.ts +138 -0
  24. package/dist/api/modules/cooldown.js +359 -0
  25. package/dist/api/modules/database.d.ts +135 -0
  26. package/dist/api/modules/database.js +271 -0
  27. package/dist/api/modules/event.d.ts +43 -0
  28. package/dist/api/modules/event.js +100 -0
  29. package/dist/api/modules/flag.d.ts +40 -0
  30. package/dist/api/modules/flag.js +72 -0
  31. package/dist/api/modules/fuse.d.ts +218 -0
  32. package/dist/api/modules/fuse.js +123 -0
  33. package/dist/api/modules/helpmenu.d.ts +106 -0
  34. package/dist/api/modules/helpmenu.js +167 -0
  35. package/dist/api/modules/language.d.ts +85 -0
  36. package/dist/api/modules/language.js +195 -0
  37. package/dist/api/modules/permission.d.ts +121 -0
  38. package/dist/api/modules/permission.js +314 -0
  39. package/dist/api/modules/plugin.d.ts +128 -0
  40. package/dist/api/modules/plugin.js +168 -0
  41. package/dist/api/modules/post.d.ts +44 -0
  42. package/dist/api/modules/post.js +92 -0
  43. package/dist/api/modules/progressbar.d.ts +108 -0
  44. package/dist/api/modules/progressbar.js +233 -0
  45. package/dist/api/modules/responder.d.ts +506 -0
  46. package/dist/api/modules/responder.js +1468 -0
  47. package/dist/api/modules/session.d.ts +58 -0
  48. package/dist/api/modules/session.js +171 -0
  49. package/dist/api/modules/startscreen.d.ts +165 -0
  50. package/dist/api/modules/startscreen.js +293 -0
  51. package/dist/api/modules/stat.d.ts +142 -0
  52. package/dist/api/modules/stat.js +293 -0
  53. package/dist/api/modules/verifybar.d.ts +54 -0
  54. package/dist/api/modules/verifybar.js +60 -0
  55. package/dist/api/modules/worker.d.ts +41 -0
  56. package/dist/api/modules/worker.js +93 -0
  57. package/dist/api/utils.d.ts +61 -0
  58. package/dist/api/utils.js +254 -0
  59. package/dist/index.d.ts +4 -1
  60. package/dist/index.js +40 -0
  61. package/dist/startup/dump.d.ts +14 -0
  62. package/dist/startup/dump.js +79 -0
  63. package/dist/startup/errorHandling.d.ts +2 -0
  64. package/dist/startup/errorHandling.js +43 -0
  65. package/dist/startup/pluginLauncher.d.ts +2 -0
  66. package/dist/startup/pluginLauncher.js +202 -0
  67. package/package.json +9 -3
  68. package/src/api/api.ts +29 -0
  69. package/src/api/main.ts +189 -0
  70. package/src/api/modules/action.ts +58 -0
  71. package/src/api/modules/base.ts +811 -0
  72. package/src/api/modules/builder.ts +1554 -0
  73. package/src/api/modules/checker.ts +1549 -0
  74. package/src/api/modules/client.ts +2247 -0
  75. package/src/api/modules/code.ts +58 -0
  76. package/src/api/modules/config.ts +159 -0
  77. package/src/api/modules/console.ts +665 -0
  78. package/src/api/modules/cooldown.ts +348 -0
  79. package/src/api/modules/database.ts +278 -0
  80. package/src/api/modules/event.ts +99 -0
  81. package/src/api/modules/flag.ts +73 -0
  82. package/src/api/modules/fuse.ts +348 -0
  83. package/src/api/modules/helpmenu.ts +216 -0
  84. package/src/api/modules/language.ts +201 -0
  85. package/src/api/modules/permission.ts +340 -0
  86. package/src/api/modules/plugin.ts +242 -0
  87. package/src/api/modules/post.ts +90 -0
  88. package/src/api/modules/progressbar.ts +232 -0
  89. package/src/api/modules/responder.ts +1420 -0
  90. package/src/api/modules/session.ts +155 -0
  91. package/src/api/modules/startscreen.ts +320 -0
  92. package/src/api/modules/stat.ts +313 -0
  93. package/src/api/modules/verifybar.ts +61 -0
  94. package/src/api/modules/worker.ts +93 -0
  95. package/src/api/utils.ts +206 -0
  96. package/src/cli/cli.ts +151 -0
  97. package/src/cli/editConfig.ts +943 -0
  98. package/src/index.ts +6 -1
  99. package/src/startup/compilation.ts +186 -0
  100. package/src/startup/dump.ts +45 -0
  101. package/src/startup/errorHandling.ts +38 -0
  102. package/src/startup/pluginLauncher.ts +261 -0
  103. package/LICENSE +0 -21
@@ -0,0 +1,232 @@
1
+ ///////////////////////////////////////
2
+ //PROGRESS BAR MODULE
3
+ ///////////////////////////////////////
4
+ import { ODSystemError, ODManager, ODManagerData, ODValidId } from "./base"
5
+ import { ODDebugger } from "./console"
6
+ import readline from "readline"
7
+
8
+ /**## ODProgressBarRendererManager `class`
9
+ * This is an Open Discord progress bar renderer manager.
10
+ *
11
+ * It is responsible for managing all console progress bar renderers in Open Discord.
12
+ *
13
+ * A renderer is a function which will try to visualize the progress bar in the console.
14
+ */
15
+ export class ODProgressBarRendererManager extends ODManager<ODProgressBarRenderer<{}>> {
16
+ constructor(debug:ODDebugger){
17
+ super(debug,"progress bar renderer")
18
+ }
19
+ }
20
+
21
+ /**## ODProgressBarManager `class`
22
+ * This is an Open Discord progress bar manager.
23
+ *
24
+ * It is responsible for managing all console progress bars in Open Discord. An example of this is the slash command registration progress bar.
25
+ *
26
+ * There are many types of progress bars available, but you can also create your own!
27
+ */
28
+ export class ODProgressBarManager extends ODManager<ODProgressBar> {
29
+ renderers: ODProgressBarRendererManager
30
+
31
+ constructor(debug:ODDebugger){
32
+ super(debug,"progress bar")
33
+ this.renderers = new ODProgressBarRendererManager(debug)
34
+ }
35
+ }
36
+
37
+ /**## ODProgressBarRenderFunc `type`
38
+ * This is the render function for an Open Discord console progress bar.
39
+ */
40
+ export type ODProgressBarRenderFunc<Settings extends {}> = (settings:Settings,min:number,max:number,value:number,prefix:string|null,suffix:string|null) => string
41
+
42
+ /**## ODProgressBarRenderer `class`
43
+ * This is an Open Discord console progress bar renderer.
44
+ *
45
+ * It is used to render a progress bar in the console of the bot.
46
+ *
47
+ * There are already a lot of default options available if you just want an easy progress bar!
48
+ */
49
+ export class ODProgressBarRenderer<Settings extends {}> extends ODManagerData {
50
+ settings: Settings
51
+ #render: ODProgressBarRenderFunc<Settings>
52
+
53
+ constructor(id:ODValidId,render:ODProgressBarRenderFunc<Settings>,settings:Settings){
54
+ super(id)
55
+ this.#render = render
56
+ this.settings = settings
57
+ }
58
+
59
+ /**Render a progress bar using this renderer. */
60
+ render(min:number,max:number,value:number,prefix:string|null,suffix:string|null){
61
+ try {
62
+ return this.#render(this.settings,min,max,value,prefix,suffix)
63
+ }catch(err){
64
+ process.emit("uncaughtException",err)
65
+ return "<PROGRESS-BAR-ERROR>"
66
+ }
67
+ }
68
+
69
+ withAdditionalSettings(settings:Partial<Settings>): ODProgressBarRenderer<Settings> {
70
+ const newSettings: Settings = {...this.settings}
71
+ for (const key of Object.keys(settings)){
72
+ if (typeof settings[key] != "undefined") newSettings[key] = settings[key]
73
+ }
74
+ return new ODProgressBarRenderer(this.id,this.#render,newSettings)
75
+ }
76
+ }
77
+
78
+ /**## ODProgressBar `class`
79
+ * This is an Open Discord console progress bar.
80
+ *
81
+ * It is used to create a simple or advanced progress bar in the console of the bot.
82
+ * These progress bars are not visible in the `debug.txt` file and should only be used as extra visuals.
83
+ *
84
+ * Use other classes as existing templates or create your own progress bar from scratch using this class.
85
+ */
86
+ export class ODProgressBar extends ODManagerData {
87
+ /**The renderer of this progress bar. */
88
+ renderer: ODProgressBarRenderer<{}>
89
+ /**Is this progress bar currently active? */
90
+ #active: boolean = false
91
+ /**A list of listeners when the progress bar stops. */
92
+ #stopListeners: Function[] = []
93
+ /**The current value of the progress bar. */
94
+ protected value: number
95
+ /**The minimum value of the progress bar. */
96
+ min: number
97
+ /**The maximum value of the progress bar. */
98
+ max: number
99
+ /**The initial value of the progress bar. */
100
+ initialValue: number
101
+ /**The prefix displayed in the progress bar. */
102
+ prefix:string|null
103
+ /**The prefix displayed in the progress bar. */
104
+ suffix:string|null
105
+
106
+ /**Enable automatic stopping when reaching `min` or `max`. */
107
+ autoStop: null|"min"|"max"
108
+
109
+ constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,min:number,max:number,value:number,autoStop:null|"min"|"max",prefix:string|null,suffix:string|null){
110
+ super(id)
111
+ this.renderer = renderer
112
+ this.min = min
113
+ this.max = max
114
+ this.initialValue = this.#parseValue(value)
115
+ this.value = this.#parseValue(value)
116
+ this.autoStop = autoStop
117
+ this.prefix = prefix
118
+ this.suffix = suffix
119
+ }
120
+ /**Parse a value in such a way that it doesn't go below/above the min/max limits. */
121
+ #parseValue(value:number){
122
+ if (value > this.max) return this.max
123
+ else if (value < this.min) return this.min
124
+ else return value
125
+ }
126
+ /**Render progress bar to the console. */
127
+ #renderStdout(){
128
+ if (!this.#active) return
129
+ readline.clearLine(process.stdout,0)
130
+ readline.cursorTo(process.stdout,0)
131
+ process.stdout.write(this.renderer.render(this.min,this.max,this.value,this.prefix,this.suffix))
132
+ }
133
+ /**Start showing this progress bar in the console. */
134
+ start(): boolean {
135
+ if (this.#active) return false
136
+ this.value = this.#parseValue(this.initialValue)
137
+ this.#active = true
138
+ this.#renderStdout()
139
+ return true
140
+ }
141
+ /**Update this progress bar while active. (will automatically update the progress bar in the console) */
142
+ protected update(value:number,stop?:boolean): boolean {
143
+ if (!this.#active) return false
144
+ this.value = this.#parseValue(value)
145
+ this.#renderStdout()
146
+ if (stop || (this.autoStop == "max" && this.value == this.max) || (this.autoStop == "min" && this.value == this.min)){
147
+ process.stdout.write("\n")
148
+ this.#active = false
149
+ this.#stopListeners.forEach((cb) => cb())
150
+ this.#stopListeners = []
151
+ }
152
+ return true
153
+ }
154
+ /**Wait for the progress bar to finish. */
155
+ finished(): Promise<void> {
156
+ return new Promise((resolve) => {
157
+ this.#stopListeners.push(resolve)
158
+ })
159
+ }
160
+ }
161
+
162
+ /**## ODTimedProgressBar `class`
163
+ * This is an Open Discord timed console progress bar.
164
+ *
165
+ * It is used to create a simple timed progress bar in the console.
166
+ * You can set a fixed duration (milliseconds) in the constructor.
167
+ */
168
+ export class ODTimedProgressBar extends ODProgressBar {
169
+ /**The time in milliseconds. */
170
+ time: number
171
+ /**The mode of the timer. */
172
+ mode: "increasing"|"decreasing"
173
+
174
+ constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,time:number,mode:"increasing"|"decreasing",prefix:string|null,suffix:string|null){
175
+ super(id,renderer,0,time,0,(mode == "increasing") ? "max" : "min",prefix,suffix)
176
+ this.time = time
177
+ this.mode = mode
178
+ }
179
+
180
+ /**The timer which is used. */
181
+ async #timer(ms:number): Promise<void> {
182
+ return new Promise((resolve) => {
183
+ setTimeout(() => {
184
+ resolve()
185
+ },ms)
186
+ })
187
+ }
188
+ /**Run the timed progress bar. */
189
+ async #execute(){
190
+ let i = 0
191
+ const fragment = this.time/100
192
+ while (i < 100){
193
+ await this.#timer(fragment)
194
+ i++
195
+ super.update((this.mode == "increasing") ? (i*fragment) : this.time-(i*fragment))
196
+ }
197
+ }
198
+ start(){
199
+ const res = super.start()
200
+ if (!res) return false
201
+ this.#execute()
202
+ return true
203
+ }
204
+ }
205
+
206
+ /**## ODManualProgressBar `class`
207
+ * This is an Open Discord manual console progress bar.
208
+ *
209
+ * It is used to create a simple manual progress bar in the console.
210
+ * You can update the progress manually using `update()`.
211
+ */
212
+ export class ODManualProgressBar extends ODProgressBar {
213
+ constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,amount:number,autoStop:null|"min"|"max",prefix:string|null,suffix:string|null){
214
+ super(id,renderer,0,amount,0,autoStop,prefix,suffix)
215
+ }
216
+ /**Set the value of the progress bar. */
217
+ set(value:number,stop?:boolean){
218
+ super.update(value,stop)
219
+ }
220
+ /**Get the current value of the progress bar. */
221
+ get(){
222
+ return this.value
223
+ }
224
+ /**Increase the value of the progress bar. */
225
+ increase(amount:number,stop?:boolean){
226
+ super.update(this.value+amount,stop)
227
+ }
228
+ /**Decrease the value of the progress bar. */
229
+ decrease(amount:number,stop?:boolean){
230
+ super.update(this.value-amount,stop)
231
+ }
232
+ }