From d1abe19c8822304b99bcf91a05848138bbcf504f Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 17 Aug 2024 18:14:47 -0400 Subject: [PATCH] Store user profile picture and name for requester --- commands/np.js | 3 +-- commands/play.js | 10 +++++----- utils/queueManager.js | 6 ++++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/commands/np.js b/commands/np.js index 118ddb7..992d8d6 100644 --- a/commands/np.js +++ b/commands/np.js @@ -19,7 +19,6 @@ module.exports = { const currentTime = player.state?.resource?.playbackDuration || 0; const totalDuration = getTrackDuration(currentTrack.filePath); - const timeLeft = msToTime(totalDuration - currentTime); const embed = new EmbedBuilder() @@ -29,7 +28,7 @@ module.exports = { .addFields( { name: 'Time Left', value: timeLeft }, ) - .setFooter({ text: `Requested by ${message.author.username}`, iconURL: message.author.displayAvatarURL() }) + .setFooter({ text: `Requested by ${currentTrack.requester}`, iconURL: currentTrack.avatarURL }) .setTimestamp(); message.channel.send({ embeds: [embed] }); diff --git a/commands/play.js b/commands/play.js index f79bd34..80bdff7 100644 --- a/commands/play.js +++ b/commands/play.js @@ -50,7 +50,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, message.author.username, message.author.displayAvatarURL()); playNextInQueue(message.guild.id); return; } else { @@ -84,7 +84,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, message.author.username, message.author.displayAvatarURL()); playNextInQueue(message.guild.id); return; } else if (searchQuery.includes("cdn.discordapp.com")) { @@ -111,7 +111,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, message.author.username, message.author.displayAvatarURL()); playNextInQueue(message.guild.id); return; } else { @@ -148,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, videoUrl); + addToQueue(message.guild.id, tempFilePath, title, voiceChannel, videoUrl, message.author.username, message.author.displayAvatarURL()); playNextInQueue(message.guild.id); }); }); @@ -189,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, videoUrl); + addToQueue(message.guild.id, tempFilePath, title, voiceChannel, videoUrl, message.author.username, message.author.displayAvatarURL()); playNextInQueue(message.guild.id); }); }); diff --git a/utils/queueManager.js b/utils/queueManager.js index d007ca5..417eea9 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, url = null) { +function addToQueue(guildId, filePath, title, voiceChannel, url, requester, avatarURL) { if (!queueMap.has(guildId)) { queueMap.set(guildId, []); } - queueMap.get(guildId).push({ filePath, title, url }); + queueMap.get(guildId).push({ filePath, title, url, requester, avatarURL }); if (voiceChannel) { voiceChannelMap.set(guildId, voiceChannel); @@ -106,6 +106,8 @@ function playTrack(guildId, voiceChannel, track) { audioPlayer.play(resource); connection.subscribe(audioPlayer); + currentTrackMap.set(guildId, { ...track, resource }); + audioPlayer.on(AudioPlayerStatus.Idle, () => { if (!repeatMap.get(guildId)) { currentTrackMap.delete(guildId);