aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2021-12-13 21:04:17 -0500
committerMax Isom <[email protected]>2021-12-13 21:04:17 -0500
commitcbc9aafe780805d6aa3fb456fdb1620dc66679d3 (patch)
tree56239e69cf45554ade96a6827035fbffe3d43695 /src/commands
parentc33526b8b7825cbf01a9ca1c84ab3fd30a94ef0f (diff)
downloadmuse-cbc9aafe780805d6aa3fb456fdb1620dc66679d3.tar.xz
muse-cbc9aafe780805d6aa3fb456fdb1620dc66679d3.zip
Migrate fseek command
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/fseek.ts63
1 files changed, 41 insertions, 22 deletions
diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts
index 16d1430..5a46a17 100644
--- a/src/commands/fseek.ts
+++ b/src/commands/fseek.ts
@@ -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 {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 +25,54 @@ 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 executeFromInteraction(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'));
+ await interaction.reply({
+ content: errorMsg('nothing is playing'),
+ ephemeral: true,
+ });
+
return;
}
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;
}
- 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,
+ });
- if (seekTime + player.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);
+ if (seekTime + player.getPosition() > currentSong.length) {
+ await interaction.reply({
+ content: errorMsg('can\'t seek past the end of the song'),
+ ephemeral: true,
+ });
- await loading.start();
+ return;
+ }
- try {
- await player.forwardSeek(seekTime);
+ await Promise.all([
+ player.forwardSeek(seekTime),
+ interaction.deferReply(),
+ ]);
- await loading.stop();
- } catch (error: unknown) {
- await loading.stop(errorMsg(error as Error));
- }
+ await interaction.editReply(`👍 seeked to ${prettyTime(player.getPosition())}`);
}
}