Update queueManager.js

This commit is contained in:
Wizzard 2024-08-17 16:53:07 -04:00
parent fb027bc7a6
commit 4ccc75d38b
1 changed files with 22 additions and 5 deletions

View File

@ -5,12 +5,23 @@ const queueMap = new Map();
const playerMap = new Map();
const currentTrackMap = new Map();
const repeatMap = new Map();
const voiceChannelMap = new Map();
function addToQueue(guildId, filePath, title) {
function addToQueue(guildId, filePath, title, voiceChannel) {
if (!queueMap.has(guildId)) {
queueMap.set(guildId, []);
}
queueMap.get(guildId).push({ filePath, title });
if (voiceChannel) {
voiceChannelMap.set(guildId, voiceChannel);
}
const audioPlayer = playerMap.get(guildId);
if (!audioPlayer || audioPlayer.state.status !== AudioPlayerStatus.Playing) {
playNextInQueue(guildId);
}
}
function getQueue(guildId) {
@ -27,10 +38,16 @@ function toggleRepeat(guildId) {
return !currentRepeat;
}
function playNextInQueue(guildId, voiceChannel) {
function playNextInQueue(guildId) {
const queue = getQueue(guildId);
const currentTrack = getCurrentTrack(guildId);
const repeat = repeatMap.get(guildId);
const voiceChannel = voiceChannelMap.get(guildId);
if (!voiceChannel) {
console.error("Voice channel is undefined. Cannot play track.");
return false;
}
if (currentTrack && !repeat) {
return false;
@ -85,7 +102,7 @@ function playTrack(guildId, voiceChannel, track) {
const queue = getQueue(guildId);
if (queue.length > 0 || repeatMap.get(guildId)) {
playNextInQueue(guildId, voiceChannel);
playNextInQueue(guildId);
} else {
if (connection && connection.state.status !== 'destroyed') {
connection.destroy();
@ -102,7 +119,7 @@ function playTrack(guildId, voiceChannel, track) {
});
}
function skipTrack(guildId, voiceChannel) {
function skipTrack(guildId) {
const player = playerMap.get(guildId);
const queue = getQueue(guildId);
@ -115,7 +132,7 @@ function skipTrack(guildId, voiceChannel) {
player.stop();
if (queue.length > 0) {
playNextInQueue(guildId, voiceChannel);
playNextInQueue(guildId);
} else {
const connection = playerMap.get(guildId)?._state?.subscription?.connection;
if (connection && connection.state.status !== 'destroyed') {