From d024b4f714f54b99451d0ab7e86f3db6699c8cdd Mon Sep 17 00:00:00 2001 From: Manuel Ruwe Date: Sat, 17 Dec 2022 22:54:46 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Rename=20current=20command?= =?UTF-8?q?=20to=20playlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/command.module.ts | 4 +-- ...current.command.ts => playlist.command.ts} | 36 ++++++++++++------- src/playback/playback.service.ts | 4 +++ 3 files changed, 29 insertions(+), 15 deletions(-) rename src/commands/{current.command.ts => playlist.command.ts} (66%) diff --git a/src/commands/command.module.ts b/src/commands/command.module.ts index bd414d2..fdee065 100644 --- a/src/commands/command.module.ts +++ b/src/commands/command.module.ts @@ -4,7 +4,7 @@ import { Module } from '@nestjs/common'; import { DiscordClientModule } from '../clients/discord/discord.module'; import { JellyfinClientModule } from '../clients/jellyfin/jellyfin.module'; import { PlaybackModule } from '../playback/playback.module'; -import { CurrentTrackCommand } from './current.command'; +import { PlaylistCommand } from './playlist.command'; import { DisconnectCommand } from './disconnect.command'; import { HelpCommand } from './help.command'; import { PausePlaybackCommand } from './pause.command'; @@ -26,7 +26,7 @@ import { SummonCommand } from './summon.command'; providers: [ HelpCommand, StatusCommand, - CurrentTrackCommand, + PlaylistCommand, DisconnectCommand, PausePlaybackCommand, SkipTrackCommand, diff --git a/src/commands/current.command.ts b/src/commands/playlist.command.ts similarity index 66% rename from src/commands/current.command.ts rename to src/commands/playlist.command.ts index be4db65..4d2aeb6 100644 --- a/src/commands/current.command.ts +++ b/src/commands/playlist.command.ts @@ -6,14 +6,15 @@ import { DiscordMessageService } from '../clients/discord/discord.message.servic import { GenericCustomReply } from '../models/generic-try-handler'; import { PlaybackService } from '../playback/playback.service'; import { Constants } from '../utils/constants'; +import { trimStringToFixedLength } from '../utils/stringUtils'; import { formatMillisecondsAsHumanReadable } from '../utils/timeUtils'; @Command({ - name: 'current', + name: 'playlist', description: 'Print the current track information', }) @UsePipes(TransformPipe) -export class CurrentTrackCommand implements DiscordCommand { +export class PlaylistCommand implements DiscordCommand { constructor( private readonly discordMessageService: DiscordMessageService, private readonly playbackService: PlaybackService, @@ -36,15 +37,24 @@ export class CurrentTrackCommand implements DiscordCommand { const tracklist = playList.tracks .slice(0, 10) - .map((track) => { + .map((track, index) => { const isCurrent = track.id === playList.activeTrack; - return `${this.getListPoint(isCurrent)} ${ - track.track.name - }\n${Constants.Design.InvisibleSpace.repeat( - 3, - )}${formatMillisecondsAsHumanReadable( + + let point = this.getListPoint(isCurrent, index); + point += `**${trimStringToFixedLength(track.track.name, 30)}**`; + + if (isCurrent === true) { + point += ' :loud_sound:'; + } + + point += '\n'; + point += Constants.Design.InvisibleSpace.repeat(2); + point += 'Duration: '; + point += formatMillisecondsAsHumanReadable( track.track.durationInMilliseconds, - )} ${isCurrent ? ' *(active track)*' : ''}`; + ); + + return point; }) .join(',\n'); @@ -52,17 +62,17 @@ export class CurrentTrackCommand implements DiscordCommand { embeds: [ this.discordMessageService.buildMessage({ title: 'Your Playlist', - description: tracklist, + description: `${tracklist}\n\nUse the /skip and /previous command to select a track`, }), ], }; } - private getListPoint(isCurrent: boolean) { + private getListPoint(isCurrent: boolean, index: number) { if (isCurrent) { - return ':black_small_square:'; + return `${index + 1}. `; } - return ':white_small_square:'; + return `${index + 1}. `; } } diff --git a/src/playback/playback.service.ts b/src/playback/playback.service.ts index fa3629f..beb4034 100644 --- a/src/playback/playback.service.ts +++ b/src/playback/playback.service.ts @@ -74,6 +74,10 @@ export class PlaybackService { track: track, }); + this.logger.debug( + `Added the track '${track.jellyfinId}' to the current playlist`, + ); + if (emptyBefore) { this.setActiveTrack(this.playlist.tracks.find((x) => x.id === uuid).id); this.controlAudioPlayer();