@open-discord-bots/framework 0.2.3 → 0.2.5
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/README.md +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/main.d.ts +3 -3
- package/dist/api/main.js +2 -2
- package/dist/api/modules/code.d.ts +1 -1
- package/dist/api/modules/code.js +1 -1
- package/dist/api/modules/console.js +2 -2
- package/dist/api/modules/fuse.d.ts +6 -6
- package/dist/api/modules/fuse.js +3 -3
- package/dist/api/modules/progressbar.d.ts +46 -1
- package/dist/api/modules/progressbar.js +43 -1
- package/dist/api/modules/statistic.d.ts +176 -0
- package/dist/api/modules/{stat.js → statistic.js} +52 -52
- package/package.json +1 -1
- package/src/api/index.ts +1 -1
- package/src/api/main.ts +14 -14
- package/src/api/modules/code.ts +1 -1
- package/src/api/modules/console.ts +2 -2
- package/src/api/modules/fuse.ts +9 -9
- package/src/api/modules/progressbar.ts +85 -1
- package/src/api/modules/{stat.ts → statistic.ts} +114 -114
- package/dist/api/modules/stat.d.ts +0 -176
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ODDynamicStatistic = exports.ODBaseStatistic = exports.ODStatistic = exports.ODStatisticGlobalScope = exports.ODStatisticScope = exports.ODStatisticManager = void 0;
|
|
4
4
|
///////////////////////////////////////
|
|
5
|
-
//
|
|
5
|
+
//STATISTIC MODULE
|
|
6
6
|
///////////////////////////////////////
|
|
7
7
|
const base_1 = require("./base");
|
|
8
|
-
/**##
|
|
9
|
-
* This is an Open Discord
|
|
8
|
+
/**## ODStatisticManager `class`
|
|
9
|
+
* This is an Open Discord statistics manager.
|
|
10
10
|
*
|
|
11
|
-
* This class is responsible for managing all
|
|
12
|
-
*
|
|
11
|
+
* This class is responsible for managing all statistics of the bot.
|
|
12
|
+
* Statistic are categorized in "scopes" which can be accessed in this manager.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* Statistic can be accessed in the individual scopes.
|
|
15
15
|
*/
|
|
16
|
-
class
|
|
16
|
+
class ODStatisticManager extends base_1.ODManager {
|
|
17
17
|
/**Alias to Open Discord debugger. */
|
|
18
18
|
#debug;
|
|
19
|
-
/**Alias to Open Discord
|
|
19
|
+
/**Alias to Open Discord statistics database. */
|
|
20
20
|
database = null;
|
|
21
21
|
/**All the listeners for the init event. */
|
|
22
22
|
#initListeners = [];
|
|
23
23
|
constructor(debug) {
|
|
24
|
-
super(debug, "
|
|
24
|
+
super(debug, "statistic scope");
|
|
25
25
|
this.#debug = debug;
|
|
26
26
|
}
|
|
27
|
-
/**Select the database to use to read/write all
|
|
27
|
+
/**Select the database to use to read/write all statistics from/to. */
|
|
28
28
|
useDatabase(database) {
|
|
29
29
|
this.database = database;
|
|
30
30
|
}
|
|
@@ -34,16 +34,16 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
34
34
|
data.useDatabase(this.database);
|
|
35
35
|
return super.add(data, overwrite);
|
|
36
36
|
}
|
|
37
|
-
/**Init all
|
|
37
|
+
/**Init all statistics and run `onInit()` listeners. */
|
|
38
38
|
async init() {
|
|
39
39
|
if (!this.database)
|
|
40
|
-
throw new base_1.ODSystemError("Unable to initialize
|
|
40
|
+
throw new base_1.ODSystemError("Unable to initialize statistics scopes due to missing database!");
|
|
41
41
|
//get all valid categories
|
|
42
42
|
const validCategories = [];
|
|
43
43
|
for (const scope of this.getAll()) {
|
|
44
44
|
validCategories.push(...scope.init());
|
|
45
45
|
}
|
|
46
|
-
//filter out the deletable
|
|
46
|
+
//filter out the deletable statistics
|
|
47
47
|
const deletableStats = [];
|
|
48
48
|
const data = await this.database.getAll();
|
|
49
49
|
data.forEach((data) => {
|
|
@@ -54,14 +54,14 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
54
54
|
for (const cb of this.#initListeners) {
|
|
55
55
|
await cb(data, deletableStats);
|
|
56
56
|
}
|
|
57
|
-
//delete all deletable
|
|
57
|
+
//delete all deletable statistics
|
|
58
58
|
for (const data of deletableStats) {
|
|
59
59
|
if (!this.database)
|
|
60
60
|
return;
|
|
61
61
|
await this.database.delete(data.category, data.key);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
/**Reset all
|
|
64
|
+
/**Reset all statistics. (clears the entire database) */
|
|
65
65
|
async reset() {
|
|
66
66
|
if (!this.database)
|
|
67
67
|
return;
|
|
@@ -72,7 +72,7 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
72
72
|
await this.database.delete(d.category, d.key);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
/**Run a function when the
|
|
75
|
+
/**Run a function when the statistics are initialized. This can be used to clear statistics from users that left the server or tickets which don't exist anymore. */
|
|
76
76
|
onInit(callback) {
|
|
77
77
|
this.#initListeners.push(callback);
|
|
78
78
|
}
|
|
@@ -86,21 +86,21 @@ class ODStatsManager extends base_1.ODManager {
|
|
|
86
86
|
return super.exists(id);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
exports.
|
|
90
|
-
/**##
|
|
91
|
-
* This is an Open Discord
|
|
89
|
+
exports.ODStatisticManager = ODStatisticManager;
|
|
90
|
+
/**## ODStatisticScope `class`
|
|
91
|
+
* This is an Open Discord statistic scope.
|
|
92
92
|
*
|
|
93
|
-
* A scope can contain multiple
|
|
94
|
-
* Here, you can read & write the values of all
|
|
93
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
94
|
+
* Here, you can read & write the values of all statistics.
|
|
95
95
|
*
|
|
96
96
|
* The built-in Open Discord scopes are: `global`, `user`, `ticket`
|
|
97
97
|
*/
|
|
98
|
-
class
|
|
98
|
+
class ODStatisticScope extends base_1.ODManager {
|
|
99
99
|
/**The id of this statistics scope. */
|
|
100
100
|
id;
|
|
101
|
-
/**Is this
|
|
101
|
+
/**Is this scope already initialized? */
|
|
102
102
|
ready = false;
|
|
103
|
-
/**Alias to Open Discord
|
|
103
|
+
/**Alias to Open Discord statistics database. */
|
|
104
104
|
database = null;
|
|
105
105
|
/**The name of this scope (used in embed title) */
|
|
106
106
|
name;
|
|
@@ -109,7 +109,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
109
109
|
this.id = new base_1.ODId(id);
|
|
110
110
|
this.name = name;
|
|
111
111
|
}
|
|
112
|
-
/**Select the database to use to read/write all
|
|
112
|
+
/**Select the database to use to read/write all statistics from/to. (Automatically assigned when used in `ODStatisticManager`) */
|
|
113
113
|
useDatabase(database) {
|
|
114
114
|
this.database = database;
|
|
115
115
|
}
|
|
@@ -119,7 +119,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
119
119
|
const newId = new base_1.ODId(id);
|
|
120
120
|
const data = await this.database.get(this.id.value + "_" + newId.value, scopeId);
|
|
121
121
|
if (typeof data == "undefined") {
|
|
122
|
-
//set
|
|
122
|
+
//set statistics to default value & return
|
|
123
123
|
return this.resetStat(id, scopeId);
|
|
124
124
|
}
|
|
125
125
|
else if (typeof data == "string" || typeof data == "boolean" || typeof data == "number") {
|
|
@@ -179,13 +179,13 @@ class ODStatScope extends base_1.ODManager {
|
|
|
179
179
|
await this.database.set(this.id.value + "_" + stat.id.value, scopeId, stat.value);
|
|
180
180
|
return stat.value;
|
|
181
181
|
}
|
|
182
|
-
/**Initialize this
|
|
182
|
+
/**Initialize this statistic scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
|
|
183
183
|
init() {
|
|
184
|
-
//get all valid
|
|
184
|
+
//get all valid statistics categories
|
|
185
185
|
this.ready = true;
|
|
186
186
|
return this.getAll().map((stat) => this.id.value + "_" + stat.id.value);
|
|
187
187
|
}
|
|
188
|
-
/**Render all
|
|
188
|
+
/**Render all statistics in this scope for usage in a discord message/embed. */
|
|
189
189
|
async render(scopeId, guild, channel, user) {
|
|
190
190
|
//sort from high priority to low
|
|
191
191
|
const derefArray = [...this.getAll()];
|
|
@@ -195,7 +195,7 @@ class ODStatScope extends base_1.ODManager {
|
|
|
195
195
|
const result = [];
|
|
196
196
|
for (const stat of derefArray) {
|
|
197
197
|
try {
|
|
198
|
-
if (stat instanceof
|
|
198
|
+
if (stat instanceof ODDynamicStatistic) {
|
|
199
199
|
//dynamic render (without value)
|
|
200
200
|
result.push(await stat.render("", scopeId, guild, channel, user));
|
|
201
201
|
}
|
|
@@ -222,16 +222,16 @@ class ODStatScope extends base_1.ODManager {
|
|
|
222
222
|
return super.exists(id);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
exports.
|
|
226
|
-
/**##
|
|
227
|
-
* This is an Open Discord
|
|
225
|
+
exports.ODStatisticScope = ODStatisticScope;
|
|
226
|
+
/**## ODStatisticGlobalScope `class`
|
|
227
|
+
* This is an Open Discord statistic global scope.
|
|
228
228
|
*
|
|
229
|
-
* A scope can contain multiple
|
|
230
|
-
* Here, you can read & write the values of all
|
|
229
|
+
* A scope can contain multiple statistics. Every scope is seperated from other scopes.
|
|
230
|
+
* Here, you can read & write the values of all statistics.
|
|
231
231
|
*
|
|
232
|
-
* This scope is made specifically for the global
|
|
232
|
+
* This scope is made specifically for the global statistics of Open Discord.
|
|
233
233
|
*/
|
|
234
|
-
class
|
|
234
|
+
class ODStatisticGlobalScope extends ODStatisticScope {
|
|
235
235
|
getStat(id) {
|
|
236
236
|
return super.getStat(id, "GLOBAL");
|
|
237
237
|
}
|
|
@@ -248,16 +248,16 @@ class ODStatGlobalScope extends ODStatScope {
|
|
|
248
248
|
return super.render("GLOBAL", guild, channel, user);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
exports.
|
|
252
|
-
/**##
|
|
251
|
+
exports.ODStatisticGlobalScope = ODStatisticGlobalScope;
|
|
252
|
+
/**## ODStatistic `class`
|
|
253
253
|
* This is an Open Discord statistic.
|
|
254
254
|
*
|
|
255
255
|
* This single statistic doesn't do anything except defining the rules of this statistic.
|
|
256
|
-
* Use it in a
|
|
256
|
+
* Use it in a statistics scope to register a new statistic. A statistic can also include a priority to choose the render priority.
|
|
257
257
|
*
|
|
258
|
-
* It's recommended to use the `
|
|
258
|
+
* It's recommended to use the `ODBaseStatistic` & `ODDynamicStatistic` classes instead of this one!
|
|
259
259
|
*/
|
|
260
|
-
class
|
|
260
|
+
class ODStatistic extends base_1.ODManagerData {
|
|
261
261
|
/**The priority of this statistic. */
|
|
262
262
|
priority;
|
|
263
263
|
/**The render function of this statistic. */
|
|
@@ -271,15 +271,15 @@ class ODStat extends base_1.ODManagerData {
|
|
|
271
271
|
this.value = value ?? null;
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
exports.
|
|
275
|
-
/**##
|
|
274
|
+
exports.ODStatistic = ODStatistic;
|
|
275
|
+
/**## ODBaseStatistic `class`
|
|
276
276
|
* This is an Open Discord basic statistic.
|
|
277
277
|
*
|
|
278
278
|
* This single statistic will store a number, boolean or string in the database.
|
|
279
|
-
* Use it to create a simple statistic for any
|
|
279
|
+
* Use it to create a simple statistic for any statistics scope.
|
|
280
280
|
*/
|
|
281
|
-
class
|
|
282
|
-
/**The name of this
|
|
281
|
+
class ODBaseStatistic extends ODStatistic {
|
|
282
|
+
/**The name of this statistic. Rendered in discord embeds/messages. */
|
|
283
283
|
name;
|
|
284
284
|
constructor(id, priority, name, value) {
|
|
285
285
|
super(id, priority, (value) => {
|
|
@@ -288,8 +288,8 @@ class ODBasicStat extends ODStat {
|
|
|
288
288
|
this.name = name;
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
exports.
|
|
292
|
-
/**##
|
|
291
|
+
exports.ODBaseStatistic = ODBaseStatistic;
|
|
292
|
+
/**## ODDynamicStatistic `class`
|
|
293
293
|
* This is an Open Discord dynamic statistic.
|
|
294
294
|
*
|
|
295
295
|
* A dynamic statistic does not store anything in the database! Instead, it will execute a function to return a custom result.
|
|
@@ -297,11 +297,11 @@ exports.ODBasicStat = ODBasicStat;
|
|
|
297
297
|
*
|
|
298
298
|
* This is used in Open Discord for the live ticket status, participants & system status.
|
|
299
299
|
*/
|
|
300
|
-
class
|
|
300
|
+
class ODDynamicStatistic extends ODStatistic {
|
|
301
301
|
constructor(id, priority, render) {
|
|
302
302
|
super(id, priority, (value, scopeId, guild, channel, user) => {
|
|
303
303
|
return render(scopeId, guild, channel, user);
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
|
-
exports.
|
|
307
|
+
exports.ODDynamicStatistic = ODDynamicStatistic;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-discord-bots/framework",
|
|
3
3
|
"author": "DJj123dj",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"description": "The core framework of the popular open-source discord bots: Open Ticket & Open Moderation.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
package/src/api/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export * from "./modules/action"
|
|
|
20
20
|
export * from "./modules/permission"
|
|
21
21
|
export * from "./modules/helpmenu"
|
|
22
22
|
export * from "./modules/session"
|
|
23
|
-
export * from "./modules/
|
|
23
|
+
export * from "./modules/statistic"
|
|
24
24
|
export * from "./modules/code"
|
|
25
25
|
export * from "./modules/cooldown"
|
|
26
26
|
export * from "./modules/post"
|
package/src/api/main.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
//BASE MODULES
|
|
2
|
-
import { ODEnvHelper, ODProjectType, ODVersion, ODVersionManager
|
|
3
|
-
import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager
|
|
4
|
-
import {
|
|
2
|
+
import { ODEnvHelper, ODProjectType, ODVersion, ODVersionManager } from "./modules/base"
|
|
3
|
+
import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager } from "./modules/console"
|
|
4
|
+
import { ODCheckerManager } from "./modules/checker"
|
|
5
5
|
import { ODEventManager } from "./modules/event"
|
|
6
6
|
import { ODPluginManager } from "./modules/plugin"
|
|
7
7
|
import { ODFlagManager } from "./modules/flag"
|
|
8
8
|
import { ODProgressBarManager } from "./modules/progressbar"
|
|
9
|
-
import { ODConfigManager
|
|
10
|
-
import { ODDatabaseManager
|
|
9
|
+
import { ODConfigManager } from "./modules/config"
|
|
10
|
+
import { ODDatabaseManager } from "./modules/database"
|
|
11
11
|
import { ODSessionManager } from "./modules/session"
|
|
12
12
|
import { ODLanguageManager } from "./modules/language"
|
|
13
|
-
import { ODBuilderManager
|
|
13
|
+
import { ODBuilderManager } from "./modules/builder"
|
|
14
14
|
import { ODResponderManager } from "./modules/responder"
|
|
15
|
-
import { ODActionManager
|
|
15
|
+
import { ODActionManager } from "./modules/action"
|
|
16
16
|
import { ODVerifyBarManager } from "./modules/verifybar"
|
|
17
17
|
import { ODPermissionManager } from "./modules/permission"
|
|
18
|
-
import { ODCooldownManager
|
|
18
|
+
import { ODCooldownManager } from "./modules/cooldown"
|
|
19
19
|
import { ODHelpMenuManager } from "./modules/helpmenu"
|
|
20
|
-
import {
|
|
21
|
-
import { ODCodeManager
|
|
20
|
+
import { ODStatisticManager } from "./modules/statistic"
|
|
21
|
+
import { ODCodeManager } from "./modules/code"
|
|
22
22
|
import { ODPostManager } from "./modules/post"
|
|
23
|
-
import { ODClientManager
|
|
23
|
+
import { ODClientManager } from "./modules/client"
|
|
24
24
|
import { ODSharedFuseManager } from "./modules/fuse"
|
|
25
25
|
import { ODStartScreenManager } from "./modules/startscreen"
|
|
26
26
|
|
|
@@ -77,7 +77,7 @@ export interface ODMainManagers {
|
|
|
77
77
|
/**The manager that manages & renders the Open Discord help menu. (not the embed, but the text) */
|
|
78
78
|
helpmenu: ODHelpMenuManager
|
|
79
79
|
/**The manager that manages, saves & renders the Open Discord statistics. (not the embed, but the text & database) */
|
|
80
|
-
|
|
80
|
+
statistics: ODStatisticManager
|
|
81
81
|
/**This manager is a place where you can put code that executes when the bot almost finishes the setup. (can be used for less important stuff that doesn't require an exact time-order) */
|
|
82
82
|
code: ODCodeManager
|
|
83
83
|
/**The manager that manages all posts (static discord channels) in the bot. (e.g. transcripts, logs, etc) */
|
|
@@ -129,7 +129,7 @@ export class ODMain implements ODMainManagers {
|
|
|
129
129
|
readonly permissions: ODPermissionManager
|
|
130
130
|
readonly cooldowns: ODCooldownManager
|
|
131
131
|
readonly helpmenu: ODHelpMenuManager
|
|
132
|
-
readonly
|
|
132
|
+
readonly statistics: ODStatisticManager
|
|
133
133
|
readonly code: ODCodeManager
|
|
134
134
|
readonly posts: ODPostManager
|
|
135
135
|
|
|
@@ -167,7 +167,7 @@ export class ODMain implements ODMainManagers {
|
|
|
167
167
|
this.permissions = managers.permissions
|
|
168
168
|
this.cooldowns = managers.cooldowns
|
|
169
169
|
this.helpmenu = managers.helpmenu
|
|
170
|
-
this.
|
|
170
|
+
this.statistics = managers.statistics
|
|
171
171
|
this.code = managers.code
|
|
172
172
|
this.posts = managers.posts
|
|
173
173
|
|
package/src/api/modules/code.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { ODDebugger } from "./console"
|
|
|
12
12
|
* You can also specify a priority to change the execution order.
|
|
13
13
|
* In Open Discord, this is used for the following processes:
|
|
14
14
|
* - Autoclose/delete
|
|
15
|
-
* - Database syncronisation (with tickets,
|
|
15
|
+
* - Database syncronisation (with tickets, statistics & used options)
|
|
16
16
|
* - Panel auto-update
|
|
17
17
|
* - Database Garbage Collection (removing tickets that don't exist anymore)
|
|
18
18
|
* - And more!
|
|
@@ -347,7 +347,7 @@ export class ODDebugFileManager {
|
|
|
347
347
|
fs.writeFileSync(this.path,newtext)
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
|
-
/**Generate the
|
|
350
|
+
/**Generate the statistics/header of the debug file (containing the version) */
|
|
351
351
|
#createStatsText(){
|
|
352
352
|
const date = new Date()
|
|
353
353
|
const dstring = `${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`
|
|
@@ -359,7 +359,7 @@ export class ODDebugFileManager {
|
|
|
359
359
|
"=========================\n\n"
|
|
360
360
|
].join("\n")
|
|
361
361
|
}
|
|
362
|
-
/**Write the
|
|
362
|
+
/**Write the statistics/header to the debug file on startup */
|
|
363
363
|
#writeStartupStats(){
|
|
364
364
|
const currenttext = this.#readDebugFile()
|
|
365
365
|
if (currenttext){
|
package/src/api/modules/fuse.ts
CHANGED
|
@@ -212,12 +212,12 @@ export interface ODSharedFuseList {
|
|
|
212
212
|
/**Load the default Open Discord help menu components. */
|
|
213
213
|
helpMenuComponentLoading:boolean,
|
|
214
214
|
|
|
215
|
-
/**Load the default Open Discord
|
|
216
|
-
|
|
217
|
-
/**Load the default Open Discord
|
|
218
|
-
|
|
219
|
-
/**Initiate the default Open Discord
|
|
220
|
-
|
|
215
|
+
/**Load the default Open Discord statistic scopes. */
|
|
216
|
+
statisticScopesLoading:boolean,
|
|
217
|
+
/**Load the default Open Discord statistics. */
|
|
218
|
+
statisticLoading:boolean,
|
|
219
|
+
/**Initiate the default Open Discord statistics. */
|
|
220
|
+
statisticInitiating:boolean,
|
|
221
221
|
|
|
222
222
|
/**Load the default Open Discord code/functions. */
|
|
223
223
|
codeLoading:boolean,
|
|
@@ -329,9 +329,9 @@ export class ODSharedFuseManager extends ODFuseManager<ODSharedFuseList> {
|
|
|
329
329
|
helpMenuCategoryLoading:true,
|
|
330
330
|
helpMenuComponentLoading:true,
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
332
|
+
statisticScopesLoading:true,
|
|
333
|
+
statisticLoading:true,
|
|
334
|
+
statisticInitiating:true,
|
|
335
335
|
|
|
336
336
|
codeLoading:true,
|
|
337
337
|
codeExecution:true,
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
//PROGRESS BAR MODULE
|
|
3
3
|
///////////////////////////////////////
|
|
4
4
|
import { ODSystemError, ODManager, ODManagerData, ODValidId } from "./base"
|
|
5
|
-
import { ODDebugger } from "./console"
|
|
5
|
+
import { ODDebugger, ODValidConsoleColor } from "./console"
|
|
6
6
|
import readline from "readline"
|
|
7
|
+
import ansis from "ansis"
|
|
7
8
|
|
|
8
9
|
/**## ODProgressBarRendererManagerIdConstraint `type`
|
|
9
10
|
* The constraint/layout for id mappings/interfaces of the `ODProgressBarRendererManager` class.
|
|
@@ -282,4 +283,87 @@ export class ODManualProgressBar extends ODProgressBar {
|
|
|
282
283
|
decrease(amount:number,stop?:boolean){
|
|
283
284
|
super.update(this.value-amount,stop)
|
|
284
285
|
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**## ODDefaultProgressBarRendererLabel `type`
|
|
289
|
+
* All available label types for the default progress bar renderer
|
|
290
|
+
*/
|
|
291
|
+
export type ODDefaultProgressBarRendererLabel = "value"|"percentage"|"fraction"|"time-ms"|"time-sec"|"time-min"
|
|
292
|
+
|
|
293
|
+
/**## ODDefaultProgressBarRendererSettings `interface`
|
|
294
|
+
* All settings for the default progress bar renderer.
|
|
295
|
+
*/
|
|
296
|
+
export interface ODDefaultProgressBarRendererSettings {
|
|
297
|
+
/**The color of the progress bar border. */
|
|
298
|
+
borderColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
299
|
+
/**The color of the progress bar (filled side). */
|
|
300
|
+
filledBarColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
301
|
+
/**The color of the progress bar (empty side). */
|
|
302
|
+
emptyBarColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
303
|
+
/**The color of the text before the progress bar. */
|
|
304
|
+
prefixColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
305
|
+
/**The color of the text after the progress bar. */
|
|
306
|
+
suffixColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
307
|
+
/**The color of the progress bar label. */
|
|
308
|
+
labelColor:ODValidConsoleColor|"openticket"|"openmoderation",
|
|
309
|
+
|
|
310
|
+
/**The character used in the left border. */
|
|
311
|
+
leftBorderChar:string,
|
|
312
|
+
/**The character used in the right border. */
|
|
313
|
+
rightBorderChar:string,
|
|
314
|
+
/**The character used in the filled side of the progress bar. */
|
|
315
|
+
filledBarChar:string,
|
|
316
|
+
/**The character used in the empty side of the progress bar. */
|
|
317
|
+
emptyBarChar:string,
|
|
318
|
+
/**The label type. (will show a number related to the progress) */
|
|
319
|
+
labelType:ODDefaultProgressBarRendererLabel,
|
|
320
|
+
/**The position of the label. */
|
|
321
|
+
labelPosition:"start"|"end",
|
|
322
|
+
/**The width of the bar. (50 characters by default) */
|
|
323
|
+
barWidth:number,
|
|
324
|
+
|
|
325
|
+
/**Show the bar. */
|
|
326
|
+
showBar:boolean,
|
|
327
|
+
/**Show the label. */
|
|
328
|
+
showLabel:boolean,
|
|
329
|
+
/**Show the border. */
|
|
330
|
+
showBorder:boolean,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaultProgressBarRendererSettings> {
|
|
334
|
+
constructor(id:ODValidId,settings:ODDefaultProgressBarRendererSettings){
|
|
335
|
+
super(id,(settings,min,max,value,rawPrefix,rawSuffix) => {
|
|
336
|
+
const percentage = (value-min)/(max-min)
|
|
337
|
+
const barLevel = Math.round(percentage*settings.barWidth)
|
|
338
|
+
|
|
339
|
+
const borderAnsis = this.#switchColorAnsis(settings.borderColor)
|
|
340
|
+
const filledBarAnsis = this.#switchColorAnsis(settings.filledBarColor)
|
|
341
|
+
const emptyBarAnsis = this.#switchColorAnsis(settings.emptyBarColor)
|
|
342
|
+
const labelAnsis = this.#switchColorAnsis(settings.labelColor)
|
|
343
|
+
const prefixAnsis = this.#switchColorAnsis(settings.prefixColor)
|
|
344
|
+
const suffixAnsis = this.#switchColorAnsis(settings.suffixColor)
|
|
345
|
+
|
|
346
|
+
const leftBorder = (settings.showBorder) ? borderAnsis(settings.leftBorderChar) : ""
|
|
347
|
+
const rightBorder = (settings.showBorder) ? borderAnsis(settings.rightBorderChar) : ""
|
|
348
|
+
const bar = (settings.showBar) ? filledBarAnsis(settings.filledBarChar.repeat(barLevel))+emptyBarAnsis(settings.emptyBarChar.repeat(settings.barWidth-barLevel)) : ""
|
|
349
|
+
const prefix = (rawPrefix) ? prefixAnsis(rawPrefix)+" " : ""
|
|
350
|
+
const suffix = (rawSuffix) ? " "+suffixAnsis(rawSuffix) : ""
|
|
351
|
+
let label: string
|
|
352
|
+
if (!settings.showLabel) label = ""
|
|
353
|
+
if (settings.labelType == "fraction") label = labelAnsis(value+"/"+max)
|
|
354
|
+
else if (settings.labelType == "percentage") label = labelAnsis(Math.round(percentage*100)+"%")
|
|
355
|
+
else if (settings.labelType == "time-ms") label = labelAnsis(value+"ms")
|
|
356
|
+
else if (settings.labelType == "time-sec") label = labelAnsis(Math.round(value*10)/10+"sec")
|
|
357
|
+
else if (settings.labelType == "time-min") label = labelAnsis(Math.round(value*10)/10+"min")
|
|
358
|
+
else label = labelAnsis(value.toString())
|
|
359
|
+
|
|
360
|
+
const labelWithPrefixAndSuffix = prefix+label+suffix
|
|
361
|
+
return (settings.labelPosition == "start") ? labelWithPrefixAndSuffix+" "+leftBorder+bar+rightBorder : leftBorder+bar+rightBorder+" "+labelWithPrefixAndSuffix
|
|
362
|
+
},settings)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**Switch between Ansis functions based on the specified color. */
|
|
366
|
+
#switchColorAnsis(c:ODValidConsoleColor|"openticket"|"openmoderation"){
|
|
367
|
+
return (c === "openticket") ? ansis.hex("#f8ba00") : (c === "openmoderation") ? ansis.hex("#1690ff") : ansis[c]
|
|
368
|
+
}
|
|
285
369
|
}
|