From 1af2e8780980e635fe0ddf9cf98c53f87633e44c Mon Sep 17 00:00:00 2001 From: Wizzard Date: Sat, 17 Aug 2024 18:05:36 -0400 Subject: [PATCH] Remove command --- commands/queue.js | 6 +++--- commands/remove.js | 22 ++++++++++++++++++++++ utils/queueManager.js | 12 +++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 commands/remove.js diff --git a/commands/queue.js b/commands/queue.js index 11f6e49..121f491 100644 --- a/commands/queue.js +++ b/commands/queue.js @@ -22,9 +22,9 @@ module.exports = { if (queue.length > 0) { const queueDisplay = queue.map((track, index) => { const trackDisplay = track.url - ? `[${track.title}](${track.url})` - : track.title; - return `${index + 1}. ${trackDisplay}`; + ? `**${index + 1}.** [${track.title}](${track.url})` + : `**${index + 1}.** ${track.title}`; + return trackDisplay; }).join('\n'); embed.addFields({ diff --git a/commands/remove.js b/commands/remove.js new file mode 100644 index 0000000..0a3b85b --- /dev/null +++ b/commands/remove.js @@ -0,0 +1,22 @@ +const { getQueue, removeFromQueue } = require('../utils/queueManager'); + +module.exports = { + name: 'remove', + description: 'Remove a specific song from the queue by its number', + execute(message, args) { + const queue = getQueue(message.guild.id); + const indexToRemove = parseInt(args[0], 10) - 1; + + if (isNaN(indexToRemove) || indexToRemove < 0 || indexToRemove >= queue.length) { + return message.reply('Please provide a valid song number to remove.'); + } + + const removedTrack = removeFromQueue(message.guild.id, indexToRemove); + + if (removedTrack) { + message.reply(`Removed **${removedTrack.title}** from the queue.`); + } else { + message.reply('There was an issue removing the song from the queue.'); + } + }, +}; \ No newline at end of file diff --git a/utils/queueManager.js b/utils/queueManager.js index f1b2d0d..5d69cfd 100644 --- a/utils/queueManager.js +++ b/utils/queueManager.js @@ -24,6 +24,16 @@ function addToQueue(guildId, filePath, title, voiceChannel, url = null) { } } +function removeFromQueue(guildId, index) { + const queue = getQueue(guildId); + + if (index >= 0 && index < queue.length) { + return queue.splice(index, 1)[0]; + } + + return null; +} + function getQueue(guildId) { return queueMap.get(guildId) || []; } @@ -145,4 +155,4 @@ function clearQueue(guildId) { queueMap.set(guildId, []); } -module.exports = { addToQueue, getQueue, getCurrentTrack, playNextInQueue, skipTrack, toggleRepeat, clearQueue }; \ No newline at end of file +module.exports = { addToQueue, getQueue, getCurrentTrack, playNextInQueue, skipTrack, toggleRepeat, clearQueue, removeFromQueue }; \ No newline at end of file