ahegao 1.69.1

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.
@@ -0,0 +1,851 @@
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.TextComp = exports.WeightedMap = exports.Config = exports.Lockable = exports.NumbersAnalysis = exports.NumberAnalysis = exports.Timer = exports.BoundedDeque = exports.Compare = exports.MUSIC_ALIASES = exports.Aliases = exports.TitleAndArtists = void 0;
7
+ const fs_1 = require("fs");
8
+ const path_1 = __importDefault(require("path"));
9
+ const structs_1 = require("../structures/structs");
10
+ const util_1 = require("../utils/util");
11
+ const fields_1 = require("./fields");
12
+ const mathjs_1 = require("mathjs");
13
+ class TitleAndArtists {
14
+ constructor(artists, artist, title) {
15
+ this.artists = artists;
16
+ this.artist = artist;
17
+ this.title = title;
18
+ this.sanitized_for_seed_artist = (0, util_1.sanitizeStringForSeed)(this.artist);
19
+ this.sanitized_for_seed_title = (0, util_1.sanitizeStringForSeed)(title);
20
+ this.seed = `${this.sanitized_for_seed_artist} ${this.sanitized_for_seed_title}`.trim();
21
+ this.hash = (0, util_1.generateHash)(this.seed);
22
+ }
23
+ get artistsDashTitle() {
24
+ return `${this.artist} - ${this.title}`;
25
+ }
26
+ async findGeniusLyrics() {
27
+ let lyrics = await (0, util_1.findGeniusLyrics)(this.artistsDashTitle);
28
+ if (this.artists.length > 1) {
29
+ if (lyrics == undefined || lyrics.length == 0) {
30
+ for (const artist of this.artists) {
31
+ const geniusLyrics = await (0, util_1.findGeniusLyrics)(`${artist} - ${this.title}`);
32
+ if (geniusLyrics != undefined && geniusLyrics.length > 0) {
33
+ lyrics = geniusLyrics;
34
+ break;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ return lyrics;
40
+ }
41
+ }
42
+ exports.TitleAndArtists = TitleAndArtists;
43
+ (function (TitleAndArtists) {
44
+ async function fromFileInfo(fileInfo, aliases = exports.MUSIC_ALIASES) {
45
+ let name = fileInfo.name;
46
+ const tags = await util_1.musicMetadata.parseFile(fileInfo.path);
47
+ const artists = (0, util_1.getArtistsFromFlacMetadata)(tags, aliases);
48
+ let artistsArray = Array.from(artists);
49
+ artistsArray.sort();
50
+ let artistsString = artistsArray.join(" & ");
51
+ let title = (0, util_1.getTitleFromFlacMetadata)(tags).replaceAll("[", "(").replaceAll("]", ")");
52
+ //region no artists / Various Artists
53
+ if (name.includes(" - ")) {
54
+ if (artistsString.length == 0 || artistsString === fields_1.VARIOUS_ARTISTS) {
55
+ artistsString = (0, util_1.songTitleExtractSide)(name, true, false);
56
+ if (artistsString.includes(" - ")) {
57
+ artistsString = (0, util_1.songTitleExtractSide)(artistsString, true, true);
58
+ }
59
+ (0, util_1.addAllArrayToSet)((0, util_1.librarySplitMultipleArtists)(artistsString, aliases), artists);
60
+ artists.delete(fields_1.VARIOUS_ARTISTS);
61
+ artistsArray = Array.from(artists);
62
+ artistsString = artistsArray.join(" & ");
63
+ }
64
+ }
65
+ if (title.length == 0 || title.includes(" - ")) {
66
+ title = (0, util_1.songTitleExtractSide)(name, true, true);
67
+ }
68
+ const titleFeaturingResult = (0, util_1.libraryFindFeaturing)(title, aliases);
69
+ title = (0, util_1.libraryCleanUpStartAndEndOfString)(titleFeaturingResult.newName);
70
+ return new TitleAndArtists(artistsArray, artistsString, title);
71
+ }
72
+ TitleAndArtists.fromFileInfo = fromFileInfo;
73
+ })(TitleAndArtists || (exports.TitleAndArtists = TitleAndArtists = {}));
74
+ class Aliases {
75
+ constructor() {
76
+ this.reverseAliases = new Map;
77
+ }
78
+ add(name, ...aliases) {
79
+ aliases.push(name);
80
+ for (const alias of aliases) {
81
+ this.reverseAliases.set(alias.trim().toLowerCase(), name.trim());
82
+ }
83
+ return this;
84
+ }
85
+ get(name) {
86
+ var _a;
87
+ return (_a = this.reverseAliases.get(name.trim().toLowerCase())) !== null && _a !== void 0 ? _a : name;
88
+ }
89
+ }
90
+ exports.Aliases = Aliases;
91
+ exports.MUSIC_ALIASES = new Aliases()
92
+ .add(fields_1.VARIOUS_ARTISTS)
93
+ .add("artist_lost_please_fix", "AReallyLongAndAwesomeNameThatIsBetterThanYoursInEveryPossibleWay", "Original")
94
+ .add("Vylet Pony", "Vylet", "VyletPony")
95
+ .add("General Mumble", "Mumble", "GeneralMumble", "GM")
96
+ .add("&I", "I", "&I (AndI)", "AndI")
97
+ .add("Alex S.", "AlexS", "Alex S", "Alex.", "andromulus")
98
+ .add("4EverfreeBrony", "4EverfreeBrony")
99
+ .add("Additive Subtractive", "AdditiveSubtractive")
100
+ .add("Age Of Vinyl", "Age Of Vinyl")
101
+ .add("All Levels At Once", "All Levels At Once")
102
+ .add("Archie", "Archie (Second Channel)", "Archie.V")
103
+ .add("Artémis Plume", "Artémis Plum")
104
+ .add("Assertive Fluttershy", "AssertiveFluttershy", "Assertive")
105
+ .add("Awkward Marina", "AwkwardMarina")
106
+ .add("Black Gryph0n", "BlackGryph0n")
107
+ .add("BriLizy T", "BriLizyT")
108
+ .add("Brilliant Venture", "Brilliant Ventures")
109
+ .add("Camellia", "Camelia")
110
+ .add("Chi-Chi", "Chi-Chi", "Chi Chi")
111
+ .add("Chord Catcher", "ChordCatcher")
112
+ .add("Cyril the Wolf", "Cyril The Wolf", "CyrilTheWolf")
113
+ .add("DE$iGNATED", "DE$iGNATED 2k13")
114
+ .add("Dauntless Dan", "Dauntless")
115
+ .add("Dijit", "Dijit DJT", "Dijit | DJT", "DJT")
116
+ .add("EnsionD", "Ension")
117
+ .add("Errar404", "Error 404", "Error404")
118
+ .add("FIREeNVY")
119
+ .add("FluffyKittyMusic", "FluffyKitty")
120
+ .add("GROskAr")
121
+ .add("Giggly Maria", "GigglyMaria")
122
+ .add("GloryOfTheRainWings", "Glory of the Rainwings")
123
+ .add("JackleApp", "Jackle App")
124
+ .add("KLBI", "KLBI VIP")
125
+ .add("KeepOnRockin'", "KeeponRockin'")
126
+ .add("MC-Arch", "MC Arch")
127
+ .add("Maikel631", "Maikel6311")
128
+ .add("MandoPony")
129
+ .add("Metapony", "Meta Pony")
130
+ .add("Mic the Microphone")
131
+ .add("Daniel Ingram", "My Little Pony", "My Little Pony Official")
132
+ .add("N. Hollow", "N.Hollow")
133
+ .add("Neu KatalYst")
134
+ .add("NeverLastStanding")
135
+ .add("Nikki Layne", "Nikki-Layne")
136
+ .add("Ponies at Dawn")
137
+ .add("Relative1Pitch", "Relative|Pitch")
138
+ .add("Rina-Chan", "Rina Chan", "Rina-Chan - Human")
139
+ .add("RoseDoodle")
140
+ .add("SP1TF1R3", "SP1TF1RE")
141
+ .add("Sam Quak Brony")
142
+ .add("Scraton", "Scraton Music Official")
143
+ .add("Senntenial", "Senntennial")
144
+ .add("Seshlehem", "Seshleshem")
145
+ .add("SeyN AQ")
146
+ .add("Sherclop Pones", "SherclopPones")
147
+ .add("Sim Gretina", "SimGretina")
148
+ .add("SoGreatAndPowerful")
149
+ .add("StealingShad3z")
150
+ .add("Synthion", "Synthion Ch")
151
+ .add("Thomas H.", "Thomas H")
152
+ .add("Tw3Lv3")
153
+ .add("Velvet R. Wings", "Velvet Wings")
154
+ .add("WoodenToaster", "Wooden Toaster")
155
+ .add("YOKAIII", "YOKAII", "YOKAI")
156
+ .add("saradisk", "saradisk - 220")
157
+ .add("アイスベア", "アイスベア (Ice Bear)")
158
+ .add("ArtAttack", "Art Attack")
159
+ .add("Krewella", "Krewella Fuck On Me")
160
+ .add("Replacer", "Replacer &I")
161
+ .add("Tune Up", "Tune Up!")
162
+ .add("µThunder")
163
+ .add("MC-Arch", "MC - Arch")
164
+ .add("Forest Rain", "ForestRain", "Forest Rain Covers")
165
+ .add("IgnaPon3", "IgnaPone", "IgnaPony", "Igna")
166
+ .add("Sam Synthis", "Synthis");
167
+ var Compare;
168
+ (function (Compare) {
169
+ let NumberCompareOperator;
170
+ (function (NumberCompareOperator) {
171
+ NumberCompareOperator["Equal"] = "equal";
172
+ NumberCompareOperator["NotEqual"] = "not_equal";
173
+ NumberCompareOperator["GreaterThan"] = "greater_than";
174
+ NumberCompareOperator["GreaterThanOrEqual"] = "greater_than_or_equal";
175
+ NumberCompareOperator["LessThan"] = "less_than";
176
+ NumberCompareOperator["LessThanOrEqual"] = "less_than_or_equal";
177
+ })(NumberCompareOperator = Compare.NumberCompareOperator || (Compare.NumberCompareOperator = {}));
178
+ let StringCompareOperator;
179
+ (function (StringCompareOperator) {
180
+ StringCompareOperator["Equal"] = "equal";
181
+ StringCompareOperator["NotEqual"] = "not_equal";
182
+ StringCompareOperator["Contains"] = "contains";
183
+ StringCompareOperator["NotContains"] = "not_contains";
184
+ StringCompareOperator["StartsWith"] = "starts_with";
185
+ StringCompareOperator["EndsWith"] = "ends_with";
186
+ })(StringCompareOperator = Compare.StringCompareOperator || (Compare.StringCompareOperator = {}));
187
+ function fromString(input) {
188
+ switch (input) {
189
+ case "equal":
190
+ case "eq":
191
+ return NumberCompareOperator.Equal;
192
+ case "not_equal":
193
+ case "neq":
194
+ case "!=":
195
+ return NumberCompareOperator.NotEqual;
196
+ case "greater_than":
197
+ case "gt":
198
+ case ">":
199
+ return NumberCompareOperator.GreaterThan;
200
+ case "greater_than_or_equal":
201
+ case "gte":
202
+ case ">=":
203
+ return NumberCompareOperator.GreaterThanOrEqual;
204
+ case "less_than":
205
+ case "lt":
206
+ case "<":
207
+ return NumberCompareOperator.LessThan;
208
+ case "less_than_or_equal":
209
+ case "lte":
210
+ case "<=":
211
+ return NumberCompareOperator.LessThanOrEqual;
212
+ case "contains":
213
+ case "in":
214
+ return StringCompareOperator.Contains;
215
+ case "starts_with":
216
+ case "starts":
217
+ return StringCompareOperator.StartsWith;
218
+ case "ends_with":
219
+ case "ends":
220
+ return StringCompareOperator.EndsWith;
221
+ case "not_contains":
222
+ case "not_in":
223
+ return StringCompareOperator.NotContains;
224
+ default:
225
+ throw new Error(`Unknown operator: ${input}`);
226
+ }
227
+ }
228
+ Compare.fromString = fromString;
229
+ function compare(value, operator) {
230
+ if ((0, util_1.isString)(value)) {
231
+ return string(value, operator);
232
+ }
233
+ else {
234
+ return number(value, operator);
235
+ }
236
+ }
237
+ Compare.compare = compare;
238
+ function number(value, operator) {
239
+ switch (operator) {
240
+ case NumberCompareOperator.Equal:
241
+ return value == value;
242
+ case NumberCompareOperator.NotEqual:
243
+ return value != value;
244
+ case NumberCompareOperator.GreaterThan:
245
+ return value > value;
246
+ case NumberCompareOperator.GreaterThanOrEqual:
247
+ return value >= value;
248
+ case NumberCompareOperator.LessThan:
249
+ return value < value;
250
+ case NumberCompareOperator.LessThanOrEqual:
251
+ return value <= value;
252
+ }
253
+ }
254
+ Compare.number = number;
255
+ function string(value, operator) {
256
+ switch (operator) {
257
+ case StringCompareOperator.Equal:
258
+ return value == value;
259
+ case StringCompareOperator.NotEqual:
260
+ return value != value;
261
+ case StringCompareOperator.Contains:
262
+ return value.includes(value);
263
+ case StringCompareOperator.StartsWith:
264
+ return value.startsWith(value);
265
+ case StringCompareOperator.EndsWith:
266
+ return value.endsWith(value);
267
+ case StringCompareOperator.NotContains:
268
+ return !value.includes(value);
269
+ }
270
+ }
271
+ Compare.string = string;
272
+ })(Compare || (exports.Compare = Compare = {}));
273
+ class BoundedDeque {
274
+ constructor(maxSize) {
275
+ this.maxSize = maxSize;
276
+ this.queue = [];
277
+ if (maxSize < 1)
278
+ throw new Error("Max size must be at least 1!");
279
+ }
280
+ pushEnd(item) {
281
+ this.queue.push(item);
282
+ this.trimFrontIfNeeded();
283
+ }
284
+ pushFront(item) {
285
+ this.queue.unshift(item);
286
+ this.trimBackIfNeeded();
287
+ }
288
+ popEnd() {
289
+ return this.queue.pop();
290
+ }
291
+ popFront() {
292
+ return this.queue.shift();
293
+ }
294
+ peekFront() {
295
+ return this.queue[0];
296
+ }
297
+ peekEnd() {
298
+ return (0, util_1.getLast)(this.queue);
299
+ }
300
+ get size() {
301
+ return this.queue.length;
302
+ }
303
+ isEmpty() {
304
+ return this.queue.length == 0;
305
+ }
306
+ isFull() {
307
+ return this.queue.length == this.maxSize;
308
+ }
309
+ clear() {
310
+ this.queue = [];
311
+ }
312
+ toArray() {
313
+ return [...this.queue];
314
+ }
315
+ get array() {
316
+ return this.queue;
317
+ }
318
+ trimFrontIfNeeded() {
319
+ while (this.queue.length > this.maxSize) {
320
+ this.queue.shift();
321
+ }
322
+ }
323
+ trimBackIfNeeded() {
324
+ while (this.queue.length > this.maxSize) {
325
+ this.queue.pop();
326
+ }
327
+ }
328
+ }
329
+ exports.BoundedDeque = BoundedDeque;
330
+ class Timer {
331
+ constructor() {
332
+ this._startMs = 0;
333
+ this._lastIncrementMs = 0;
334
+ this._count = 0;
335
+ this.updateLoadingBar = util_1.noop;
336
+ this.reset();
337
+ }
338
+ reset() {
339
+ this._startMs = Date.now();
340
+ this._lastIncrementMs = this._startMs;
341
+ this._count = 0;
342
+ }
343
+ get startMs() {
344
+ return this._startMs;
345
+ }
346
+ get elapsedMs() {
347
+ return Date.now() - this._startMs;
348
+ }
349
+ get elapsedS() {
350
+ return this.elapsedMs / 1000;
351
+ }
352
+ increment(incrementBy = 1, updateLoadingBar = false) {
353
+ this._count += incrementBy;
354
+ this._lastIncrementMs = Date.now();
355
+ if (updateLoadingBar) {
356
+ this.updateLoadingBar();
357
+ }
358
+ return this._count;
359
+ }
360
+ get lastIncrementMs() {
361
+ return this._lastIncrementMs;
362
+ }
363
+ get lastIncrementGapMs() {
364
+ return Date.now() - this._lastIncrementMs;
365
+ }
366
+ get lastIncrementGapS() {
367
+ return this.lastIncrementGapMs / 1000;
368
+ }
369
+ get count() {
370
+ return this._count;
371
+ }
372
+ get countPerSecond() {
373
+ return this._count / this.elapsedS;
374
+ }
375
+ get countPerSecondString() {
376
+ return `${(0, util_1.softToFixed)(this.countPerSecond)}/s`;
377
+ }
378
+ isFinished(goalCount) {
379
+ return goalCount <= this._count;
380
+ }
381
+ getETASecondsForCount(goalCount) {
382
+ return (goalCount - this._count) / this.countPerSecond;
383
+ }
384
+ getETASecondsForCountString(goalCount) {
385
+ return (0, util_1.toStamp)(this.getETASecondsForCount(goalCount));
386
+ }
387
+ getCountAndPercentString(goalCount) {
388
+ if (this._count == 0) {
389
+ return `[0/${(0, util_1.softToFixed)(goalCount)}]~[0.00%]`;
390
+ }
391
+ const percent = (this._count / goalCount) * 100;
392
+ return `[${(0, util_1.softToFixed)(this.count)}/${(0, util_1.softToFixed)(goalCount)}]~[${(percent).toFixed(2)}%]`;
393
+ }
394
+ getFullStatsString(goalCount) {
395
+ if (this._count == 0) {
396
+ return this.getCountAndPercentString(goalCount);
397
+ }
398
+ return `${this.getCountAndPercentString(goalCount)} | ${this.getETASecondsForCountString(goalCount)} | ${this.countPerSecondString}`;
399
+ }
400
+ startLoadingBarForS(durationS, suffixDecider = "", onFinish = util_1.noop, intervalMs = 250, rainbowIntervalMs = 250) {
401
+ this.reset();
402
+ const loop = this.startLoadingBarUntilDone(durationS, suffixDecider, onFinish, false, intervalMs, rainbowIntervalMs);
403
+ let secondsPassed = 0;
404
+ let finished = false;
405
+ (0, util_1.whileFalseAsyncMs)(intervalMs, () => {
406
+ this.increment(secondsPassed - this._count);
407
+ return finished;
408
+ });
409
+ (0, util_1.whileFalseAsyncS)(1, () => {
410
+ ++secondsPassed;
411
+ if (durationS <= secondsPassed) {
412
+ finished = true;
413
+ }
414
+ return finished;
415
+ });
416
+ return loop;
417
+ }
418
+ startLoadingBarUntilDone(goalCountDecider, suffixDecider = "", onFinish = util_1.noop, fullStats = true, intervalMs = 250, rainbowIntervalMs = 1000) {
419
+ const cycleRainbowEveryMs = (0, mathjs_1.max)(rainbowIntervalMs, intervalMs);
420
+ const goalCountIsNumber = (0, mathjs_1.isNumber)(goalCountDecider);
421
+ const suffixIsString = (0, util_1.isString)(suffixDecider);
422
+ this.updateLoadingBar = () => {
423
+ const goalCount = goalCountIsNumber ? goalCountDecider : goalCountDecider();
424
+ const finished = goalCount <= this._count;
425
+ if (finished) {
426
+ clearInterval(loop);
427
+ }
428
+ const suffix = suffixIsString ? suffixDecider : suffixDecider();
429
+ let line = fullStats ? this.getFullStatsString(goalCount) : this.getCountAndPercentString(goalCount);
430
+ if (suffix.length > 0) {
431
+ line += ` | ${suffix}`;
432
+ }
433
+ const rainbowIndex = (0, mathjs_1.floor)(Date.now() / cycleRainbowEveryMs);
434
+ if (rainbowIntervalMs > 0) {
435
+ line = (0, util_1.chalkRainbowColor)(line, rainbowIndex);
436
+ }
437
+ (0, util_1.replaceLastTerminalLine)(line);
438
+ if (finished) {
439
+ console.log((0, util_1.chalkRainbowColor)(` | Finished!`, rainbowIndex));
440
+ this.updateLoadingBar = util_1.noop;
441
+ onFinish();
442
+ }
443
+ };
444
+ const loop = setInterval(() => {
445
+ this.updateLoadingBar();
446
+ }, intervalMs);
447
+ return loop;
448
+ }
449
+ startReplaceLastTerminalLineLoop(stringMaker, intervalMs = 250) {
450
+ return setInterval(() => {
451
+ (0, util_1.replaceLastTerminalLine)(stringMaker());
452
+ }, intervalMs);
453
+ }
454
+ }
455
+ exports.Timer = Timer;
456
+ // export class SmartTimer extends Timer
457
+ // {
458
+ // private _lookbackHistoryMs: BoundedDeque<number>
459
+ // public constructor(public readonly lookBackCount: number = 10)
460
+ // {
461
+ // super()
462
+ // this._lookbackHistoryMs = new BoundedDeque(lookBackCount)
463
+ // }
464
+ // public override increment(incrementBy?: number): number
465
+ // {
466
+ // }
467
+ // }
468
+ class NumberAnalysis {
469
+ constructor(values = fields_1.EMPTY_ARRAY) {
470
+ this._lowest = Number.MAX_VALUE;
471
+ this._highest = Number.MIN_VALUE;
472
+ this.updateArray(values);
473
+ }
474
+ updateArray(buffer) {
475
+ for (const byte of buffer) {
476
+ this.update(byte);
477
+ }
478
+ }
479
+ update(value) {
480
+ if (value < this._lowest) {
481
+ this._lowest = value;
482
+ }
483
+ else if (this._highest < value) {
484
+ this._highest = value;
485
+ }
486
+ }
487
+ get lowest() {
488
+ return this._lowest;
489
+ }
490
+ get highest() {
491
+ return this._highest;
492
+ }
493
+ forEachLowestFirst(consumer) {
494
+ for (let y = this._lowest; y <= this._highest; ++y) {
495
+ consumer(y);
496
+ }
497
+ }
498
+ forEachHighestFirst(consumer) {
499
+ for (let y = this._highest; y >= this._lowest; --y) {
500
+ consumer(y);
501
+ }
502
+ }
503
+ forEach(lowestFirst, consumer) {
504
+ if (lowestFirst) {
505
+ this.forEachLowestFirst(consumer);
506
+ }
507
+ else {
508
+ this.forEachHighestFirst(consumer);
509
+ }
510
+ }
511
+ get gap() {
512
+ return this._highest - this._lowest;
513
+ }
514
+ toRangedNumber() {
515
+ return structs_1.RangedNumber.range(this._lowest, this._highest);
516
+ }
517
+ toString() {
518
+ return `${this._lowest}<->${this._highest}`;
519
+ }
520
+ }
521
+ exports.NumberAnalysis = NumberAnalysis;
522
+ class NumbersAnalysis extends NumberAnalysis {
523
+ constructor(values = fields_1.EMPTY_ARRAY) {
524
+ super(fields_1.EMPTY_ARRAY);
525
+ this._sum = 0;
526
+ this.array = [];
527
+ this.map = new Map();
528
+ this.updateArray(values);
529
+ }
530
+ update(value) {
531
+ super.update(value);
532
+ (0, util_1.incrementMap)(this.map, value);
533
+ this.array.push(value);
534
+ this._sum += value;
535
+ }
536
+ get average() {
537
+ return this._sum / this.count;
538
+ }
539
+ get sum() {
540
+ return this._sum;
541
+ }
542
+ get count() {
543
+ return this.array.length;
544
+ }
545
+ sortedArray(ascending = false) {
546
+ return this.array.slice().sort((a, b) => ascending ? a - b : b - a);
547
+ }
548
+ get median() {
549
+ if (this.count == 0) {
550
+ return 0;
551
+ }
552
+ const sorted = this.sortedArray();
553
+ const middle = Math.floor(this.count / 2);
554
+ if (this.count % 2 == 0) {
555
+ return (sorted[middle - 1] + sorted[middle]) / 2;
556
+ }
557
+ else {
558
+ return sorted[middle];
559
+ }
560
+ }
561
+ getSortedFrequencyKeys(ascending = false) {
562
+ return Array.from(this.map.keys()).sort((a, b) => ascending ? a - b : b - a);
563
+ }
564
+ toString() {
565
+ let text = `[${this.lowest}<->${this.highest} | count: ${this.count} | sum: ${this._sum} | average: ${(0, util_1.softToFixed)(this.average)} | median: ${this.median}]`;
566
+ for (const key of this.getSortedFrequencyKeys()) {
567
+ text += `\n- ${key}: ${this.map.get(key)}`;
568
+ }
569
+ return text;
570
+ }
571
+ }
572
+ exports.NumbersAnalysis = NumbersAnalysis;
573
+ class Lockable {
574
+ constructor(item) {
575
+ this._locked = false;
576
+ this._item = item;
577
+ }
578
+ get item() {
579
+ return this._item;
580
+ }
581
+ set item(item) {
582
+ if (this._locked) {
583
+ throw new Error("Cannot set item, object is locked.");
584
+ }
585
+ this._item = item;
586
+ }
587
+ get locked() {
588
+ return this._locked;
589
+ }
590
+ set locked(locked) {
591
+ this._locked = locked;
592
+ }
593
+ set(item) {
594
+ this.item = item;
595
+ }
596
+ get() {
597
+ return this._item;
598
+ }
599
+ lock() {
600
+ this._locked = true;
601
+ }
602
+ unlock() {
603
+ this._locked = false;
604
+ }
605
+ toString() {
606
+ return `${this._item}`;
607
+ }
608
+ }
609
+ exports.Lockable = Lockable;
610
+ class Config {
611
+ constructor(configPath = `${path_1.default.resolve(__dirname, "..")}/config.json`) {
612
+ this.configPath = configPath;
613
+ this._init = false;
614
+ this._config = {};
615
+ this.basePath = path_1.default.resolve(__dirname, "..");
616
+ this.name = path_1.default.basename(configPath);
617
+ }
618
+ get isInit() {
619
+ return this._init;
620
+ }
621
+ throwIfNotInit() {
622
+ if (!this._init) {
623
+ throw `Config\n"${this}"\nIs not initialized`;
624
+ }
625
+ }
626
+ throwIfInit(error = `${this}\nIs already initialized`) {
627
+ if (this._init) {
628
+ throw error;
629
+ }
630
+ }
631
+ define(key, value) {
632
+ this.throwIfInit(`Config\n"${this}"\nTried to define "${key}" with value "${value}" after initialization`);
633
+ const existingValue = this._config[key];
634
+ if (existingValue != null) {
635
+ throw `${this}\nValue "${key}" already defined: ${existingValue}`;
636
+ }
637
+ this._config[key] = value;
638
+ return this;
639
+ }
640
+ get(key) {
641
+ this.throwIfNotInit();
642
+ return this._config[key];
643
+ }
644
+ getString(key) {
645
+ return this.get(key);
646
+ }
647
+ getNumber(key) {
648
+ return this.get(key);
649
+ }
650
+ getBool(key) {
651
+ return this.is(key);
652
+ }
653
+ is(key) {
654
+ this.throwIfNotInit();
655
+ return this.get(key);
656
+ }
657
+ set(key, value) {
658
+ this.throwIfNotInit();
659
+ return this._set(key, value);
660
+ }
661
+ _set(key, value) {
662
+ const currentValue = this._config[key];
663
+ if (currentValue != null) {
664
+ if (typeof (value) !== typeof (currentValue)) {
665
+ throw `${this}\nValue type mismatch for key ${key}: expected ${typeof (this._config[key])}, got ${typeof (value)}`;
666
+ }
667
+ }
668
+ else {
669
+ throw `${this}\nKey "${key}" is not defined`;
670
+ }
671
+ this._config[key] = value;
672
+ return this;
673
+ }
674
+ init() {
675
+ this.throwIfInit();
676
+ if ((0, fs_1.existsSync)(this.configPath)) {
677
+ const localConfigJson = require(this.configPath);
678
+ for (const [key, value] of Object.entries(localConfigJson)) {
679
+ const defaultValue = this._config[key];
680
+ if (defaultValue == null) {
681
+ console.warn(`${this}\nReading undefined config "${key}"`);
682
+ }
683
+ if (typeof (value) !== typeof (defaultValue)) {
684
+ throw `${this}\nValue type mismatch for key ${key}: expected ${typeof (defaultValue)}, got ${typeof (value)}`;
685
+ }
686
+ this._set(key, value);
687
+ }
688
+ }
689
+ this.save();
690
+ this._init = true;
691
+ return this;
692
+ }
693
+ save() {
694
+ const configJson = (0, util_1.stringify)(this._config);
695
+ (0, fs_1.writeFileSync)(this.configPath, configJson);
696
+ return this;
697
+ }
698
+ toString() {
699
+ let result = `Config "${this.name}"\n`;
700
+ for (const [key, value] of Object.entries(this._config)) {
701
+ result += `"${key}": "${value}"\n`;
702
+ }
703
+ return result;
704
+ }
705
+ }
706
+ exports.Config = Config;
707
+ class WeightedMap {
708
+ constructor() {
709
+ this._map = new Map();
710
+ this._totalWeight = 0;
711
+ }
712
+ add(item, weight = 1) {
713
+ if (weight <= 0) {
714
+ throw `${this}: Cannot add "${item}"; weight <= 0`;
715
+ }
716
+ this._map.set(item, weight);
717
+ this._totalWeight += weight;
718
+ return this;
719
+ }
720
+ get() {
721
+ if (this.empty) {
722
+ throw `${this}: Cannot get item; map is empty`;
723
+ }
724
+ const item = (0, util_1.getRandomWeighedItem)(this._map, this._totalWeight);
725
+ if (item == null) {
726
+ throw `${this}: Got ${item} item`;
727
+ }
728
+ return item;
729
+ }
730
+ get empty() {
731
+ return this.size == 0;
732
+ }
733
+ get hasItems() {
734
+ return this.size > 0;
735
+ }
736
+ get size() {
737
+ return this._map.size;
738
+ }
739
+ }
740
+ exports.WeightedMap = WeightedMap;
741
+ (function (WeightedMap) {
742
+ function of(input) {
743
+ const weightedMap = new WeightedMap;
744
+ if ((0, mathjs_1.isArray)(input)) {
745
+ for (const item of input) {
746
+ weightedMap.add(item);
747
+ }
748
+ }
749
+ else {
750
+ weightedMap.add(input);
751
+ }
752
+ return weightedMap;
753
+ }
754
+ WeightedMap.of = of;
755
+ })(WeightedMap || (exports.WeightedMap = WeightedMap = {}));
756
+ class TextComp {
757
+ constructor(data) {
758
+ var _a, _b;
759
+ if (data == null) {
760
+ this._children = new WeightedMap;
761
+ throw `${this}: Cannot create TextComp from null`;
762
+ }
763
+ this.text = data.text == undefined ? "" : data.text.trim();
764
+ this.chance = (_a = data.chance) !== null && _a !== void 0 ? _a : 1;
765
+ this.continueToChildOnFail = (_b = data.continueToChildOnFail) !== null && _b !== void 0 ? _b : false;
766
+ if (data.children == undefined) {
767
+ this._children = new WeightedMap;
768
+ }
769
+ else {
770
+ if (data.children instanceof WeightedMap) {
771
+ this._children = data.children;
772
+ }
773
+ else {
774
+ this._children = new WeightedMap;
775
+ if ((0, mathjs_1.isArray)(data.children)) {
776
+ for (const child of data.children) {
777
+ this._children.add(TextComp.of(child));
778
+ }
779
+ }
780
+ else {
781
+ this._children.add(TextComp.of(data.children));
782
+ }
783
+ }
784
+ }
785
+ }
786
+ get hasChildren() {
787
+ return this._children.hasItems;
788
+ }
789
+ getRandomChild() {
790
+ return this._children.get();
791
+ }
792
+ generate(lookup = fields_1.EMPTY_MAP, separator = " ", text = "") {
793
+ if ((0, util_1.randomBoolean)(this.chance)) {
794
+ if (this.text.length > 0) {
795
+ text += `${text.length > 0 ? separator : ""}${this.text.replaceAll(fields_1.KEY_WORDS_REGEX, (_, match) => {
796
+ const lookupItem = lookup.get(match);
797
+ if (lookupItem == null) {
798
+ return match;
799
+ }
800
+ if (lookupItem.empty) {
801
+ return match;
802
+ }
803
+ return TextComp.of(lookupItem.get()).generate(lookup, separator);
804
+ })}`;
805
+ }
806
+ }
807
+ else {
808
+ if (!this.continueToChildOnFail) {
809
+ return text;
810
+ }
811
+ }
812
+ if (this._children.hasItems) {
813
+ const child = this.getRandomChild();
814
+ return child.generate(lookup, separator, text);
815
+ }
816
+ return text;
817
+ }
818
+ toString() {
819
+ return `TextComp: "${this.text}" | chance: ${this.chance} | children: ${this._children.size}`;
820
+ }
821
+ }
822
+ exports.TextComp = TextComp;
823
+ (function (TextComp) {
824
+ function of(item) {
825
+ if ((0, util_1.isString)(item)) {
826
+ return TextComp.of({ text: item });
827
+ }
828
+ else if (item instanceof TextComp) {
829
+ return item;
830
+ }
831
+ else {
832
+ return new TextComp(item);
833
+ }
834
+ }
835
+ TextComp.of = of;
836
+ })(TextComp || (exports.TextComp = TextComp = {}));
837
+ // export abstract class ConfigEntry<T>
838
+ // {
839
+ // constructor
840
+ // (
841
+ // public readonly name: string,
842
+ // public readonly defaultValue: T,
843
+ // public readonly description: string = "",
844
+ // )
845
+ // {
846
+ // }
847
+ // }
848
+ // export class Config
849
+ // {
850
+ // }
851
+ //# sourceMappingURL=classes.js.map