Refactor skip command as slash command

This commit is contained in:
Federico fuji97 Rapetti 2021-12-27 16:43:23 +01:00
parent 995c0360fe
commit 1890f264ac

View file

@ -1,10 +1,11 @@
import {Message, TextChannel} from 'discord.js';
import {CommandInteraction, Message, TextChannel} from 'discord.js';
import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player.js';
import Command from '.';
import LoadingMessage from '../utils/loading-message.js';
import errorMsg from '../utils/error-msg.js';
import {SlashCommandBuilder} from '@discordjs/builders';
@injectable()
export default class implements Command {
@ -15,6 +16,15 @@ export default class implements Command {
['skip 2', 'skips the next 2 songs'],
];
public readonly slashCommand = new SlashCommandBuilder()
.setName('skip')
// TODO: make sure verb tense is consistent between all command descriptions
.setDescription('skips the next songs')
.addIntegerOption(option => option
.setName('number')
.setDescription('number of songs to skip [default: 1]')
.setRequired(false));
public requiresVC = true;
private readonly playerManager: PlayerManager;
@ -23,6 +33,23 @@ export default class implements Command {
this.playerManager = playerManager;
}
public async executeFromInteraction(interaction: CommandInteraction): Promise<void> {
const numToSkip = interaction.options.getInteger('skip') ?? 1;
if (numToSkip < 1) {
await interaction.reply({content: errorMsg('invalid number of songs to skip'), ephemeral: true});
}
const player = this.playerManager.get(interaction.guild!.id);
try {
await player.forward(numToSkip);
await interaction.reply('keep \'er movin\'');
} catch (_: unknown) {
await interaction.reply({content: errorMsg('invalid number of songs to skip'), ephemeral: true});
}
}
public async execute(msg: Message, args: string []): Promise<void> {
let numToSkip = 1;