From 60376d4f5798004bc0215698bc1cc0786fcd5dbc Mon Sep 17 00:00:00 2001 From: Zagrthos <36556009+Zagrthos@users.noreply.github.com> Date: Sat, 19 Mar 2022 15:55:23 +0100 Subject: Update README and add "Now playing" Command (#589) Co-authored-by: Max Isom Co-authored-by: Max Isom --- src/commands/now-playing.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/commands/now-playing.ts (limited to 'src/commands') diff --git a/src/commands/now-playing.ts b/src/commands/now-playing.ts new file mode 100644 index 0000000..999bb69 --- /dev/null +++ b/src/commands/now-playing.ts @@ -0,0 +1,32 @@ +import {CommandInteraction} 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'; +import {buildPlayingMessageEmbed} from '../utils/build-embed.js'; + +@injectable() +export default class implements Command { + public readonly slashCommand = new SlashCommandBuilder() + .setName('now-playing') + .setDescription('shows the currently played song'); + + private readonly playerManager: PlayerManager; + + constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) { + this.playerManager = playerManager; + } + + public async execute(interaction: CommandInteraction): Promise { + const player = this.playerManager.get(interaction.guild!.id); + + if (!player.getCurrent()) { + throw new Error('nothing is currently playing'); + } + + await interaction.reply({ + embeds: [buildPlayingMessageEmbed(player)], + }); + } +} -- cgit v1.2.3