♻️ Rename current command to playlist

This commit is contained in:
Manuel Ruwe 2022-12-17 22:54:46 +01:00
parent d8ce16d7d8
commit d024b4f714
3 changed files with 29 additions and 15 deletions

View File

@ -4,7 +4,7 @@ import { Module } from '@nestjs/common';
import { DiscordClientModule } from '../clients/discord/discord.module'; import { DiscordClientModule } from '../clients/discord/discord.module';
import { JellyfinClientModule } from '../clients/jellyfin/jellyfin.module'; import { JellyfinClientModule } from '../clients/jellyfin/jellyfin.module';
import { PlaybackModule } from '../playback/playback.module'; import { PlaybackModule } from '../playback/playback.module';
import { CurrentTrackCommand } from './current.command'; import { PlaylistCommand } from './playlist.command';
import { DisconnectCommand } from './disconnect.command'; import { DisconnectCommand } from './disconnect.command';
import { HelpCommand } from './help.command'; import { HelpCommand } from './help.command';
import { PausePlaybackCommand } from './pause.command'; import { PausePlaybackCommand } from './pause.command';
@ -26,7 +26,7 @@ import { SummonCommand } from './summon.command';
providers: [ providers: [
HelpCommand, HelpCommand,
StatusCommand, StatusCommand,
CurrentTrackCommand, PlaylistCommand,
DisconnectCommand, DisconnectCommand,
PausePlaybackCommand, PausePlaybackCommand,
SkipTrackCommand, SkipTrackCommand,

View File

@ -6,14 +6,15 @@ import { DiscordMessageService } from '../clients/discord/discord.message.servic
import { GenericCustomReply } from '../models/generic-try-handler'; import { GenericCustomReply } from '../models/generic-try-handler';
import { PlaybackService } from '../playback/playback.service'; import { PlaybackService } from '../playback/playback.service';
import { Constants } from '../utils/constants'; import { Constants } from '../utils/constants';
import { trimStringToFixedLength } from '../utils/stringUtils';
import { formatMillisecondsAsHumanReadable } from '../utils/timeUtils'; import { formatMillisecondsAsHumanReadable } from '../utils/timeUtils';
@Command({ @Command({
name: 'current', name: 'playlist',
description: 'Print the current track information', description: 'Print the current track information',
}) })
@UsePipes(TransformPipe) @UsePipes(TransformPipe)
export class CurrentTrackCommand implements DiscordCommand { export class PlaylistCommand implements DiscordCommand {
constructor( constructor(
private readonly discordMessageService: DiscordMessageService, private readonly discordMessageService: DiscordMessageService,
private readonly playbackService: PlaybackService, private readonly playbackService: PlaybackService,
@ -36,15 +37,24 @@ export class CurrentTrackCommand implements DiscordCommand {
const tracklist = playList.tracks const tracklist = playList.tracks
.slice(0, 10) .slice(0, 10)
.map((track) => { .map((track, index) => {
const isCurrent = track.id === playList.activeTrack; const isCurrent = track.id === playList.activeTrack;
return `${this.getListPoint(isCurrent)} ${
track.track.name let point = this.getListPoint(isCurrent, index);
}\n${Constants.Design.InvisibleSpace.repeat( point += `**${trimStringToFixedLength(track.track.name, 30)}**`;
3,
)}${formatMillisecondsAsHumanReadable( if (isCurrent === true) {
point += ' :loud_sound:';
}
point += '\n';
point += Constants.Design.InvisibleSpace.repeat(2);
point += 'Duration: ';
point += formatMillisecondsAsHumanReadable(
track.track.durationInMilliseconds, track.track.durationInMilliseconds,
)} ${isCurrent ? ' *(active track)*' : ''}`; );
return point;
}) })
.join(',\n'); .join(',\n');
@ -52,17 +62,17 @@ export class CurrentTrackCommand implements DiscordCommand {
embeds: [ embeds: [
this.discordMessageService.buildMessage({ this.discordMessageService.buildMessage({
title: 'Your Playlist', 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) { if (isCurrent) {
return ':black_small_square:'; return `${index + 1}. `;
} }
return ':white_small_square:'; return `${index + 1}. `;
} }
} }

View File

@ -74,6 +74,10 @@ export class PlaybackService {
track: track, track: track,
}); });
this.logger.debug(
`Added the track '${track.jellyfinId}' to the current playlist`,
);
if (emptyBefore) { if (emptyBefore) {
this.setActiveTrack(this.playlist.tracks.find((x) => x.id === uuid).id); this.setActiveTrack(this.playlist.tracks.find((x) => x.id === uuid).id);
this.controlAudioPlayer(); this.controlAudioPlayer();