@open-discord-bots/framework 0.3.13 → 0.3.15
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/responder.js +50 -26
- package/dist/api/modules/verifybar.d.ts +1 -1
- package/dist/api/modules/verifybar.js +1 -1
- package/package.json +1 -1
- package/src/api/index.ts +0 -31
- package/src/api/main.ts +0 -203
- package/src/api/modules/action.ts +0 -89
- package/src/api/modules/base.ts +0 -845
- package/src/api/modules/builder.ts +0 -1755
- package/src/api/modules/checker.ts +0 -1826
- package/src/api/modules/client.ts +0 -2345
- package/src/api/modules/code.ts +0 -84
- package/src/api/modules/component.ts +0 -2000
- package/src/api/modules/config.ts +0 -264
- package/src/api/modules/console.ts +0 -697
- package/src/api/modules/cooldown.ts +0 -369
- package/src/api/modules/database.ts +0 -321
- package/src/api/modules/event.ts +0 -123
- package/src/api/modules/flag.ts +0 -99
- package/src/api/modules/fuse.ts +0 -365
- package/src/api/modules/helpmenu.ts +0 -273
- package/src/api/modules/language.ts +0 -230
- package/src/api/modules/permission.ts +0 -363
- package/src/api/modules/plugin.ts +0 -294
- package/src/api/modules/post.ts +0 -137
- package/src/api/modules/progressbar.ts +0 -370
- package/src/api/modules/responder.ts +0 -1625
- package/src/api/modules/session.ts +0 -181
- package/src/api/modules/startscreen.ts +0 -345
- package/src/api/modules/state.ts +0 -298
- package/src/api/modules/statistic.ts +0 -380
- package/src/api/modules/verifybar.ts +0 -68
- package/src/api/modules/worker.ts +0 -119
- package/src/cli/editConfig.ts +0 -930
- package/src/cli/index.ts +0 -152
- package/src/index.ts +0 -8
- package/src/startup/compilation.ts +0 -204
- package/src/startup/dump.ts +0 -46
- package/src/startup/errorHandling.ts +0 -42
- package/src/startup/pluginLauncher.ts +0 -265
- package/src/utilities/index.ts +0 -229
- package/tools/cleanup.js +0 -2
package/src/api/modules/post.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
///////////////////////////////////////
|
|
2
|
-
//POST MODULE
|
|
3
|
-
///////////////////////////////////////
|
|
4
|
-
import { ODId, ODManager, ODManagerData, ODNoGeneric, ODValidId } from "./base.js"
|
|
5
|
-
import { ODMessageBuildResult } from "./builder.js"
|
|
6
|
-
import { ODDebugger } from "./console.js"
|
|
7
|
-
import * as discord from "discord.js"
|
|
8
|
-
import { ODResponderSendResult } from "./responder.js"
|
|
9
|
-
import { ODMessageComponentBuildResult } from "./component.js"
|
|
10
|
-
|
|
11
|
-
/**## ODPostManagerIdConstraint `type`
|
|
12
|
-
* The constraint/layout for id mappings/interfaces of the `ODPostManager` class.
|
|
13
|
-
*/
|
|
14
|
-
export type ODPostManagerIdConstraint = Record<string,ODPost<discord.GuildBasedChannel>|null>
|
|
15
|
-
|
|
16
|
-
/**## ODPostManager `class`
|
|
17
|
-
* This is an Open Discord post manager.
|
|
18
|
-
*
|
|
19
|
-
* It manages `ODPosts`'s for you.
|
|
20
|
-
*
|
|
21
|
-
* You can use this to get the logs channel of the bot (or some other static channel/category).
|
|
22
|
-
*/
|
|
23
|
-
export class ODPostManager<IdList extends ODPostManagerIdConstraint = ODPostManagerIdConstraint> extends ODManager<ODPost<discord.GuildBasedChannel>> {
|
|
24
|
-
/**A reference to the main server of the bot */
|
|
25
|
-
protected guild: discord.Guild|null = null
|
|
26
|
-
|
|
27
|
-
constructor(debug:ODDebugger){
|
|
28
|
-
super(debug,"post")
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
add(data:ODPost<discord.GuildBasedChannel>, overwrite?:boolean): boolean {
|
|
32
|
-
if (this.guild) data.useGuild(this.guild)
|
|
33
|
-
return super.add(data,overwrite)
|
|
34
|
-
}
|
|
35
|
-
/**Initialize the post manager & all posts. */
|
|
36
|
-
async init(guild:discord.Guild){
|
|
37
|
-
this.guild = guild
|
|
38
|
-
for (const post of this.getAll()){
|
|
39
|
-
post.useGuild(guild)
|
|
40
|
-
await post.init()
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get<PostId extends keyof ODNoGeneric<IdList>>(id:PostId): IdList[PostId]
|
|
45
|
-
get(id:ODValidId): ODPost<discord.GuildBasedChannel>|null
|
|
46
|
-
|
|
47
|
-
get(id:ODValidId): ODPost<discord.GuildBasedChannel>|null {
|
|
48
|
-
return super.get(id)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
remove<PostId extends keyof ODNoGeneric<IdList>>(id:PostId): IdList[PostId]
|
|
52
|
-
remove(id:ODValidId): ODPost<discord.GuildBasedChannel>|null
|
|
53
|
-
|
|
54
|
-
remove(id:ODValidId): ODPost<discord.GuildBasedChannel>|null {
|
|
55
|
-
return super.remove(id)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
59
|
-
exists(id:ODValidId): boolean
|
|
60
|
-
|
|
61
|
-
exists(id:ODValidId): boolean {
|
|
62
|
-
return super.exists(id)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**## ODPost `class`
|
|
67
|
-
* This is an Open Discord post class.
|
|
68
|
-
*
|
|
69
|
-
* A post is just a shortcut to a static discord channel or category.
|
|
70
|
-
* This can be used to get a specific channel over and over again!
|
|
71
|
-
*
|
|
72
|
-
* This class also contains utilities for sending messages via the Open Discord builders.
|
|
73
|
-
*/
|
|
74
|
-
export class ODPost<ChannelType extends discord.GuildBasedChannel> extends ODManagerData {
|
|
75
|
-
/**A reference to the main server of the bot */
|
|
76
|
-
protected guild: discord.Guild|null = null
|
|
77
|
-
/**Is this post already initialized? */
|
|
78
|
-
ready: boolean = false
|
|
79
|
-
/**The discord.js channel */
|
|
80
|
-
channel: ChannelType|null = null
|
|
81
|
-
/**The discord channel id */
|
|
82
|
-
channelId: string
|
|
83
|
-
|
|
84
|
-
constructor(id:ODValidId, channelId:string){
|
|
85
|
-
super(id)
|
|
86
|
-
this.channelId = channelId
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**Use a specific guild in this class for fetching the channel*/
|
|
90
|
-
useGuild(guild:discord.Guild|null){
|
|
91
|
-
this.guild = guild
|
|
92
|
-
}
|
|
93
|
-
/**Change the channel id to another channel! */
|
|
94
|
-
setChannelId(id:string){
|
|
95
|
-
this.channelId = id
|
|
96
|
-
}
|
|
97
|
-
/**Initialize the discord.js channel of this post. */
|
|
98
|
-
async init(){
|
|
99
|
-
if (this.ready) return
|
|
100
|
-
if (!this.guild) return this.channel = null
|
|
101
|
-
try{
|
|
102
|
-
this.channel = await this.guild.channels.fetch(this.channelId) as ChannelType
|
|
103
|
-
}catch{
|
|
104
|
-
this.channel = null
|
|
105
|
-
}
|
|
106
|
-
this.ready = true
|
|
107
|
-
}
|
|
108
|
-
/**Send a message to this channel using the Open Discord builder system */
|
|
109
|
-
async send(build:ODMessageBuildResult|ODMessageComponentBuildResult): Promise<ODResponderSendResult<true>> {
|
|
110
|
-
if (!this.channel || !this.channel.isTextBased()) return {success:false}
|
|
111
|
-
try{
|
|
112
|
-
const finalMessage = this.getMessageFromBuildResult(build,"message")
|
|
113
|
-
const sent = await this.channel.send(finalMessage)
|
|
114
|
-
return {success:true,message:sent,ephemeral:false}
|
|
115
|
-
}catch{
|
|
116
|
-
return {success:false}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
/**Get the final `messageCreateOptions` from a returned build result from builders/components. */
|
|
120
|
-
protected getMessageFromBuildResult(build:ODMessageBuildResult|ODMessageComponentBuildResult,type:"interaction"|"message"){
|
|
121
|
-
const msgFlags: number[] = []
|
|
122
|
-
let msgData: discord.MessageCreateOptions
|
|
123
|
-
if ('message' in build){
|
|
124
|
-
//USING BUILDERS (deprecated)
|
|
125
|
-
msgData = build.message
|
|
126
|
-
if (build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral)
|
|
127
|
-
}else{
|
|
128
|
-
//USING COMPONENTS
|
|
129
|
-
msgData = build.msg
|
|
130
|
-
if (type == "interaction" && build.ephemeral) msgFlags.push(discord.MessageFlags.Ephemeral) //disabled with regular messages
|
|
131
|
-
if (build.componentsV2) msgFlags.push(discord.MessageFlags.IsComponentsV2)
|
|
132
|
-
if (build.supressEmbeds) msgFlags.push(discord.MessageFlags.SuppressEmbeds)
|
|
133
|
-
if (build.supressNotifications) msgFlags.push(discord.MessageFlags.SuppressNotifications)
|
|
134
|
-
}
|
|
135
|
-
return Object.assign(msgData,{flags:msgFlags})
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
///////////////////////////////////////
|
|
2
|
-
//PROGRESS BAR MODULE
|
|
3
|
-
///////////////////////////////////////
|
|
4
|
-
import { ODSystemError, ODManager, ODManagerData, ODValidId, ODNoGeneric } from "./base.js"
|
|
5
|
-
import { ODDebugger, ODValidConsoleColor } from "./console.js"
|
|
6
|
-
import readline from "readline"
|
|
7
|
-
import ansis from "ansis"
|
|
8
|
-
|
|
9
|
-
/**## ODProgressBarRendererManagerIdConstraint `type`
|
|
10
|
-
* The constraint/layout for id mappings/interfaces of the `ODProgressBarRendererManager` class.
|
|
11
|
-
*/
|
|
12
|
-
export type ODProgressBarRendererManagerIdConstraint = Record<string,ODProgressBarRenderer<{}>>
|
|
13
|
-
|
|
14
|
-
/**## ODProgressBarRendererManager `class`
|
|
15
|
-
* This is an Open Discord progress bar renderer manager.
|
|
16
|
-
*
|
|
17
|
-
* It is responsible for managing all console progress bar renderers in Open Discord.
|
|
18
|
-
*
|
|
19
|
-
* A renderer is a function which will try to visualize the progress bar in the console.
|
|
20
|
-
*/
|
|
21
|
-
export class ODProgressBarRendererManager<IdList extends ODProgressBarRendererManagerIdConstraint = ODProgressBarRendererManagerIdConstraint> extends ODManager<ODProgressBarRenderer<{}>> {
|
|
22
|
-
constructor(debug:ODDebugger){
|
|
23
|
-
super(debug,"progress bar renderer")
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get<RendererId extends keyof ODNoGeneric<IdList>>(id:RendererId): IdList[RendererId]
|
|
27
|
-
get(id:ODValidId): ODProgressBarRenderer<{}>|null
|
|
28
|
-
|
|
29
|
-
get(id:ODValidId): ODProgressBarRenderer<{}>|null {
|
|
30
|
-
return super.get(id)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
remove<RendererId extends keyof ODNoGeneric<IdList>>(id:RendererId): IdList[RendererId]
|
|
34
|
-
remove(id:ODValidId): ODProgressBarRenderer<{}>|null
|
|
35
|
-
|
|
36
|
-
remove(id:ODValidId): ODProgressBarRenderer<{}>|null {
|
|
37
|
-
return super.remove(id)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exists(id:keyof ODNoGeneric<IdList>): boolean
|
|
41
|
-
exists(id:ODValidId): boolean
|
|
42
|
-
|
|
43
|
-
exists(id:ODValidId): boolean {
|
|
44
|
-
return super.exists(id)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**## ODProgressBarManagerIdConstraint `type`
|
|
49
|
-
* The constraint/layout for id mappings/interfaces of the `ODProgressBarManager` class.
|
|
50
|
-
*/
|
|
51
|
-
export type ODProgressBarManagerIdConstraint = Record<string,ODProgressBar>
|
|
52
|
-
|
|
53
|
-
/**## ODProgressBarManager `class`
|
|
54
|
-
* This is an Open Discord progress bar manager.
|
|
55
|
-
*
|
|
56
|
-
* It is responsible for managing all console progress bars in Open Discord. An example of this is the slash command registration progress bar.
|
|
57
|
-
*
|
|
58
|
-
* There are many types of progress bars available, but you can also create your own!
|
|
59
|
-
*/
|
|
60
|
-
export class ODProgressBarManager<IdList extends ODProgressBarManagerIdConstraint = ODProgressBarManagerIdConstraint,RendererIdList extends ODProgressBarRendererManagerIdConstraint = ODProgressBarRendererManagerIdConstraint> extends ODManager<ODProgressBar> {
|
|
61
|
-
/**A collection of render types for progress bars. */
|
|
62
|
-
renderers: ODProgressBarRendererManager<RendererIdList>
|
|
63
|
-
|
|
64
|
-
constructor(debug:ODDebugger){
|
|
65
|
-
super(debug,"progress bar")
|
|
66
|
-
this.renderers = new ODProgressBarRendererManager(debug)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
get<ProgressBarId extends keyof ODNoGeneric<IdList>>(id:ProgressBarId): IdList[ProgressBarId]
|
|
70
|
-
get(id:ODValidId): ODProgressBar|null
|
|
71
|
-
|
|
72
|
-
get(id:ODValidId): ODProgressBar|null {
|
|
73
|
-
return super.get(id)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
remove<ProgressBarId extends keyof ODNoGeneric<IdList>>(id:ProgressBarId): IdList[ProgressBarId]
|
|
77
|
-
remove(id:ODValidId): ODProgressBar|null
|
|
78
|
-
|
|
79
|
-
remove(id:ODValidId): ODProgressBar|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
|
-
/**## ODProgressBarRenderFunc `type`
|
|
92
|
-
* This is the render function for an Open Discord console progress bar.
|
|
93
|
-
*/
|
|
94
|
-
export type ODProgressBarRenderFunc<Settings extends {}> = (settings:Settings,min:number,max:number,value:number,prefix:string|null,suffix:string|null) => string
|
|
95
|
-
|
|
96
|
-
/**## ODProgressBarRenderer `class`
|
|
97
|
-
* This is an Open Discord console progress bar renderer.
|
|
98
|
-
*
|
|
99
|
-
* It is used to render a progress bar in the console of the bot.
|
|
100
|
-
*
|
|
101
|
-
* There are already a lot of default options available if you just want an easy progress bar!
|
|
102
|
-
*/
|
|
103
|
-
export class ODProgressBarRenderer<Settings extends {}> extends ODManagerData {
|
|
104
|
-
settings: Settings
|
|
105
|
-
private renderFunction: ODProgressBarRenderFunc<Settings>
|
|
106
|
-
|
|
107
|
-
constructor(id:ODValidId,renderFunction:ODProgressBarRenderFunc<Settings>,settings:Settings){
|
|
108
|
-
super(id)
|
|
109
|
-
this.renderFunction = renderFunction
|
|
110
|
-
this.settings = settings
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**Render a progress bar using this renderer. */
|
|
114
|
-
render(min:number,max:number,value:number,prefix:string|null,suffix:string|null){
|
|
115
|
-
try {
|
|
116
|
-
return this.renderFunction(this.settings,min,max,value,prefix,suffix)
|
|
117
|
-
}catch(err){
|
|
118
|
-
process.emit("uncaughtException",err)
|
|
119
|
-
return "<PROGRESS-BAR-ERROR>"
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**Create a clone of this progress bar renderer, but with additional settings. */
|
|
123
|
-
withAdditionalSettings(settings:Partial<Settings>): ODProgressBarRenderer<Settings> {
|
|
124
|
-
const newSettings: Settings = {...this.settings}
|
|
125
|
-
for (const key of Object.keys(settings) as (keyof Partial<Settings>)[]){
|
|
126
|
-
if (typeof settings[key] != "undefined") newSettings[key] = settings[key]
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return new ODProgressBarRenderer(this.id,this.renderFunction,newSettings)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**## ODProgressBar `class`
|
|
134
|
-
* This is an Open Discord console progress bar.
|
|
135
|
-
*
|
|
136
|
-
* It is used to create a simple or advanced progress bar in the console of the bot.
|
|
137
|
-
* These progress bars are not visible in the `debug.txt` file and should only be used as extra visuals.
|
|
138
|
-
*
|
|
139
|
-
* Use other classes as existing templates or create your own progress bar from scratch using this class.
|
|
140
|
-
*/
|
|
141
|
-
export abstract class ODProgressBar extends ODManagerData {
|
|
142
|
-
/**The renderer of this progress bar. */
|
|
143
|
-
renderer: ODProgressBarRenderer<{}>
|
|
144
|
-
/**Is this progress bar currently active? */
|
|
145
|
-
protected active: boolean = false
|
|
146
|
-
/**A list of listeners when the progress bar stops. */
|
|
147
|
-
protected stopListeners: Function[] = []
|
|
148
|
-
/**The current value of the progress bar. */
|
|
149
|
-
protected value: number
|
|
150
|
-
/**The minimum value of the progress bar. */
|
|
151
|
-
min: number
|
|
152
|
-
/**The maximum value of the progress bar. */
|
|
153
|
-
max: number
|
|
154
|
-
/**The initial value of the progress bar. */
|
|
155
|
-
initialValue: number
|
|
156
|
-
/**The prefix displayed in the progress bar. */
|
|
157
|
-
prefix:string|null
|
|
158
|
-
/**The prefix displayed in the progress bar. */
|
|
159
|
-
suffix:string|null
|
|
160
|
-
|
|
161
|
-
/**Enable automatic stopping when reaching `min` or `max`. */
|
|
162
|
-
autoStop: null|"min"|"max"
|
|
163
|
-
|
|
164
|
-
constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,min:number,max:number,value:number,autoStop:null|"min"|"max",prefix:string|null,suffix:string|null){
|
|
165
|
-
super(id)
|
|
166
|
-
this.renderer = renderer
|
|
167
|
-
this.min = min
|
|
168
|
-
this.max = max
|
|
169
|
-
this.initialValue = this.parseValue(value)
|
|
170
|
-
this.value = this.parseValue(value)
|
|
171
|
-
this.autoStop = autoStop
|
|
172
|
-
this.prefix = prefix
|
|
173
|
-
this.suffix = suffix
|
|
174
|
-
}
|
|
175
|
-
/**Parse a value in such a way that it doesn't go below/above the min/max limits. */
|
|
176
|
-
private parseValue(value:number){
|
|
177
|
-
if (value > this.max) return this.max
|
|
178
|
-
else if (value < this.min) return this.min
|
|
179
|
-
else return value
|
|
180
|
-
}
|
|
181
|
-
/**Render progress bar to the console. */
|
|
182
|
-
private renderStdout(){
|
|
183
|
-
if (!this.active) return
|
|
184
|
-
readline.clearLine(process.stdout,0)
|
|
185
|
-
readline.cursorTo(process.stdout,0)
|
|
186
|
-
process.stdout.write(this.renderer.render(this.min,this.max,this.value,this.prefix,this.suffix))
|
|
187
|
-
}
|
|
188
|
-
/**Start showing this progress bar in the console. */
|
|
189
|
-
start(): boolean {
|
|
190
|
-
if (this.active) return false
|
|
191
|
-
this.value = this.parseValue(this.initialValue)
|
|
192
|
-
this.active = true
|
|
193
|
-
this.renderStdout()
|
|
194
|
-
return true
|
|
195
|
-
}
|
|
196
|
-
/**Update this progress bar while active. (will automatically update the progress bar in the console) */
|
|
197
|
-
protected update(value:number,stop?:boolean): boolean {
|
|
198
|
-
if (!this.active) return false
|
|
199
|
-
this.value = this.parseValue(value)
|
|
200
|
-
this.renderStdout()
|
|
201
|
-
if (stop || (this.autoStop == "max" && this.value == this.max) || (this.autoStop == "min" && this.value == this.min)){
|
|
202
|
-
process.stdout.write("\n")
|
|
203
|
-
this.active = false
|
|
204
|
-
this.stopListeners.forEach((cb) => cb())
|
|
205
|
-
this.stopListeners = []
|
|
206
|
-
}
|
|
207
|
-
return true
|
|
208
|
-
}
|
|
209
|
-
/**Wait for the progress bar to finish. */
|
|
210
|
-
finished(): Promise<void> {
|
|
211
|
-
return new Promise((resolve) => {
|
|
212
|
-
this.stopListeners.push(resolve)
|
|
213
|
-
})
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**## ODTimedProgressBar `class`
|
|
218
|
-
* This is an Open Discord timed console progress bar.
|
|
219
|
-
*
|
|
220
|
-
* It is used to create a simple timed progress bar in the console.
|
|
221
|
-
* You can set a fixed duration (milliseconds) in the constructor.
|
|
222
|
-
*/
|
|
223
|
-
export class ODTimedProgressBar extends ODProgressBar {
|
|
224
|
-
/**The time in milliseconds. */
|
|
225
|
-
time: number
|
|
226
|
-
/**The mode of the timer. */
|
|
227
|
-
mode: "increasing"|"decreasing"
|
|
228
|
-
|
|
229
|
-
constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,time:number,mode:"increasing"|"decreasing",prefix:string|null,suffix:string|null){
|
|
230
|
-
super(id,renderer,0,time,0,(mode == "increasing") ? "max" : "min",prefix,suffix)
|
|
231
|
-
this.time = time
|
|
232
|
-
this.mode = mode
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**The timer which is used. */
|
|
236
|
-
private async timer(ms:number): Promise<void> {
|
|
237
|
-
return new Promise((resolve) => {
|
|
238
|
-
setTimeout(() => {
|
|
239
|
-
resolve()
|
|
240
|
-
},ms)
|
|
241
|
-
})
|
|
242
|
-
}
|
|
243
|
-
/**Run the timed progress bar. */
|
|
244
|
-
private async execute(){
|
|
245
|
-
let i = 0
|
|
246
|
-
const fragment = this.time/100
|
|
247
|
-
while (i < 100){
|
|
248
|
-
await this.timer(fragment)
|
|
249
|
-
i++
|
|
250
|
-
super.update((this.mode == "increasing") ? (i*fragment) : this.time-(i*fragment))
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
start(){
|
|
254
|
-
const res = super.start()
|
|
255
|
-
if (!res) return false
|
|
256
|
-
this.execute()
|
|
257
|
-
return true
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**## ODManualProgressBar `class`
|
|
262
|
-
* This is an Open Discord manual console progress bar.
|
|
263
|
-
*
|
|
264
|
-
* It is used to create a simple manual progress bar in the console.
|
|
265
|
-
* You can update the progress manually using `update()`.
|
|
266
|
-
*/
|
|
267
|
-
export class ODManualProgressBar extends ODProgressBar {
|
|
268
|
-
constructor(id:ODValidId,renderer:ODProgressBarRenderer<{}>,amount:number,autoStop:null|"min"|"max",prefix:string|null,suffix:string|null){
|
|
269
|
-
super(id,renderer,0,amount,0,autoStop,prefix,suffix)
|
|
270
|
-
}
|
|
271
|
-
/**Set the value of the progress bar. */
|
|
272
|
-
set(value:number,stop?:boolean){
|
|
273
|
-
super.update(value,stop)
|
|
274
|
-
}
|
|
275
|
-
/**Get the current value of the progress bar. */
|
|
276
|
-
get(){
|
|
277
|
-
return this.value
|
|
278
|
-
}
|
|
279
|
-
/**Increase the value of the progress bar. */
|
|
280
|
-
increase(amount:number,stop?:boolean){
|
|
281
|
-
super.update(this.value+amount,stop)
|
|
282
|
-
}
|
|
283
|
-
/**Decrease the value of the progress bar. */
|
|
284
|
-
decrease(amount:number,stop?:boolean){
|
|
285
|
-
super.update(this.value-amount,stop)
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**## ODDefaultProgressBarRendererLabel `type`
|
|
290
|
-
* All available label types for the default progress bar renderer
|
|
291
|
-
*/
|
|
292
|
-
export type ODDefaultProgressBarRendererLabel = "value"|"percentage"|"fraction"|"time-ms"|"time-sec"|"time-min"
|
|
293
|
-
|
|
294
|
-
/**## ODDefaultProgressBarRendererSettings `interface`
|
|
295
|
-
* All settings for the default progress bar renderer.
|
|
296
|
-
*/
|
|
297
|
-
export interface ODDefaultProgressBarRendererSettings {
|
|
298
|
-
/**The color of the progress bar border. */
|
|
299
|
-
borderColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
300
|
-
/**The color of the progress bar (filled side). */
|
|
301
|
-
filledBarColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
302
|
-
/**The color of the progress bar (empty side). */
|
|
303
|
-
emptyBarColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
304
|
-
/**The color of the text before the progress bar. */
|
|
305
|
-
prefixColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
306
|
-
/**The color of the text after the progress bar. */
|
|
307
|
-
suffixColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
308
|
-
/**The color of the progress bar label. */
|
|
309
|
-
labelColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
310
|
-
|
|
311
|
-
/**The character used in the left border. */
|
|
312
|
-
leftBorderChar:string,
|
|
313
|
-
/**The character used in the right border. */
|
|
314
|
-
rightBorderChar:string,
|
|
315
|
-
/**The character used in the filled side of the progress bar. */
|
|
316
|
-
filledBarChar:string,
|
|
317
|
-
/**The character used in the empty side of the progress bar. */
|
|
318
|
-
emptyBarChar:string,
|
|
319
|
-
/**The label type. (will show a number related to the progress) */
|
|
320
|
-
labelType:ODDefaultProgressBarRendererLabel,
|
|
321
|
-
/**The position of the label. */
|
|
322
|
-
labelPosition:"start"|"end",
|
|
323
|
-
/**The width of the bar. (50 characters by default) */
|
|
324
|
-
barWidth:number,
|
|
325
|
-
|
|
326
|
-
/**Show the bar. */
|
|
327
|
-
showBar:boolean,
|
|
328
|
-
/**Show the label. */
|
|
329
|
-
showLabel:boolean,
|
|
330
|
-
/**Show the border. */
|
|
331
|
-
showBorder:boolean,
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaultProgressBarRendererSettings> {
|
|
335
|
-
constructor(id:ODValidId,settings:ODDefaultProgressBarRendererSettings){
|
|
336
|
-
super(id,(settings,min,max,value,rawPrefix,rawSuffix) => {
|
|
337
|
-
const percentage = (value-min)/(max-min)
|
|
338
|
-
const barLevel = Math.round(percentage*settings.barWidth)
|
|
339
|
-
|
|
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
|
-
|
|
347
|
-
const leftBorder = (settings.showBorder) ? borderAnsis(settings.leftBorderChar) : ""
|
|
348
|
-
const rightBorder = (settings.showBorder) ? borderAnsis(settings.rightBorderChar) : ""
|
|
349
|
-
const bar = (settings.showBar) ? filledBarAnsis(settings.filledBarChar.repeat(barLevel))+emptyBarAnsis(settings.emptyBarChar.repeat(settings.barWidth-barLevel)) : ""
|
|
350
|
-
const prefix = (rawPrefix) ? prefixAnsis(rawPrefix)+" " : ""
|
|
351
|
-
const suffix = (rawSuffix) ? " "+suffixAnsis(rawSuffix) : ""
|
|
352
|
-
let label: string
|
|
353
|
-
if (!settings.showLabel) label = ""
|
|
354
|
-
if (settings.labelType == "fraction") label = labelAnsis(value+"/"+max)
|
|
355
|
-
else if (settings.labelType == "percentage") label = labelAnsis(Math.round(percentage*100)+"%")
|
|
356
|
-
else if (settings.labelType == "time-ms") label = labelAnsis(value+"ms")
|
|
357
|
-
else if (settings.labelType == "time-sec") label = labelAnsis(Math.round(value*10)/10+"sec")
|
|
358
|
-
else if (settings.labelType == "time-min") label = labelAnsis(Math.round(value*10)/10+"min")
|
|
359
|
-
else label = labelAnsis(value.toString())
|
|
360
|
-
|
|
361
|
-
const labelWithPrefixAndSuffix = prefix+label+suffix
|
|
362
|
-
return (settings.labelPosition == "start") ? labelWithPrefixAndSuffix+" "+leftBorder+bar+rightBorder : leftBorder+bar+rightBorder+" "+labelWithPrefixAndSuffix
|
|
363
|
-
},settings)
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**Switch between Ansis functions based on the specified color. */
|
|
367
|
-
private switchColorAnsis(c:ODValidConsoleColor|"openticket"|"openmoderation"){
|
|
368
|
-
return (c === "openticket") ? ansis.hex("#f8ba00") : (c === "openmoderation") ? ansis.hex("#1690ff") : ansis[c]
|
|
369
|
-
}
|
|
370
|
-
}
|