@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.
@@ -1,30 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ODDynamicStat = exports.ODBasicStat = exports.ODStat = exports.ODStatGlobalScope = exports.ODStatScope = exports.ODStatsManager = void 0;
3
+ exports.ODDynamicStatistic = exports.ODBaseStatistic = exports.ODStatistic = exports.ODStatisticGlobalScope = exports.ODStatisticScope = exports.ODStatisticManager = void 0;
4
4
  ///////////////////////////////////////
5
- //STAT MODULE
5
+ //STATISTIC MODULE
6
6
  ///////////////////////////////////////
7
7
  const base_1 = require("./base");
8
- /**## ODStatsManager `class`
9
- * This is an Open Discord stats manager.
8
+ /**## ODStatisticManager `class`
9
+ * This is an Open Discord statistics manager.
10
10
  *
11
- * This class is responsible for managing all stats of the bot.
12
- * Stats are categorized in "scopes" which can be accessed in this manager.
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
- * Stats can be accessed in the individual scopes.
14
+ * Statistic can be accessed in the individual scopes.
15
15
  */
16
- class ODStatsManager extends base_1.ODManager {
16
+ class ODStatisticManager extends base_1.ODManager {
17
17
  /**Alias to Open Discord debugger. */
18
18
  #debug;
19
- /**Alias to Open Discord stats database. */
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, "stat scope");
24
+ super(debug, "statistic scope");
25
25
  this.#debug = debug;
26
26
  }
27
- /**Select the database to use to read/write all stats from/to. */
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 stats and run `onInit()` listeners. */
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 stats scopes due to missing database!");
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 stats
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 stats
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 stats. (clears the entire database) */
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 stats are initialized. This can be used to clear stats from users that left the server or tickets which don't exist anymore. */
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.ODStatsManager = ODStatsManager;
90
- /**## ODStatScope `class`
91
- * This is an Open Discord stat scope.
89
+ exports.ODStatisticManager = ODStatisticManager;
90
+ /**## ODStatisticScope `class`
91
+ * This is an Open Discord statistic scope.
92
92
  *
93
- * A scope can contain multiple stats. Every scope is seperated from other scopes.
94
- * Here, you can read & write the values of all stats.
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 ODStatScope extends base_1.ODManager {
98
+ class ODStatisticScope extends base_1.ODManager {
99
99
  /**The id of this statistics scope. */
100
100
  id;
101
- /**Is this stat scope already initialized? */
101
+ /**Is this scope already initialized? */
102
102
  ready = false;
103
- /**Alias to Open Discord stats database. */
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 stats from/to. (Automatically assigned when used in `ODStatsManager`) */
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 stats to default value & return
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 stat scope & return a list of all statistic ids in the following format: `<scopeid>_<statid>` */
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 stats categories
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 stats in this scope for usage in a discord message/embed. */
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 ODDynamicStat) {
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.ODStatScope = ODStatScope;
226
- /**## ODStatGlobalScope `class`
227
- * This is an Open Discord stat global scope.
225
+ exports.ODStatisticScope = ODStatisticScope;
226
+ /**## ODStatisticGlobalScope `class`
227
+ * This is an Open Discord statistic global scope.
228
228
  *
229
- * A scope can contain multiple stats. Every scope is seperated from other scopes.
230
- * Here, you can read & write the values of all stats.
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 stats of Open Discord.
232
+ * This scope is made specifically for the global statistics of Open Discord.
233
233
  */
234
- class ODStatGlobalScope extends ODStatScope {
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.ODStatGlobalScope = ODStatGlobalScope;
252
- /**## ODStat `class`
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 stats scope to register a new statistic. A statistic can also include a priority to choose the render priority.
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 `ODBasicStat` & `ODDynamicStat` classes instead of this one!
258
+ * It's recommended to use the `ODBaseStatistic` & `ODDynamicStatistic` classes instead of this one!
259
259
  */
260
- class ODStat extends base_1.ODManagerData {
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.ODStat = ODStat;
275
- /**## ODBasicStat `class`
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 stats scope.
279
+ * Use it to create a simple statistic for any statistics scope.
280
280
  */
281
- class ODBasicStat extends ODStat {
282
- /**The name of this stat. Rendered in discord embeds/messages. */
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.ODBasicStat = ODBasicStat;
292
- /**## ODDynamicStat `class`
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 ODDynamicStat extends ODStat {
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.ODDynamicStat = ODDynamicStat;
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.3",
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/stat"
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, ODVersionManagerIdConstraint } from "./modules/base"
3
- import { ODConsoleManager, ODConsoleMessage, ODConsoleMessageParam, ODConsoleMessageTypes, ODDebugFileManager, ODDebugger, ODError, ODLiveStatusManager, ODLiveStatusManagerIdConstraint } from "./modules/console"
4
- import { ODCheckerFunctionManagerIdConstraint, ODCheckerManager, ODCheckerManagerIdConstraint, ODCheckerRenderer } from "./modules/checker"
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, ODConfigManagerIdConstraint } from "./modules/config"
10
- import { ODDatabaseManager, ODDatabaseManagerIdConstraint } from "./modules/database"
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, ODButtonManagerIdConstraint, ODDropdownManagerIdConstraint, ODEmbedManagerIdConstraint, ODFileManagerIdConstraint, ODMessageManagerIdConstraint, ODModalManagerIdConstraint } from "./modules/builder"
13
+ import { ODBuilderManager } from "./modules/builder"
14
14
  import { ODResponderManager } from "./modules/responder"
15
- import { ODActionManager, ODActionManagerIdConstraint } from "./modules/action"
15
+ import { ODActionManager } from "./modules/action"
16
16
  import { ODVerifyBarManager } from "./modules/verifybar"
17
17
  import { ODPermissionManager } from "./modules/permission"
18
- import { ODCooldownManager, ODCooldownManagerIdConstraint } from "./modules/cooldown"
18
+ import { ODCooldownManager } from "./modules/cooldown"
19
19
  import { ODHelpMenuManager } from "./modules/helpmenu"
20
- import { ODStatsManager } from "./modules/stat"
21
- import { ODCodeManager, ODCodeManagerIdConstraint } from "./modules/code"
20
+ import { ODStatisticManager } from "./modules/statistic"
21
+ import { ODCodeManager } from "./modules/code"
22
22
  import { ODPostManager } from "./modules/post"
23
- import { ODClientManager, ODContextMenuManagerIdConstraint, ODSlashCommandManagerIdConstraint, ODTextCommandManagerIdConstraint } from "./modules/client"
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
- stats: ODStatsManager
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 stats: ODStatsManager
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.stats = managers.stats
170
+ this.statistics = managers.statistics
171
171
  this.code = managers.code
172
172
  this.posts = managers.posts
173
173
 
@@ -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, stats & used options)
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 stats/header of the debug file (containing the version) */
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 stats/header to the debug file on startup */
362
+ /**Write the statistics/header to the debug file on startup */
363
363
  #writeStartupStats(){
364
364
  const currenttext = this.#readDebugFile()
365
365
  if (currenttext){
@@ -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 stat scopes. */
216
- statScopesLoading:boolean,
217
- /**Load the default Open Discord stats. */
218
- statLoading:boolean,
219
- /**Initiate the default Open Discord stats. */
220
- statInitiating:boolean,
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
- statScopesLoading:true,
333
- statLoading:true,
334
- statInitiating:true,
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
  }