From c6da39844b5ba9d7790f84481464422db49ed0f3 Mon Sep 17 00:00:00 2001 From: FAYStarNext Date: Sun, 8 Sep 2024 01:23:21 +0000 Subject: [PATCH] Refactor Manager class to properly initialize nodes and decode tracks --- src/Structures/Manager.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Structures/Manager.ts b/src/Structures/Manager.ts index 8fba726..57b443d 100644 --- a/src/Structures/Manager.ts +++ b/src/Structures/Manager.ts @@ -97,11 +97,10 @@ export class Manager extends TypedEmitter { super(); managerCheck(options); - Structure.get("Player").init(this); Structure.get("Node").init(this); TrackUtils.init(this); - + if (options.trackPartial) { TrackUtils.setTrackPartial(options.trackPartial); delete options.trackPartial; @@ -134,7 +133,10 @@ export class Manager extends TypedEmitter { } if (this.options.nodes) { - for (const nodeOptions of this.options.nodes) new (Structure.get("Node"))(nodeOptions); + for (const nodeOptions of this.options.nodes) { + const node = new (Structure.get("Node"))(nodeOptions); + this.nodes.set(node.options.identifier, node); + } } } @@ -263,17 +265,18 @@ export class Manager extends TypedEmitter { * @param tracks */ public decodeTracks(tracks: string[]): Promise { - return new Promise(async (resolve, reject) => { + return new Promise(async(resolve, reject) => { const node = this.nodes.first(); - if (!node) throw new Error("No available nodes."); - - const res = (await node.rest.post("/v4/decodetracks", JSON.stringify(tracks)).catch((err) => reject(err))) as TrackData[]; - - if (!res) { - return reject(new Error("No data returned from query.")); + if (!node) { + return reject(new Error("No available nodes.")); } - - return resolve(res); + + await node.rest.post("/v4/decodetracks", JSON.stringify(tracks)) + .then((res) => { + if (!res) return reject(new Error("No data returned from query.")); + resolve(res as TrackData[]); + }) + .catch((err) => reject(err)); }); }