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