Compare commits
No commits in common. "4ccc75d38b56dd86bf1cf12351a14e3e78233f73" and "f4788940020cd83331c34206e662e90ca5e87dde" have entirely different histories.
4ccc75d38b
...
f478894002
|
@ -45,8 +45,8 @@ module.exports = {
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath, title, voiceChannel);
|
addToQueue(message.guild.id, tempFilePath, title);
|
||||||
playNextInQueue(message.guild.id);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return message.reply('Only MP3 files are supported for uploads.');
|
return message.reply('Only MP3 files are supported for uploads.');
|
||||||
|
@ -54,12 +54,12 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValidURL(searchQuery)) {
|
if (isValidURL(searchQuery)) {
|
||||||
if (searchQuery.endsWith('.mp3')) {
|
if (searchQuery.includes('cdn.discordapp.com')) {
|
||||||
title = path.basename(searchQuery.split('?')[0]);
|
title = path.basename(searchQuery.split('?')[0]);
|
||||||
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}_${title}`);
|
tempFilePath = path.join(__dirname, '../utils/tmp', title);
|
||||||
|
|
||||||
console.log(`MP3 link received: ${searchQuery}`);
|
console.log(`Discord CDN link received: ${searchQuery}`);
|
||||||
console.log(`Downloading MP3 to: ${tempFilePath}`);
|
console.log(`Downloading to: ${tempFilePath}`);
|
||||||
|
|
||||||
const response = await fetch(searchQuery);
|
const response = await fetch(searchQuery);
|
||||||
if (!response.ok) throw new Error('Failed to download MP3 file.');
|
if (!response.ok) throw new Error('Failed to download MP3 file.');
|
||||||
|
@ -77,18 +77,18 @@ module.exports = {
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath, title, voiceChannel);
|
addToQueue(message.guild.id, tempFilePath, title);
|
||||||
playNextInQueue(message.guild.id);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
return;
|
return;
|
||||||
} else if (searchQuery.includes("cdn.discordapp.com")) {
|
} else if (searchQuery.endsWith('.mp3')) {
|
||||||
title = path.basename(searchQuery.split('?')[0]);
|
title = path.basename(searchQuery.split('?')[0]);
|
||||||
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}_${title}`);
|
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}_${title}`);
|
||||||
|
|
||||||
console.log(`Discord MP3 link received: ${searchQuery}`);
|
console.log(`Direct MP3 link received: ${searchQuery}`);
|
||||||
console.log(`Downloading MP3 from Discord to: ${tempFilePath}`);
|
console.log(`Downloading to: ${tempFilePath}`);
|
||||||
|
|
||||||
const response = await fetch(searchQuery);
|
const response = await fetch(searchQuery);
|
||||||
if (!response.ok) throw new Error('Failed to download MP3 file from Discord.');
|
if (!response.ok) throw new Error('Failed to download MP3 file.');
|
||||||
const buffer = await response.buffer();
|
const buffer = await response.buffer();
|
||||||
fs.writeFileSync(tempFilePath, buffer);
|
fs.writeFileSync(tempFilePath, buffer);
|
||||||
|
|
||||||
|
@ -103,12 +103,14 @@ module.exports = {
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath, title, voiceChannel);
|
addToQueue(message.guild.id, tempFilePath, title);
|
||||||
playNextInQueue(message.guild.id);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
||||||
|
|
||||||
|
console.log(`YouTube link received: ${searchQuery}`);
|
||||||
|
|
||||||
exec(`yt-dlp --print title ${searchQuery}`, (error, stdout, stderr) => {
|
exec(`yt-dlp --print title ${searchQuery}`, (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`Error getting title: ${error}`);
|
console.error(`Error getting title: ${error}`);
|
||||||
|
@ -126,6 +128,8 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Downloaded and saved: ${tempFilePath}`);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor('#0099ff')
|
.setColor('#0099ff')
|
||||||
.setTitle('Now Playing')
|
.setTitle('Now Playing')
|
||||||
|
@ -135,8 +139,8 @@ module.exports = {
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath, title, voiceChannel);
|
addToQueue(message.guild.id, tempFilePath, title);
|
||||||
playNextInQueue(message.guild.id);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -162,6 +166,8 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Downloaded and saved: ${tempFilePath}`);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor('#0099ff')
|
.setColor('#0099ff')
|
||||||
.setTitle('Now Playing')
|
.setTitle('Now Playing')
|
||||||
|
@ -171,8 +177,8 @@ module.exports = {
|
||||||
|
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
addToQueue(message.guild.id, tempFilePath, title, voiceChannel);
|
addToQueue(message.guild.id, tempFilePath, title);
|
||||||
playNextInQueue(message.guild.id);
|
playNextInQueue(message.guild.id, voiceChannel);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,12 @@ const queueMap = new Map();
|
||||||
const playerMap = new Map();
|
const playerMap = new Map();
|
||||||
const currentTrackMap = new Map();
|
const currentTrackMap = new Map();
|
||||||
const repeatMap = new Map();
|
const repeatMap = new Map();
|
||||||
const voiceChannelMap = new Map();
|
|
||||||
|
|
||||||
function addToQueue(guildId, filePath, title, voiceChannel) {
|
function addToQueue(guildId, filePath, title) {
|
||||||
if (!queueMap.has(guildId)) {
|
if (!queueMap.has(guildId)) {
|
||||||
queueMap.set(guildId, []);
|
queueMap.set(guildId, []);
|
||||||
}
|
}
|
||||||
queueMap.get(guildId).push({ filePath, title });
|
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) {
|
function getQueue(guildId) {
|
||||||
|
@ -38,16 +27,10 @@ function toggleRepeat(guildId) {
|
||||||
return !currentRepeat;
|
return !currentRepeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
function playNextInQueue(guildId) {
|
function playNextInQueue(guildId, voiceChannel) {
|
||||||
const queue = getQueue(guildId);
|
const queue = getQueue(guildId);
|
||||||
const currentTrack = getCurrentTrack(guildId);
|
const currentTrack = getCurrentTrack(guildId);
|
||||||
const repeat = repeatMap.get(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) {
|
if (currentTrack && !repeat) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -102,7 +85,7 @@ function playTrack(guildId, voiceChannel, track) {
|
||||||
|
|
||||||
const queue = getQueue(guildId);
|
const queue = getQueue(guildId);
|
||||||
if (queue.length > 0 || repeatMap.get(guildId)) {
|
if (queue.length > 0 || repeatMap.get(guildId)) {
|
||||||
playNextInQueue(guildId);
|
playNextInQueue(guildId, voiceChannel);
|
||||||
} else {
|
} else {
|
||||||
if (connection && connection.state.status !== 'destroyed') {
|
if (connection && connection.state.status !== 'destroyed') {
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
|
@ -119,7 +102,7 @@ function playTrack(guildId, voiceChannel, track) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function skipTrack(guildId) {
|
function skipTrack(guildId, voiceChannel) {
|
||||||
const player = playerMap.get(guildId);
|
const player = playerMap.get(guildId);
|
||||||
const queue = getQueue(guildId);
|
const queue = getQueue(guildId);
|
||||||
|
|
||||||
|
@ -132,7 +115,7 @@ function skipTrack(guildId) {
|
||||||
player.stop();
|
player.stop();
|
||||||
|
|
||||||
if (queue.length > 0) {
|
if (queue.length > 0) {
|
||||||
playNextInQueue(guildId);
|
playNextInQueue(guildId, voiceChannel);
|
||||||
} else {
|
} else {
|
||||||
const connection = playerMap.get(guildId)?._state?.subscription?.connection;
|
const connection = playerMap.get(guildId)?._state?.subscription?.connection;
|
||||||
if (connection && connection.state.status !== 'destroyed') {
|
if (connection && connection.state.status !== 'destroyed') {
|
||||||
|
|
Loading…
Reference in New Issue