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: [PATCH] Update README and add "Now playing" Command (#589) Co-authored-by: Max Isom Co-authored-by: Max Isom --- CHANGELOG.md | 2 ++ README.md | 4 +++- src/commands/now-playing.ts | 32 ++++++++++++++++++++++++++++++++ src/inversify.config.ts | 2 ++ src/utils/build-embed.ts | 4 ++-- 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/commands/now-playing.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ab20474..8709464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added a `/now-playing` command to show the current track without the full queue embed ## [1.6.2] - 2022-03-17 ### Fixed diff --git a/README.md b/README.md index d2b43fc..a913b2f 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,9 @@ services: ### Node.js -**Prerequisites**: Node.js, ffmpeg +**Prerequisites**: +* Node.js (16.x is recommended because it's the current LTS version) +* ffmpeg 1. `git clone https://github.com/codetheweb/muse.git && cd muse` 2. Copy `.env.example` to `.env` and populate with values 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)], + }); + } +} diff --git a/src/inversify.config.ts b/src/inversify.config.ts index b6a6f51..78267f8 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -21,6 +21,7 @@ import Config from './commands/config.js'; import Disconnect from './commands/disconnect.js'; import Favorites from './commands/favorites.js'; import ForwardSeek from './commands/fseek.js'; +import NowPlaying from './commands/now-playing.js'; import Pause from './commands/pause.js'; import Play from './commands/play.js'; import QueueCommand from './commands/queue.js'; @@ -65,6 +66,7 @@ container.bind(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingleton Disconnect, Favorites, ForwardSeek, + NowPlaying, Pause, Play, QueueCommand, diff --git a/src/utils/build-embed.ts b/src/utils/build-embed.ts index 0925da1..c6e9551 100644 --- a/src/utils/build-embed.ts +++ b/src/utils/build-embed.ts @@ -61,8 +61,8 @@ export const buildPlayingMessageEmbed = (player: Player): MessageEmbed => { const message = new MessageEmbed(); message - .setColor('DARK_GREEN') - .setTitle('Now Playing') + .setColor(player.status === STATUS.PLAYING ? 'DARK_GREEN' : 'DARK_RED') + .setTitle(player.status === STATUS.PLAYING ? 'Now Playing' : 'Paused') .setDescription(` **${getSongTitle(currentlyPlaying)}** Requested by: <@${requestedBy}>\n