@open-discord-bots/framework 0.2.3 → 0.2.4

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,5 +1,5 @@
1
1
  import { ODManager, ODManagerData, ODValidId } from "./base";
2
- import { ODDebugger } from "./console";
2
+ import { ODDebugger, ODValidConsoleColor } from "./console";
3
3
  /**## ODProgressBarRendererManagerIdConstraint `type`
4
4
  * The constraint/layout for id mappings/interfaces of the `ODProgressBarRendererManager` class.
5
5
  */
@@ -127,3 +127,48 @@ export declare class ODManualProgressBar extends ODProgressBar {
127
127
  /**Decrease the value of the progress bar. */
128
128
  decrease(amount: number, stop?: boolean): void;
129
129
  }
130
+ /**## ODDefaultProgressBarRendererLabel `type`
131
+ * All available label types for the default progress bar renderer
132
+ */
133
+ export type ODDefaultProgressBarRendererLabel = "value" | "percentage" | "fraction" | "time-ms" | "time-sec" | "time-min";
134
+ /**## ODDefaultProgressBarRendererSettings `interface`
135
+ * All settings for the default progress bar renderer.
136
+ */
137
+ export interface ODDefaultProgressBarRendererSettings {
138
+ /**The color of the progress bar border. */
139
+ borderColor: ODValidConsoleColor | "openticket" | "openmoderation";
140
+ /**The color of the progress bar (filled side). */
141
+ filledBarColor: ODValidConsoleColor | "openticket" | "openmoderation";
142
+ /**The color of the progress bar (empty side). */
143
+ emptyBarColor: ODValidConsoleColor | "openticket" | "openmoderation";
144
+ /**The color of the text before the progress bar. */
145
+ prefixColor: ODValidConsoleColor | "openticket" | "openmoderation";
146
+ /**The color of the text after the progress bar. */
147
+ suffixColor: ODValidConsoleColor | "openticket" | "openmoderation";
148
+ /**The color of the progress bar label. */
149
+ labelColor: ODValidConsoleColor | "openticket" | "openmoderation";
150
+ /**The character used in the left border. */
151
+ leftBorderChar: string;
152
+ /**The character used in the right border. */
153
+ rightBorderChar: string;
154
+ /**The character used in the filled side of the progress bar. */
155
+ filledBarChar: string;
156
+ /**The character used in the empty side of the progress bar. */
157
+ emptyBarChar: string;
158
+ /**The label type. (will show a number related to the progress) */
159
+ labelType: ODDefaultProgressBarRendererLabel;
160
+ /**The position of the label. */
161
+ labelPosition: "start" | "end";
162
+ /**The width of the bar. (50 characters by default) */
163
+ barWidth: number;
164
+ /**Show the bar. */
165
+ showBar: boolean;
166
+ /**Show the label. */
167
+ showLabel: boolean;
168
+ /**Show the border. */
169
+ showBorder: boolean;
170
+ }
171
+ export declare class ODDefaultProgressBarRenderer extends ODProgressBarRenderer<ODDefaultProgressBarRendererSettings> {
172
+ #private;
173
+ constructor(id: ODValidId, settings: ODDefaultProgressBarRendererSettings);
174
+ }
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ODManualProgressBar = exports.ODTimedProgressBar = exports.ODProgressBar = exports.ODProgressBarRenderer = exports.ODProgressBarManager = exports.ODProgressBarRendererManager = void 0;
6
+ exports.ODDefaultProgressBarRenderer = exports.ODManualProgressBar = exports.ODTimedProgressBar = exports.ODProgressBar = exports.ODProgressBarRenderer = exports.ODProgressBarManager = exports.ODProgressBarRendererManager = void 0;
7
7
  ///////////////////////////////////////
8
8
  //PROGRESS BAR MODULE
9
9
  ///////////////////////////////////////
10
10
  const base_1 = require("./base");
11
11
  const readline_1 = __importDefault(require("readline"));
12
+ const ansis_1 = __importDefault(require("ansis"));
12
13
  /**## ODProgressBarRendererManager `class`
13
14
  * This is an Open Discord progress bar renderer manager.
14
15
  *
@@ -250,3 +251,44 @@ class ODManualProgressBar extends ODProgressBar {
250
251
  }
251
252
  }
252
253
  exports.ODManualProgressBar = ODManualProgressBar;
254
+ class ODDefaultProgressBarRenderer extends ODProgressBarRenderer {
255
+ constructor(id, settings) {
256
+ super(id, (settings, min, max, value, rawPrefix, rawSuffix) => {
257
+ const percentage = (value - min) / (max - min);
258
+ const barLevel = Math.round(percentage * settings.barWidth);
259
+ const borderAnsis = this.#switchColorAnsis(settings.borderColor);
260
+ const filledBarAnsis = this.#switchColorAnsis(settings.filledBarColor);
261
+ const emptyBarAnsis = this.#switchColorAnsis(settings.emptyBarColor);
262
+ const labelAnsis = this.#switchColorAnsis(settings.labelColor);
263
+ const prefixAnsis = this.#switchColorAnsis(settings.prefixColor);
264
+ const suffixAnsis = this.#switchColorAnsis(settings.suffixColor);
265
+ const leftBorder = (settings.showBorder) ? borderAnsis(settings.leftBorderChar) : "";
266
+ const rightBorder = (settings.showBorder) ? borderAnsis(settings.rightBorderChar) : "";
267
+ const bar = (settings.showBar) ? filledBarAnsis(settings.filledBarChar.repeat(barLevel)) + emptyBarAnsis(settings.emptyBarChar.repeat(settings.barWidth - barLevel)) : "";
268
+ const prefix = (rawPrefix) ? prefixAnsis(rawPrefix) + " " : "";
269
+ const suffix = (rawSuffix) ? " " + suffixAnsis(rawSuffix) : "";
270
+ let label;
271
+ if (!settings.showLabel)
272
+ label = "";
273
+ if (settings.labelType == "fraction")
274
+ label = labelAnsis(value + "/" + max);
275
+ else if (settings.labelType == "percentage")
276
+ label = labelAnsis(Math.round(percentage * 100) + "%");
277
+ else if (settings.labelType == "time-ms")
278
+ label = labelAnsis(value + "ms");
279
+ else if (settings.labelType == "time-sec")
280
+ label = labelAnsis(Math.round(value * 10) / 10 + "sec");
281
+ else if (settings.labelType == "time-min")
282
+ label = labelAnsis(Math.round(value * 10) / 10 + "min");
283
+ else
284
+ label = labelAnsis(value.toString());
285
+ const labelWithPrefixAndSuffix = prefix + label + suffix;
286
+ return (settings.labelPosition == "start") ? labelWithPrefixAndSuffix + " " + leftBorder + bar + rightBorder : leftBorder + bar + rightBorder + " " + labelWithPrefixAndSuffix;
287
+ }, settings);
288
+ }
289
+ /**Switch between Ansis functions based on the specified color. */
290
+ #switchColorAnsis(c) {
291
+ return (c === "openticket") ? ansis_1.default.hex("#f8ba00") : (c === "openmoderation") ? ansis_1.default.hex("#1690ff") : ansis_1.default[c];
292
+ }
293
+ }
294
+ exports.ODDefaultProgressBarRenderer = ODDefaultProgressBarRenderer;
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.4",
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",
@@ -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
  }