From 566d7461b02d3be063f1fabeccc14e8cd40fec0f Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 17 Aug 2024 17:56:35 -0400 Subject: [PATCH] Make youtube links clickable --- commands/play.js | 8 +++++--- commands/queue.js | 14 ++++++++++++-- utils/queueManager.js | 4 ++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/commands/play.js b/commands/play.js index 37c21fd..f79bd34 100644 --- a/commands/play.js +++ b/commands/play.js @@ -21,7 +21,7 @@ module.exports = { return message.reply('You need to be in a voice channel to play music!'); } - let title, tempFilePath; + let title, tempFilePath, videoUrl; try { if (message.attachments.size > 0) { @@ -116,6 +116,7 @@ module.exports = { return; } else { tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`); + videoUrl = searchQuery; console.log(`YouTube link received: ${searchQuery}`); exec(`yt-dlp --cookies ${path.join(__dirname, '../cookies.txt')} --print title ${searchQuery}`, (error, stdout, stderr) => { @@ -147,7 +148,7 @@ module.exports = { message.channel.send({ embeds: [embed] }); console.log('Adding to queue and attempting to play.'); - addToQueue(message.guild.id, tempFilePath, title, voiceChannel); + addToQueue(message.guild.id, tempFilePath, title, voiceChannel, videoUrl); playNextInQueue(message.guild.id); }); }); @@ -164,6 +165,7 @@ module.exports = { const info = JSON.parse(stdout); const url = info.entries[0].webpage_url; title = info.entries[0].title; + videoUrl = url; tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`); console.log(`Downloading file to: ${tempFilePath}`); @@ -187,7 +189,7 @@ module.exports = { message.channel.send({ embeds: [embed] }); console.log('Adding to queue and attempting to play.'); - addToQueue(message.guild.id, tempFilePath, title, voiceChannel); + addToQueue(message.guild.id, tempFilePath, title, voiceChannel, videoUrl); playNextInQueue(message.guild.id); }); }); diff --git a/commands/queue.js b/commands/queue.js index 29c02ec..11f6e49 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -13,13 +13,23 @@ module.exports = { .setTitle('Current Queue'); if (currentTrack) { - embed.addFields({ name: 'Currently playing', value: `${currentTrack.title}`, inline: false }); + const currentTrackDisplay = currentTrack.url + ? `[${currentTrack.title}](${currentTrack.url})` + : currentTrack.title; + embed.addFields({ name: 'Currently playing', value: currentTrackDisplay, inline: false }); } if (queue.length > 0) { + const queueDisplay = queue.map((track, index) => { + const trackDisplay = track.url + ? `[${track.title}](${track.url})` + : track.title; + return `${index + 1}. ${trackDisplay}`; + }).join('\n'); + embed.addFields({ name: 'Up next', - value: queue.map((track, index) => `${index + 1}. ${track.title}`).join('\n'), + value: queueDisplay, inline: false }); } else if (!currentTrack) { diff --git a/utils/queueManager.js b/utils/queueManager.js index 9c53a3e..f1b2d0d 100644 --- a/utils/queueManager.js +++ b/utils/queueManager.js @@ -7,11 +7,11 @@ const currentTrackMap = new Map(); const repeatMap = new Map(); const voiceChannelMap = new Map(); -function addToQueue(guildId, filePath, title, voiceChannel) { +function addToQueue(guildId, filePath, title, voiceChannel, url = null) { if (!queueMap.has(guildId)) { queueMap.set(guildId, []); } - queueMap.get(guildId).push({ filePath, title }); + queueMap.get(guildId).push({ filePath, title, url }); if (voiceChannel) { voiceChannelMap.set(guildId, voiceChannel);