1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
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,
};
|