Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed building saved queue, as not all songs are stored as build/resolved #308

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class Manager extends EventEmitter {

for (const file of playerFiles) {
const filePath = path.join(playerStatesDir, file);

if (!fs.existsSync(filePath)) {
console.warn(`File not found: ${filePath}. Skipping...`);
continue;
}

const data = fs.readFileSync(filePath, "utf-8");
const state = JSON.parse(data);

Expand All @@ -106,9 +112,8 @@ export class Manager extends EventEmitter {
volume: lavaPlayer.volume || state.options.volume,
};

this.create(playerOptions);
const player = this.create(playerOptions);

const player = this.get(state.options.guild);
if (!lavaPlayer.state.connected) {
try {
player.connect();
Expand All @@ -125,29 +130,29 @@ export class Manager extends EventEmitter {
for (const key in state.queue) {
if (!isNaN(Number(key)) && key !== "current" && key !== "previous" && key !== "manager") {
const song = state.queue[key];
tracks.push(TrackUtils.build(createTrackData(song), song.requester));
tracks.push(TrackUtils.buildUnresolved(song, song.requester));
}
}

if (tracks.length > 0) {
if (player.state !== "CONNECTED") player.connect();
player.queue.add(tracks);
if (!state.paused && player.state === "CONNECTED") player.play();
else console.log(player.state);
if (!state.paused && lavaPlayer.state.connected) player.play();
} else {
const payload = {
reason: "finished",
};
node.queueEnd(player, state.queue.current, payload as TrackEndEvent);
continue;
}
} else {
if (state.queue.previous !== null) {
const payload = {
reason: "finished",
};
node.queueEnd(player, state.queue.previous, payload as TrackEndEvent);
} else this.destroy(state.guild);
} else {
this.destroy(state.guild);
continue;
}
}
} else {
const currentTrack = state.queue.current;
Expand All @@ -156,10 +161,9 @@ export class Manager extends EventEmitter {
for (const key in state.queue) {
if (!isNaN(Number(key)) && key !== "current" && key !== "previous" && key !== "manager") {
const song = state.queue[key];
tracks.push(TrackUtils.build(createTrackData(song), song.requester));
tracks.push(TrackUtils.buildUnresolved(song, song.requester));
}
}
if (player.state !== "CONNECTED") player.connect();
player.queue.add(tracks);
}

Expand Down
Loading