blob: f4f11729e2bfe2583844d1cc0c7f48233e602df1 (
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
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
|
import {CommandInteraction} from 'discord.js';
import {SlashCommandBuilder} from '@discordjs/builders';
import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player.js';
import errorMsg from '../utils/error-msg.js';
import Command from '.';
import {prettyTime} from '../utils/time.js';
@injectable()
export default class implements Command {
public readonly slashCommand = new SlashCommandBuilder()
.setName('fseek')
.setDescription('seek forward in the current song')
.addNumberOption(option => option
.setName('seconds')
.setDescription('the number of seconds to skip forward')
.setRequired(true));
public requiresVC = true;
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.playerManager = playerManager;
}
public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent();
if (!currentSong) {
await interaction.reply({
content: errorMsg('nothing is playing'),
ephemeral: true,
});
return;
}
if (currentSong.isLive) {
await interaction.reply({
content: errorMsg('can\'t seek in a livestream'),
ephemeral: true,
});
return;
}
const seekTime = interaction.options.getNumber('seconds');
if (!seekTime) {
await interaction.reply({
content: errorMsg('missing number of seconds to seek'),
ephemeral: true,
});
return;
}
if (seekTime + player.getPosition() > currentSong.length) {
await interaction.reply({
content: errorMsg('can\'t seek past the end of the song'),
ephemeral: true,
});
return;
}
await Promise.all([
player.forwardSeek(seekTime),
interaction.deferReply(),
]);
await interaction.editReply(`👍 seeked to ${prettyTime(player.getPosition())}`);
}
}
|