diff options
| author | xHyperElectric <[email protected]> | 2023-02-26 21:50:36 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-26 20:50:36 -0600 |
| commit | 8acc4f23f245d1c8fc80992a7117d5f6af168357 (patch) | |
| tree | 3f50252b092931fbb40d736205b83ee53dc75f2b /src/commands | |
| parent | c89f288b7de40d14b8756fb878d49955570a9b3a (diff) | |
| download | muse-8acc4f23f245d1c8fc80992a7117d5f6af168357.tar.xz muse-8acc4f23f245d1c8fc80992a7117d5f6af168357.zip | |
Add /replay command (#901)
Co-authored-by: xHyperElectric <[email protected]>
Co-authored-by: xHyperElectric <xhyperelectric@xHyperElectric>
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/replay.ts | 42 |
1 files changed, 42 insertions, 0 deletions
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<void> { + 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'); + } +} |
