Make youtube links clickable
This commit is contained in:
parent
4b13b17388
commit
566d7461b0
|
@ -21,7 +21,7 @@ module.exports = {
|
||||||
return message.reply('You need to be in a voice channel to play music!');
|
return message.reply('You need to be in a voice channel to play music!');
|
||||||
}
|
}
|
||||||
|
|
||||||
let title, tempFilePath;
|
let title, tempFilePath, videoUrl;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (message.attachments.size > 0) {
|
if (message.attachments.size > 0) {
|
||||||
|
@ -116,6 +116,7 @@ module.exports = {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
||||||
|
videoUrl = searchQuery;
|
||||||
|
|
||||||
console.log(`YouTube link received: ${searchQuery}`);
|
console.log(`YouTube link received: ${searchQuery}`);
|
||||||
exec(`yt-dlp --cookies ${path.join(__dirname, '../cookies.txt')} --print title ${searchQuery}`, (error, stdout, stderr) => {
|
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] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
console.log('Adding to queue and attempting to play.');
|
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);
|
playNextInQueue(message.guild.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -164,6 +165,7 @@ module.exports = {
|
||||||
const info = JSON.parse(stdout);
|
const info = JSON.parse(stdout);
|
||||||
const url = info.entries[0].webpage_url;
|
const url = info.entries[0].webpage_url;
|
||||||
title = info.entries[0].title;
|
title = info.entries[0].title;
|
||||||
|
videoUrl = url;
|
||||||
|
|
||||||
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
tempFilePath = path.join(__dirname, '../utils/tmp', `${uuidv4()}.mp3`);
|
||||||
console.log(`Downloading file to: ${tempFilePath}`);
|
console.log(`Downloading file to: ${tempFilePath}`);
|
||||||
|
@ -187,7 +189,7 @@ module.exports = {
|
||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
|
|
||||||
console.log('Adding to queue and attempting to play.');
|
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);
|
playNextInQueue(message.guild.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,13 +13,23 @@ module.exports = {
|
||||||
.setTitle('Current Queue');
|
.setTitle('Current Queue');
|
||||||
|
|
||||||
if (currentTrack) {
|
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) {
|
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({
|
embed.addFields({
|
||||||
name: 'Up next',
|
name: 'Up next',
|
||||||
value: queue.map((track, index) => `${index + 1}. ${track.title}`).join('\n'),
|
value: queueDisplay,
|
||||||
inline: false
|
inline: false
|
||||||
});
|
});
|
||||||
} else if (!currentTrack) {
|
} else if (!currentTrack) {
|
||||||
|
|
|
@ -7,11 +7,11 @@ const currentTrackMap = new Map();
|
||||||
const repeatMap = new Map();
|
const repeatMap = new Map();
|
||||||
const voiceChannelMap = new Map();
|
const voiceChannelMap = new Map();
|
||||||
|
|
||||||
function addToQueue(guildId, filePath, title, voiceChannel) {
|
function addToQueue(guildId, filePath, title, voiceChannel, url = null) {
|
||||||
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, url });
|
||||||
|
|
||||||
if (voiceChannel) {
|
if (voiceChannel) {
|
||||||
voiceChannelMap.set(guildId, voiceChannel);
|
voiceChannelMap.set(guildId, voiceChannel);
|
||||||
|
|
Loading…
Reference in New Issue