Don't allow seeking past end of song

This commit is contained in:
Max Isom 2020-03-18 12:40:31 -05:00
parent 7844e80991
commit 11246812a6
6 changed files with 40 additions and 17 deletions

View file

@ -25,18 +25,25 @@ export default class implements Command {
public async execute(msg: Message, args: string []): Promise<void> {
const queue = this.queueManager.get(msg.guild!.id);
if (!queue.getCurrent()) {
const currentSong = queue.getCurrent();
if (!currentSong) {
await msg.channel.send(errorMsg('nothing is playing'));
return;
}
if (queue.getCurrent()?.isLive) {
if (currentSong.isLive) {
await msg.channel.send(errorMsg('can\'t seek in a livestream'));
return;
}
const seekTime = parseInt(args[0], 10);
if (seekTime + this.playerManager.get(msg.guild!.id).getPosition() > currentSong.length) {
await msg.channel.send(errorMsg('can\'t seek past the end of the song'));
return;
}
const loading = new LoadingMessage(msg.channel as TextChannel);
await loading.start();