Migrate to slash commands (#431)

Co-authored-by: Federico fuji97 Rapetti <fuji1097@gmail.com>
This commit is contained in:
Max Isom 2022-02-05 16:16:17 -06:00 committed by GitHub
parent e883275d83
commit 56a469a999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 1270 additions and 1294 deletions

View file

@ -1,18 +1,20 @@
import {Message, TextChannel} from 'discord.js';
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 LoadingMessage from '../utils/loading-message.js';
import errorMsg from '../utils/error-msg.js';
import Command from '.';
import {prettyTime} from '../utils/time.js';
@injectable()
export default class implements Command {
public name = 'fseek';
public aliases = [];
public examples = [
['fseek 10', 'skips forward in current song by 10 seconds'],
];
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;
@ -22,38 +24,34 @@ export default class implements Command {
this.playerManager = playerManager;
}
public async execute(msg: Message, args: string []): Promise<void> {
const player = this.playerManager.get(msg.guild!.id);
public async execute(interaction: CommandInteraction): Promise<void> {
const player = this.playerManager.get(interaction.guild!.id);
const currentSong = player.getCurrent();
if (!currentSong) {
await msg.channel.send(errorMsg('nothing is playing'));
return;
throw new Error('nothing is playing');
}
if (currentSong.isLive) {
await msg.channel.send(errorMsg('can\'t seek in a livestream'));
return;
throw new Error('can\'t seek in a livestream');
}
const seekTime = parseInt(args[0], 10);
const seekTime = interaction.options.getNumber('seconds');
if (!seekTime) {
throw new Error('missing number of seconds to seek');
}
if (seekTime + player.getPosition() > currentSong.length) {
await msg.channel.send(errorMsg('can\'t seek past the end of the song'));
return;
throw new Error('can\'t seek past the end of the song');
}
const loading = new LoadingMessage(msg.channel as TextChannel);
await Promise.all([
player.forwardSeek(seekTime),
interaction.deferReply(),
]);
await loading.start();
try {
await player.forwardSeek(seekTime);
await loading.stop();
} catch (error: unknown) {
await loading.stop(errorMsg(error as Error));
}
await interaction.editReply(`👍 seeked to ${prettyTime(player.getPosition())}`);
}
}