@open-discord-bots/framework 0.3.0 → 0.3.1
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.
- package/dist/api/main.js +1 -1
- package/dist/api/modules/base.d.ts +27 -9
- package/dist/api/modules/base.js +78 -80
- package/dist/api/modules/builder.d.ts +0 -9
- package/dist/api/modules/checker.d.ts +26 -5
- package/dist/api/modules/checker.js +31 -31
- package/dist/api/modules/client.d.ts +66 -14
- package/dist/api/modules/client.js +146 -132
- package/dist/api/modules/component.d.ts +8 -2
- package/dist/api/modules/component.js +8 -6
- package/dist/api/modules/config.d.ts +0 -1
- package/dist/api/modules/config.js +9 -7
- package/dist/api/modules/console.d.ts +16 -4
- package/dist/api/modules/console.js +25 -25
- package/dist/api/modules/event.d.ts +4 -2
- package/dist/api/modules/event.js +8 -10
- package/dist/api/modules/fuse.d.ts +1 -1
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +4 -7
- package/dist/api/modules/language.d.ts +2 -1
- package/dist/api/modules/language.js +6 -9
- package/dist/api/modules/permission.d.ts +10 -1
- package/dist/api/modules/permission.js +17 -20
- package/dist/api/modules/plugin.d.ts +2 -1
- package/dist/api/modules/plugin.js +2 -2
- package/dist/api/modules/post.d.ts +12 -4
- package/dist/api/modules/post.js +36 -10
- package/dist/api/modules/progressbar.d.ts +16 -5
- package/dist/api/modules/progressbar.js +34 -34
- package/dist/api/modules/responder.d.ts +95 -26
- package/dist/api/modules/responder.js +213 -172
- package/dist/api/modules/session.d.ts +10 -1
- package/dist/api/modules/session.js +15 -15
- package/dist/api/modules/startscreen.d.ts +0 -1
- package/dist/api/modules/startscreen.js +3 -6
- package/dist/api/modules/statistic.d.ts +2 -1
- package/dist/api/modules/statistic.js +4 -7
- package/dist/api/modules/worker.d.ts +2 -1
- package/dist/api/modules/worker.js +3 -3
- package/package.json +1 -1
- package/src/api/main.ts +1 -1
- package/src/api/modules/base.ts +75 -77
- package/src/api/modules/builder.ts +0 -10
- package/src/api/modules/checker.ts +31 -31
- package/src/api/modules/client.ts +144 -136
- package/src/api/modules/component.ts +11 -7
- package/src/api/modules/config.ts +8 -6
- package/src/api/modules/console.ts +25 -25
- package/src/api/modules/event.ts +6 -10
- package/src/api/modules/fuse.ts +1 -1
- package/src/api/modules/helpmenu.ts +4 -7
- package/src/api/modules/language.ts +6 -9
- package/src/api/modules/permission.ts +17 -20
- package/src/api/modules/plugin.ts +2 -2
- package/src/api/modules/post.ts +31 -10
- package/src/api/modules/progressbar.ts +34 -34
- package/src/api/modules/responder.ts +232 -181
- package/src/api/modules/session.ts +14 -14
- package/src/api/modules/startscreen.ts +3 -6
- package/src/api/modules/statistic.ts +4 -7
- package/src/api/modules/worker.ts +3 -3
|
@@ -102,18 +102,18 @@ export type ODProgressBarRenderFunc<Settings extends {}> = (settings:Settings,mi
|
|
|
102
102
|
*/
|
|
103
103
|
export class ODProgressBarRenderer<Settings extends {}> extends ODManagerData {
|
|
104
104
|
settings: Settings
|
|
105
|
-
|
|
105
|
+
private renderFunction: ODProgressBarRenderFunc<Settings>
|
|
106
106
|
|
|
107
|
-
constructor(id:ODValidId,
|
|
107
|
+
constructor(id:ODValidId,renderFunction:ODProgressBarRenderFunc<Settings>,settings:Settings){
|
|
108
108
|
super(id)
|
|
109
|
-
this
|
|
109
|
+
this.renderFunction = renderFunction
|
|
110
110
|
this.settings = settings
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**Render a progress bar using this renderer. */
|
|
114
114
|
render(min:number,max:number,value:number,prefix:string|null,suffix:string|null){
|
|
115
115
|
try {
|
|
116
|
-
return this
|
|
116
|
+
return this.renderFunction(this.settings,min,max,value,prefix,suffix)
|
|
117
117
|
}catch(err){
|
|
118
118
|
process.emit("uncaughtException",err)
|
|
119
119
|
return "<PROGRESS-BAR-ERROR>"
|
|
@@ -126,7 +126,7 @@ export class ODProgressBarRenderer<Settings extends {}> extends ODManagerData {
|
|
|
126
126
|
if (typeof settings[key] != "undefined") newSettings[key] = settings[key]
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
return new ODProgressBarRenderer(this.id,this
|
|
129
|
+
return new ODProgressBarRenderer(this.id,this.renderFunction,newSettings)
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
@@ -142,9 +142,9 @@ export abstract class ODProgressBar extends ODManagerData {
|
|
|
142
142
|
/**The renderer of this progress bar. */
|
|
143
143
|
renderer: ODProgressBarRenderer<{}>
|
|
144
144
|
/**Is this progress bar currently active? */
|
|
145
|
-
|
|
145
|
+
protected active: boolean = false
|
|
146
146
|
/**A list of listeners when the progress bar stops. */
|
|
147
|
-
|
|
147
|
+
protected stopListeners: Function[] = []
|
|
148
148
|
/**The current value of the progress bar. */
|
|
149
149
|
protected value: number
|
|
150
150
|
/**The minimum value of the progress bar. */
|
|
@@ -166,50 +166,50 @@ export abstract class ODProgressBar extends ODManagerData {
|
|
|
166
166
|
this.renderer = renderer
|
|
167
167
|
this.min = min
|
|
168
168
|
this.max = max
|
|
169
|
-
this.initialValue = this
|
|
170
|
-
this.value = this
|
|
169
|
+
this.initialValue = this.parseValue(value)
|
|
170
|
+
this.value = this.parseValue(value)
|
|
171
171
|
this.autoStop = autoStop
|
|
172
172
|
this.prefix = prefix
|
|
173
173
|
this.suffix = suffix
|
|
174
174
|
}
|
|
175
175
|
/**Parse a value in such a way that it doesn't go below/above the min/max limits. */
|
|
176
|
-
|
|
176
|
+
private parseValue(value:number){
|
|
177
177
|
if (value > this.max) return this.max
|
|
178
178
|
else if (value < this.min) return this.min
|
|
179
179
|
else return value
|
|
180
180
|
}
|
|
181
181
|
/**Render progress bar to the console. */
|
|
182
|
-
|
|
183
|
-
if (!this
|
|
182
|
+
private renderStdout(){
|
|
183
|
+
if (!this.active) return
|
|
184
184
|
readline.clearLine(process.stdout,0)
|
|
185
185
|
readline.cursorTo(process.stdout,0)
|
|
186
186
|
process.stdout.write(this.renderer.render(this.min,this.max,this.value,this.prefix,this.suffix))
|
|
187
187
|
}
|
|
188
188
|
/**Start showing this progress bar in the console. */
|
|
189
189
|
start(): boolean {
|
|
190
|
-
if (this
|
|
191
|
-
this.value = this
|
|
192
|
-
this
|
|
193
|
-
this
|
|
190
|
+
if (this.active) return false
|
|
191
|
+
this.value = this.parseValue(this.initialValue)
|
|
192
|
+
this.active = true
|
|
193
|
+
this.renderStdout()
|
|
194
194
|
return true
|
|
195
195
|
}
|
|
196
196
|
/**Update this progress bar while active. (will automatically update the progress bar in the console) */
|
|
197
197
|
protected update(value:number,stop?:boolean): boolean {
|
|
198
|
-
if (!this
|
|
199
|
-
this.value = this
|
|
200
|
-
this
|
|
198
|
+
if (!this.active) return false
|
|
199
|
+
this.value = this.parseValue(value)
|
|
200
|
+
this.renderStdout()
|
|
201
201
|
if (stop || (this.autoStop == "max" && this.value == this.max) || (this.autoStop == "min" && this.value == this.min)){
|
|
202
202
|
process.stdout.write("\n")
|
|
203
|
-
this
|
|
204
|
-
this
|
|
205
|
-
this
|
|
203
|
+
this.active = false
|
|
204
|
+
this.stopListeners.forEach((cb) => cb())
|
|
205
|
+
this.stopListeners = []
|
|
206
206
|
}
|
|
207
207
|
return true
|
|
208
208
|
}
|
|
209
209
|
/**Wait for the progress bar to finish. */
|
|
210
210
|
finished(): Promise<void> {
|
|
211
211
|
return new Promise((resolve) => {
|
|
212
|
-
this
|
|
212
|
+
this.stopListeners.push(resolve)
|
|
213
213
|
})
|
|
214
214
|
}
|
|
215
215
|
}
|
|
@@ -233,7 +233,7 @@ export class ODTimedProgressBar extends ODProgressBar {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**The timer which is used. */
|
|
236
|
-
async
|
|
236
|
+
private async timer(ms:number): Promise<void> {
|
|
237
237
|
return new Promise((resolve) => {
|
|
238
238
|
setTimeout(() => {
|
|
239
239
|
resolve()
|
|
@@ -241,11 +241,11 @@ export class ODTimedProgressBar extends ODProgressBar {
|
|
|
241
241
|
})
|
|
242
242
|
}
|
|
243
243
|
/**Run the timed progress bar. */
|
|
244
|
-
async
|
|
244
|
+
private async execute(){
|
|
245
245
|
let i = 0
|
|
246
246
|
const fragment = this.time/100
|
|
247
247
|
while (i < 100){
|
|
248
|
-
await this
|
|
248
|
+
await this.timer(fragment)
|
|
249
249
|
i++
|
|
250
250
|
super.update((this.mode == "increasing") ? (i*fragment) : this.time-(i*fragment))
|
|
251
251
|
}
|
|
@@ -253,7 +253,7 @@ export class ODTimedProgressBar extends ODProgressBar {
|
|
|
253
253
|
start(){
|
|
254
254
|
const res = super.start()
|
|
255
255
|
if (!res) return false
|
|
256
|
-
this
|
|
256
|
+
this.execute()
|
|
257
257
|
return true
|
|
258
258
|
}
|
|
259
259
|
}
|
|
@@ -337,12 +337,12 @@ export class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaul
|
|
|
337
337
|
const percentage = (value-min)/(max-min)
|
|
338
338
|
const barLevel = Math.round(percentage*settings.barWidth)
|
|
339
339
|
|
|
340
|
-
const borderAnsis = this
|
|
341
|
-
const filledBarAnsis = this
|
|
342
|
-
const emptyBarAnsis = this
|
|
343
|
-
const labelAnsis = this
|
|
344
|
-
const prefixAnsis = this
|
|
345
|
-
const suffixAnsis = this
|
|
340
|
+
const borderAnsis = this.switchColorAnsis(settings.borderColor)
|
|
341
|
+
const filledBarAnsis = this.switchColorAnsis(settings.filledBarColor)
|
|
342
|
+
const emptyBarAnsis = this.switchColorAnsis(settings.emptyBarColor)
|
|
343
|
+
const labelAnsis = this.switchColorAnsis(settings.labelColor)
|
|
344
|
+
const prefixAnsis = this.switchColorAnsis(settings.prefixColor)
|
|
345
|
+
const suffixAnsis = this.switchColorAnsis(settings.suffixColor)
|
|
346
346
|
|
|
347
347
|
const leftBorder = (settings.showBorder) ? borderAnsis(settings.leftBorderChar) : ""
|
|
348
348
|
const rightBorder = (settings.showBorder) ? borderAnsis(settings.rightBorderChar) : ""
|
|
@@ -364,7 +364,7 @@ export class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaul
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
/**Switch between Ansis functions based on the specified color. */
|
|
367
|
-
|
|
367
|
+
private switchColorAnsis(c:ODValidConsoleColor|"openticket"|"openmoderation"){
|
|
368
368
|
return (c === "openticket") ? ansis.hex("#f8ba00") : (c === "openmoderation") ? ansis.hex("#1690ff") : ansis[c]
|
|
369
369
|
}
|
|
370
370
|
}
|