From 657abed6aa4a0f1b107168aa12712e78d999bf07 Mon Sep 17 00:00:00 2001 From: flav-code Date: Sun, 28 Jul 2024 14:09:22 +0000 Subject: [PATCH 1/9] chore: update Player move method to accept MoveOptions --- src/guild/Player.ts | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index f7cf6d36..2ebc353b 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -16,6 +16,11 @@ export enum PlayerEventType { WEBSOCKET_CLOSED_EVENT = 'WebSocketClosedEvent', } +export interface MoveOptions { + name?: string; + force?: boolean; +} + export interface Band { band: number; gain: number; @@ -226,8 +231,8 @@ export class Player extends EventEmitter { return { guildId: this.guildId, playerOptions: { - track: { - encoded: this.track + track: { + encoded: this.track }, position: this.position, paused: this.paused, @@ -244,12 +249,12 @@ export class Player extends EventEmitter { /** * Move player to another node - * @param name Name of node to move to, or the default ideal node + * @param opts An object that conforms to the MoveOptions type * @returns true if the player was moved, false if not */ - public async move(name?: string): Promise { + public async move(opts: MoveOptions = { force: false }): Promise { const connection = this.node.manager.connections.get(this.guildId); - const node = this.node.manager.nodes.get(name!) || this.node.manager.getIdealNode(connection); + const node = this.node.manager.nodes.get(opts.name!) || this.node.manager.getIdealNode(connection); if (!node && ![ ...this.node.manager.nodes.values() ].some(node => node.state === State.CONNECTED)) throw new Error('No available nodes to move to'); @@ -260,9 +265,12 @@ export class Player extends EventEmitter { if (!lastNode || lastNode.state !== State.CONNECTED) lastNode = this.node.manager.getIdealNode(connection); - await this.destroy(); - - try { + if (!opts.force) + await this.destroy(); + else + await this.destroy().catch(() => null); + + try { this.node = node; await this.resume(); return true; @@ -435,7 +443,7 @@ export class Player extends EventEmitter { public async resume(options: ResumeOptions = {}, noReplace: boolean = false): Promise { const data = this.data; - if (typeof options.position === 'number') + if (typeof options.position === 'number') data.playerOptions.position = options.position; if (typeof options.endTime === 'number') data.playerOptions.endTime = options.endTime; @@ -459,11 +467,11 @@ export class Player extends EventEmitter { guildId: this.guildId, noReplace, playerOptions - } + }; await this.node.rest.updatePlayer(data); - if (!noReplace) this.paused = false + if (!noReplace) this.paused = false; if (playerOptions.filters) { const filters = { ...this.filters, ...playerOptions.filters }; From a19c59e048563d14c72a2bedfccb1cfde968db94 Mon Sep 17 00:00:00 2001 From: Flavien <48295189+flav-code@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:16:23 +0200 Subject: [PATCH 2/9] Update src/guild/Player.ts Co-authored-by: 0t4u <61939142+0t4u@users.noreply.github.com> --- src/guild/Player.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 2ebc353b..79d388c0 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -252,7 +252,14 @@ export class Player extends EventEmitter { * @param opts An object that conforms to the MoveOptions type * @returns true if the player was moved, false if not */ - public async move(opts: MoveOptions = { force: false }): Promise { + public async move(name?: string): Promise { + /** + * Move player to another node + * @param options.name Name of node to move to, or the default ideal node + * @param options.force Force the move and ignore errors when destroying the original player fails (e.g. during Node disconnect) + * @returns true if the player was moved, false if not + */ + public async move({ name, force }: MoveOptions): Promise { const connection = this.node.manager.connections.get(this.guildId); const node = this.node.manager.nodes.get(opts.name!) || this.node.manager.getIdealNode(connection); From 287d023446969d8bc10bd01c0de607934081e960 Mon Sep 17 00:00:00 2001 From: Flavien <48295189+flav-code@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:16:31 +0200 Subject: [PATCH 3/9] Update src/guild/Player.ts Co-authored-by: 0t4u <61939142+0t4u@users.noreply.github.com> --- src/guild/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 79d388c0..ac7bce82 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -261,7 +261,7 @@ export class Player extends EventEmitter { */ public async move({ name, force }: MoveOptions): Promise { const connection = this.node.manager.connections.get(this.guildId); - const node = this.node.manager.nodes.get(opts.name!) || this.node.manager.getIdealNode(connection); + const node = this.node.manager.nodes.get(name!) || this.node.manager.getIdealNode(connection); if (!node && ![ ...this.node.manager.nodes.values() ].some(node => node.state === State.CONNECTED)) throw new Error('No available nodes to move to'); From 7991cfa011c35ffc092dc40f2adadca40743ea37 Mon Sep 17 00:00:00 2001 From: Flavien <48295189+flav-code@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:16:39 +0200 Subject: [PATCH 4/9] Update src/guild/Player.ts Co-authored-by: 0t4u <61939142+0t4u@users.noreply.github.com> --- src/guild/Player.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index ac7bce82..7c6ca279 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -272,10 +272,11 @@ export class Player extends EventEmitter { if (!lastNode || lastNode.state !== State.CONNECTED) lastNode = this.node.manager.getIdealNode(connection); - if (!opts.force) + if (!force) { await this.destroy(); - else + } else { await this.destroy().catch(() => null); + } try { this.node = node; From f3dc83c934f51a2398b0e8832faca1758a1a302e Mon Sep 17 00:00:00 2001 From: Flavien <48295189+flav-code@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:16:46 +0200 Subject: [PATCH 5/9] Update src/guild/Player.ts Co-authored-by: 0t4u <61939142+0t4u@users.noreply.github.com> --- src/guild/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 7c6ca279..67af3376 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -232,7 +232,7 @@ export class Player extends EventEmitter { guildId: this.guildId, playerOptions: { track: { - encoded: this.track + encoded: this.track, }, position: this.position, paused: this.paused, From 39199bfff92128f7f1636a4ad63c2be082554562 Mon Sep 17 00:00:00 2001 From: Flavien <48295189+flav-code@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:16:52 +0200 Subject: [PATCH 6/9] Update src/guild/Player.ts Co-authored-by: 0t4u <61939142+0t4u@users.noreply.github.com> --- src/guild/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 67af3376..060480f8 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -249,7 +249,7 @@ export class Player extends EventEmitter { /** * Move player to another node - * @param opts An object that conforms to the MoveOptions type + * @param name Name of node to move to, or the default ideal node * @returns true if the player was moved, false if not */ public async move(name?: string): Promise { From af9392a6d324d8bc61476099d2f0f92c66d3ba31 Mon Sep 17 00:00:00 2001 From: flav-code Date: Sun, 4 Aug 2024 16:30:00 +0000 Subject: [PATCH 7/9] chore: remove { --- src/guild/Player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 060480f8..540e28da 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -252,7 +252,7 @@ export class Player extends EventEmitter { * @param name Name of node to move to, or the default ideal node * @returns true if the player was moved, false if not */ - public async move(name?: string): Promise { + public async move(name?: string): Promise /** * Move player to another node * @param options.name Name of node to move to, or the default ideal node From b9f29a458f6b4326f63505236051d8bf467ef669 Mon Sep 17 00:00:00 2001 From: flav-code Date: Mon, 12 Aug 2024 10:45:39 +0000 Subject: [PATCH 8/9] fix: remove overload --- src/guild/Player.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 540e28da..6f1cb6d1 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -247,19 +247,13 @@ export class Player extends EventEmitter { }; } - /** - * Move player to another node - * @param name Name of node to move to, or the default ideal node - * @returns true if the player was moved, false if not - */ - public async move(name?: string): Promise /** * Move player to another node * @param options.name Name of node to move to, or the default ideal node * @param options.force Force the move and ignore errors when destroying the original player fails (e.g. during Node disconnect) * @returns true if the player was moved, false if not */ - public async move({ name, force }: MoveOptions): Promise { + public async move({ name, force }: MoveOptions = {}): Promise { const connection = this.node.manager.connections.get(this.guildId); const node = this.node.manager.nodes.get(name!) || this.node.manager.getIdealNode(connection); From 22d570410beae2ebb862dc42dbac51de49cc2dbf Mon Sep 17 00:00:00 2001 From: flav-code Date: Mon, 12 Aug 2024 10:46:50 +0000 Subject: [PATCH 9/9] refactor: Make setFilterVolume and setEqualizer methods public in Player.ts --- src/guild/Player.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/guild/Player.ts b/src/guild/Player.ts index 6f1cb6d1..e7ff0486 100644 --- a/src/guild/Player.ts +++ b/src/guild/Player.ts @@ -334,7 +334,7 @@ export class Player extends EventEmitter { * Sets the filter volume of the player * @param volume Target volume 0.0-5.0 */ - async setFilterVolume(volume: number): Promise { + public setFilterVolume(volume: number): Promise { return this.setFilters({ volume }); } @@ -342,7 +342,7 @@ export class Player extends EventEmitter { * Change the equalizer settings applied to the currently playing track * @param equalizer An array of objects that conforms to the Bands type that define volumes at different frequencies */ - public async setEqualizer(equalizer: Band[]): Promise { + public setEqualizer(equalizer: Band[]): Promise { return this.setFilters({ equalizer }); }