blob: e48f6039a7661884957840b0148b628f500cfe14 (
plain)
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
|
const { EmbedBuilder } = require('discord.js');
const { playSong, getCurrentProgress, formatDuration, safeCleanup } = require('../utils/player');
const { getQueueOrReply } = require('../utils/helpers');
function handleSeek(interaction, queues) {
const queue = getQueueOrReply(interaction, queues, 'Nothing is playing!');
if (!queue || queue.songs.length === 0) {
if (queue) interaction.reply('Nothing is playing!');
return;
}
if (queue.isSeeking) {
return interaction.reply('Already seeking, please wait!');
}
const seconds = interaction.options.getInteger('seconds');
const progress = getCurrentProgress(queue);
if (!progress) {
return interaction.reply('Cannot seek right now!');
}
let newPosition = progress.elapsed + seconds;
const song = queue.songs[0];
if (newPosition < 0) {
newPosition = 0;
}
if (newPosition >= song.duration) {
queue.player.stop();
return interaction.reply('Skipped to next song!');
}
queue.isSeeking = true;
safeCleanup(queue, 'Seek');
queue.player.stop();
console.log(`[SEEK] Guild: ${interaction.guild.id}, From: ${progress.elapsed}s, To: ${newPosition}s`);
playSong(interaction.guild.id, queue, newPosition);
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setDescription(`⏩ Seeking to ${formatDuration(newPosition)} / ${formatDuration(song.duration)}`);
interaction.reply({ embeds: [embed] });
}
module.exports = { handleSeek };
|