From 8acc4f23f245d1c8fc80992a7117d5f6af168357 Mon Sep 17 00:00:00 2001 From: xHyperElectric <71343435+xHyperElectric@users.noreply.github.com> Date: Sun, 26 Feb 2023 21:50:36 -0500 Subject: Add /replay command (#901) Co-authored-by: xHyperElectric Co-authored-by: xHyperElectric Co-authored-by: Max Isom --- src/commands/replay.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/commands/replay.ts (limited to 'src/commands') diff --git a/src/commands/replay.ts b/src/commands/replay.ts new file mode 100644 index 0000000..43b1057 --- /dev/null +++ b/src/commands/replay.ts @@ -0,0 +1,42 @@ +import {ChatInputCommandInteraction} from 'discord.js'; +import {TYPES} from '../types.js'; +import {inject, injectable} from 'inversify'; +import PlayerManager from '../managers/player.js'; +import Command from '.'; +import {SlashCommandBuilder} from '@discordjs/builders'; + +@injectable() +export default class implements Command { + public readonly slashCommand = new SlashCommandBuilder() + .setName('replay') + .setDescription('replay the current song'); + + public requiresVC = true; + + private readonly playerManager: PlayerManager; + + constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) { + this.playerManager = playerManager; + } + + public async execute(interaction: ChatInputCommandInteraction): Promise { + const player = this.playerManager.get(interaction.guild!.id); + + const currentSong = player.getCurrent(); + + if (!currentSong) { + throw new Error('nothing is playing'); + } + + if (currentSong.isLive) { + throw new Error('can\'t replay a livestream'); + } + + await Promise.all([ + player.seek(0), + interaction.deferReply(), + ]); + + await interaction.editReply('👍 replayed the current song'); + } +} -- cgit v1.2.3