blob: 97d6a9810442f81f2d25b62289ae581403221f6f (
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
|
import {ChatInputCommandInteraction} from 'discord.js';
import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player.js';
import Command from './index.js';
import {parseTime, prettyTime} from '../utils/time.js';
import {SlashCommandBuilder} from '@discordjs/builders';
import durationStringToSeconds from '../utils/duration-string-to-seconds.js';
@injectable()
export default class implements Command {
public readonly slashCommand = new SlashCommandBuilder()
.setName('seek')
.setDescription('seek to a position from beginning of song')
.addStringOption(option =>
option.setName('time')
.setDescription('an interval expression or number of seconds (1m, 30s, 100)')
.setRequired(true),
);
public requiresVC = true;
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.playerManager = playerManager;
}
public async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent();
if (!currentSong) {
throw new Error('nothing is playing');
}
if (currentSong.isLive) {
throw new Error('can\'t seek in a livestream');
}
const time = interaction.options.getString('time')!;
let seekTime = 0;
if (time.includes(':')) {
seekTime = parseTime(time);
} else {
seekTime = durationStringToSeconds(time);
}
if (seekTime > currentSong.length) {
throw new Error('can\'t seek past the end of the song');
}
await Promise.all([
player.seek(seekTime),
interaction.deferReply(),
]);
await interaction.editReply(`👍 seeked to ${prettyTime(player.getPosition())}`);
}
}
|