magmastream 2.9.3-dev.6 → 2.9.3-dev.8
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/dist/structures/Utils.js +74 -49
- package/package.json +1 -1
package/dist/structures/Utils.js
CHANGED
|
@@ -9,6 +9,7 @@ const Enums_1 = require("./Enums");
|
|
|
9
9
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
10
|
const safe_stable_stringify_1 = tslib_1.__importDefault(require("safe-stable-stringify"));
|
|
11
11
|
const MagmastreamError_1 = require("./MagmastreamError");
|
|
12
|
+
const lodash_1 = require("lodash");
|
|
12
13
|
// import playwright from "playwright";
|
|
13
14
|
/** @hidden */
|
|
14
15
|
const SIZES = ["0", "1", "2", "3", "default", "mqdefault", "hqdefault", "maxresdefault"];
|
|
@@ -623,65 +624,89 @@ class PlayerUtils {
|
|
|
623
624
|
* @returns The serialized Player instance
|
|
624
625
|
*/
|
|
625
626
|
static async serializePlayer(player) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
return undefined;
|
|
638
|
-
return value;
|
|
639
|
-
}))
|
|
640
|
-
: null;
|
|
641
|
-
return JSON.parse(JSON.stringify(player, (key, value) => {
|
|
642
|
-
if (key === "manager")
|
|
643
|
-
return null;
|
|
644
|
-
if (key === "node")
|
|
645
|
-
return safeNode;
|
|
646
|
-
if (key === "filters") {
|
|
647
|
-
return {
|
|
648
|
-
distortion: value?.distortion ?? null,
|
|
649
|
-
equalizer: value?.equalizer ?? [],
|
|
650
|
-
karaoke: value?.karaoke ?? null,
|
|
651
|
-
rotation: value?.rotation ?? null,
|
|
652
|
-
timescale: value?.timescale ?? null,
|
|
653
|
-
vibrato: value?.vibrato ?? null,
|
|
654
|
-
reverb: value?.reverb ?? null,
|
|
655
|
-
volume: value?.volume ?? 1.0,
|
|
656
|
-
bassBoostlevel: value?.bassBoostlevel ?? null,
|
|
657
|
-
filterStatus: value?.filtersStatus ? { ...value.filtersStatus } : {},
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
if (key === "queue") {
|
|
661
|
-
return {
|
|
662
|
-
current: current ? serializeTrack(current) : null,
|
|
663
|
-
tracks: tracks.map(serializeTrack),
|
|
664
|
-
previous: previous.map(serializeTrack),
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
if (key === "data") {
|
|
668
|
-
return {
|
|
669
|
-
clientUser: value?.Internal_AutoplayUser ?? null,
|
|
670
|
-
nowPlayingMessage: value?.nowPlayingMessage ?? null,
|
|
671
|
-
};
|
|
672
|
-
}
|
|
627
|
+
const current = await player.queue.getCurrent();
|
|
628
|
+
const tracks = await player.queue.getTracks();
|
|
629
|
+
const previous = await player.queue.getPrevious();
|
|
630
|
+
const serializeTrack = (track) => ({
|
|
631
|
+
...track,
|
|
632
|
+
requester: track.requester ? { id: track.requester.id, username: track.requester.username } : null,
|
|
633
|
+
});
|
|
634
|
+
const safeNode = player.node
|
|
635
|
+
? JSON.parse(JSON.stringify(player.node, (key, value) => {
|
|
636
|
+
if (key === "rest" || key === "players" || key === "shards" || key === "manager")
|
|
637
|
+
return undefined;
|
|
673
638
|
return value;
|
|
674
|
-
}))
|
|
639
|
+
}))
|
|
640
|
+
: null;
|
|
641
|
+
const isNonSerializable = (value) => {
|
|
642
|
+
if (typeof value === "function" || typeof value === "symbol")
|
|
643
|
+
return true;
|
|
644
|
+
if (typeof value === "object" && value !== null) {
|
|
645
|
+
const ctorName = value.constructor?.name ?? "";
|
|
646
|
+
return (value instanceof Map ||
|
|
647
|
+
value instanceof Set ||
|
|
648
|
+
value instanceof WeakMap ||
|
|
649
|
+
value instanceof WeakSet ||
|
|
650
|
+
ctorName === "Timeout" ||
|
|
651
|
+
ctorName === "Socket" ||
|
|
652
|
+
ctorName === "TLSSocket" ||
|
|
653
|
+
ctorName === "EventEmitter");
|
|
654
|
+
}
|
|
655
|
+
return false;
|
|
656
|
+
};
|
|
657
|
+
const safeReplacer = (key, value) => {
|
|
658
|
+
if (isNonSerializable(value))
|
|
659
|
+
return undefined;
|
|
660
|
+
if (key === "manager")
|
|
661
|
+
return null;
|
|
662
|
+
if (key === "node")
|
|
663
|
+
return safeNode;
|
|
664
|
+
if (key === "filters") {
|
|
665
|
+
const filters = { ...value };
|
|
666
|
+
delete filters.player;
|
|
667
|
+
return {
|
|
668
|
+
distortion: filters["distortion"] ?? null,
|
|
669
|
+
equalizer: filters["equalizer"] ?? [],
|
|
670
|
+
karaoke: filters["karaoke"] ?? null,
|
|
671
|
+
rotation: filters["rotation"] ?? null,
|
|
672
|
+
timescale: value["timescale"] ?? null,
|
|
673
|
+
vibrato: value["vibrato"] ?? null,
|
|
674
|
+
reverb: value["reverb"] ?? null,
|
|
675
|
+
volume: value["volume"] ?? 1.0,
|
|
676
|
+
bassBoostlevel: value["bassBoostlevel"] ?? null,
|
|
677
|
+
filterStatus: (0, lodash_1.isPlainObject)(value["filtersStatus"]) ? { ...value["filtersStatus"] } : {},
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
if (key === "queue") {
|
|
681
|
+
return {
|
|
682
|
+
current: current ? serializeTrack(current) : null,
|
|
683
|
+
tracks: tracks.map(serializeTrack),
|
|
684
|
+
previous: previous.map(serializeTrack),
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
if (key === "data" && (0, lodash_1.isPlainObject)(value)) {
|
|
688
|
+
return {
|
|
689
|
+
clientUser: value["Internal_AutoplayUser"] ?? null,
|
|
690
|
+
nowPlayingMessage: value["nowPlayingMessage"] ?? null,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
return value;
|
|
694
|
+
};
|
|
695
|
+
let serialized;
|
|
696
|
+
try {
|
|
697
|
+
serialized = JSON.stringify(player, safeReplacer);
|
|
675
698
|
}
|
|
676
699
|
catch (err) {
|
|
677
|
-
|
|
700
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
678
701
|
? err
|
|
679
702
|
: new MagmastreamError_1.MagmaStreamError({
|
|
680
703
|
code: Enums_1.MagmaStreamErrorCode.MANAGER_SEARCH_FAILED,
|
|
681
704
|
message: `An error occurred while searching: ${err instanceof Error ? err.message : String(err)}`,
|
|
682
705
|
cause: err instanceof Error ? err : undefined,
|
|
683
706
|
});
|
|
707
|
+
console.error(error);
|
|
684
708
|
}
|
|
709
|
+
return JSON.parse(serialized);
|
|
685
710
|
}
|
|
686
711
|
/**
|
|
687
712
|
* Gets the base directory for player data.
|