mirror of
https://github.com/BluemediaGER/muse.git
synced 2024-11-10 03:55:29 +01:00
Migrate fseek command
This commit is contained in:
parent
c33526b8b7
commit
cbc9aafe78
|
@ -1,18 +1,21 @@
|
||||||
import {Message, TextChannel} from 'discord.js';
|
import {CommandInteraction} from 'discord.js';
|
||||||
|
import {SlashCommandBuilder} from '@discordjs/builders';
|
||||||
import {TYPES} from '../types.js';
|
import {TYPES} from '../types.js';
|
||||||
import {inject, injectable} from 'inversify';
|
import {inject, injectable} from 'inversify';
|
||||||
import PlayerManager from '../managers/player.js';
|
import PlayerManager from '../managers/player.js';
|
||||||
import LoadingMessage from '../utils/loading-message.js';
|
|
||||||
import errorMsg from '../utils/error-msg.js';
|
import errorMsg from '../utils/error-msg.js';
|
||||||
import Command from '.';
|
import Command from '.';
|
||||||
|
import {prettyTime} from '../utils/time.js';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export default class implements Command {
|
export default class implements Command {
|
||||||
public name = 'fseek';
|
public readonly slashCommand = new SlashCommandBuilder()
|
||||||
public aliases = [];
|
.setName('fseek')
|
||||||
public examples = [
|
.setDescription('seek forward in the current song')
|
||||||
['fseek 10', 'skips forward in current song by 10 seconds'],
|
.addNumberOption(option => option
|
||||||
];
|
.setName('seconds')
|
||||||
|
.setDescription('the number of seconds to skip forward')
|
||||||
|
.setRequired(true));
|
||||||
|
|
||||||
public requiresVC = true;
|
public requiresVC = true;
|
||||||
|
|
||||||
|
@ -22,38 +25,54 @@ export default class implements Command {
|
||||||
this.playerManager = playerManager;
|
this.playerManager = playerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async execute(msg: Message, args: string []): Promise<void> {
|
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> {
|
||||||
const player = this.playerManager.get(msg.guild!.id);
|
const player = this.playerManager.get(interaction.guild!.id);
|
||||||
|
|
||||||
const currentSong = player.getCurrent();
|
const currentSong = player.getCurrent();
|
||||||
|
|
||||||
if (!currentSong) {
|
if (!currentSong) {
|
||||||
await msg.channel.send(errorMsg('nothing is playing'));
|
await interaction.reply({
|
||||||
|
content: errorMsg('nothing is playing'),
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentSong.isLive) {
|
if (currentSong.isLive) {
|
||||||
await msg.channel.send(errorMsg('can\'t seek in a livestream'));
|
await interaction.reply({
|
||||||
|
content: errorMsg('can\'t seek in a livestream'),
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const seekTime = parseInt(args[0], 10);
|
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) {
|
if (seekTime + player.getPosition() > currentSong.length) {
|
||||||
await msg.channel.send(errorMsg('can\'t seek past the end of the song'));
|
await interaction.reply({
|
||||||
|
content: errorMsg('can\'t seek past the end of the song'),
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const loading = new LoadingMessage(msg.channel as TextChannel);
|
await Promise.all([
|
||||||
|
player.forwardSeek(seekTime),
|
||||||
|
interaction.deferReply(),
|
||||||
|
]);
|
||||||
|
|
||||||
await loading.start();
|
await interaction.editReply(`👍 seeked to ${prettyTime(player.getPosition())}`);
|
||||||
|
|
||||||
try {
|
|
||||||
await player.forwardSeek(seekTime);
|
|
||||||
|
|
||||||
await loading.stop();
|
|
||||||
} catch (error: unknown) {
|
|
||||||
await loading.stop(errorMsg(error as Error));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue