Skip to content

Commit

Permalink
fix(queue): not self-ending
Browse files Browse the repository at this point in the history
Fixes #1344
  • Loading branch information
eritislami committed Jan 23, 2023
1 parent c81f714 commit 36a4083
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions structs/MusicQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MusicQueue {
public waitTimeout: NodeJS.Timeout | null;
private queueLock = false;
private readyLock = false;
private stopped = false;

public constructor(options: QueueOptions) {
Object.assign(this, options);
Expand Down Expand Up @@ -85,6 +86,7 @@ export class MusicQueue {
this.songs.push(this.songs.shift()!);
} else {
this.songs.shift();
if (!this.songs.length) return this.stop();
}

if (this.songs.length || this.resource.audioPlayer) this.processQueue();
Expand All @@ -95,23 +97,29 @@ export class MusicQueue {

this.player.on("error", (error) => {
console.error(error);

if (this.loop && this.songs.length) {
this.songs.push(this.songs.shift()!);
} else {
this.songs.shift();
}

this.processQueue();
});
}

public enqueue(...songs: Song[]) {
if (this.waitTimeout !== null) clearTimeout(this.waitTimeout);
this.waitTimeout = null;
this.stopped = false;
this.songs = this.songs.concat(songs);
this.processQueue();
}

public stop() {
if (this.stopped) return;

this.stopped = true;
this.loop = false;
this.songs = [];
this.player.stop();
Expand Down

0 comments on commit 36a4083

Please sign in to comment.