Skip to content

Commit

Permalink
Refactor skip command as slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
fuji97 committed Dec 27, 2021
1 parent 995c036 commit 1890f26
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/commands/skip.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 1890f26

Please sign in to comment.