const { playSong, safeCleanup, clearSongBuffer } = require('../utils/player'); const { getQueueOrReply } = require('../utils/helpers'); function handlePause(interaction, queues) { const queue = getQueueOrReply(interaction, queues, 'Nothing is playing!'); if (!queue) return; queue.player.pause(); interaction.reply('Paused!'); } function handleResume(interaction, queues) { const queue = getQueueOrReply(interaction, queues, 'Nothing is paused!'); if (!queue) return; queue.player.unpause(); interaction.reply('Resumed!'); } function handleSkip(interaction, queues) { const queue = getQueueOrReply(interaction, queues, 'Nothing to skip!'); if (!queue || queue.songs.length === 0) { if (queue) interaction.reply('Nothing to skip!'); return; } const playerState = queue.player.state.status; console.log(`[SKIP] Guild: ${interaction.guild.id}, Skipping: ${queue.songs[0]?.title}, Player state: ${playerState}, Queue length: ${queue.songs.length}`); clearSongBuffer(queue.songs[0], 'skipped'); safeCleanup(queue, 'Skip'); queue.player.stop(); interaction.reply(`Skipped! (${queue.songs.length - 1} songs remaining)`); } function handleClear(interaction, queues) { const queue = getQueueOrReply(interaction, queues, 'Queue is already empty!'); if (!queue || queue.songs.length === 0) { if (queue) interaction.reply('Queue is already empty!'); return; } const currentSong = queue.songs[0]; const clearedCount = queue.songs.length - 1; for (let i = 1; i < queue.songs.length; i++) { clearSongBuffer(queue.songs[i], 'queue cleared'); } queue.songs = [currentSong]; console.log(`[QUEUE] Cleared ${clearedCount} songs from queue`); interaction.reply(`Cleared queue! Only current song remains: ${currentSong.title}`); } function handleLoop(interaction, queues) { const queue = getQueueOrReply(interaction, queues); if (!queue) return; const mode = interaction.options.getString('mode'); if (mode) { queue.loopMode = mode; } else { const modes = ['off', 'song', 'queue']; const currentIndex = modes.indexOf(queue.loopMode || 'off'); queue.loopMode = modes[(currentIndex + 1) % modes.length]; } const modeEmojis = { off: 'Loop disabled', song: 'Looping current song', queue: 'Looping queue' }; interaction.reply(modeEmojis[queue.loopMode]); } function handleQuit(interaction, queues) { const queue = getQueueOrReply(interaction, queues); if (!queue) return; try { queue.player.stop(); } catch (e) {} safeCleanup(queue, 'Quit'); queue.connection.destroy(); queues.delete(interaction.guild.id); interaction.reply('Left voice channel!'); } module.exports = { handlePause, handleResume, handleSkip, handleClear, handleLoop, handleQuit, };