2022-12-16 16:10:16 +01:00
|
|
|
import { TransformPipe } from '@discord-nestjs/common';
|
|
|
|
|
2022-12-17 17:56:55 +01:00
|
|
|
import { Command, DiscordCommand, UsePipes } from '@discord-nestjs/core';
|
|
|
|
import { CommandInteraction } from 'discord.js';
|
|
|
|
import { DiscordMessageService } from '../clients/discord/discord.message.service';
|
|
|
|
import { GenericCustomReply } from '../models/generic-try-handler';
|
2022-12-17 19:52:32 +01:00
|
|
|
import { PlaybackService } from '../playback/playback.service';
|
|
|
|
import { Constants } from '../utils/constants';
|
2022-12-25 21:57:37 +01:00
|
|
|
import { chooseSuitableRemoteImageFromTrack } from '../utils/remoteImages';
|
2022-12-17 22:54:46 +01:00
|
|
|
import { trimStringToFixedLength } from '../utils/stringUtils';
|
2022-12-17 19:52:32 +01:00
|
|
|
import { formatMillisecondsAsHumanReadable } from '../utils/timeUtils';
|
2022-12-16 16:10:16 +01:00
|
|
|
|
|
|
|
@Command({
|
2022-12-17 22:54:46 +01:00
|
|
|
name: 'playlist',
|
2022-12-16 16:10:16 +01:00
|
|
|
description: 'Print the current track information',
|
|
|
|
})
|
|
|
|
@UsePipes(TransformPipe)
|
2022-12-17 22:54:46 +01:00
|
|
|
export class PlaylistCommand implements DiscordCommand {
|
2022-12-17 19:52:32 +01:00
|
|
|
constructor(
|
|
|
|
private readonly discordMessageService: DiscordMessageService,
|
|
|
|
private readonly playbackService: PlaybackService,
|
|
|
|
) {}
|
2022-12-17 17:56:55 +01:00
|
|
|
|
2022-12-20 11:03:24 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-12-17 17:56:55 +01:00
|
|
|
handler(interaction: CommandInteraction): GenericCustomReply {
|
2022-12-17 19:52:32 +01:00
|
|
|
const playList = this.playbackService.getPlaylist();
|
|
|
|
|
|
|
|
if (playList.tracks.length === 0) {
|
|
|
|
return {
|
|
|
|
embeds: [
|
|
|
|
this.discordMessageService.buildMessage({
|
|
|
|
title: 'Your Playlist',
|
|
|
|
description:
|
|
|
|
'You do not have any tracks in your playlist.\nUse the play command to add new tracks to your playlist',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const tracklist = playList.tracks
|
|
|
|
.slice(0, 10)
|
2022-12-17 22:54:46 +01:00
|
|
|
.map((track, index) => {
|
2022-12-17 19:52:32 +01:00
|
|
|
const isCurrent = track.id === playList.activeTrack;
|
2022-12-17 22:54:46 +01:00
|
|
|
|
|
|
|
let point = this.getListPoint(isCurrent, index);
|
|
|
|
point += `**${trimStringToFixedLength(track.track.name, 30)}**`;
|
|
|
|
|
2022-12-18 19:21:33 +01:00
|
|
|
if (isCurrent) {
|
2022-12-17 22:54:46 +01:00
|
|
|
point += ' :loud_sound:';
|
|
|
|
}
|
|
|
|
|
|
|
|
point += '\n';
|
|
|
|
point += Constants.Design.InvisibleSpace.repeat(2);
|
|
|
|
point += 'Duration: ';
|
|
|
|
point += formatMillisecondsAsHumanReadable(
|
2022-12-17 19:52:32 +01:00
|
|
|
track.track.durationInMilliseconds,
|
2022-12-17 22:54:46 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return point;
|
2022-12-17 19:52:32 +01:00
|
|
|
})
|
2022-12-18 17:46:31 +01:00
|
|
|
.join('\n');
|
2022-12-17 19:52:32 +01:00
|
|
|
|
2022-12-25 21:57:37 +01:00
|
|
|
const activeTrack = this.playbackService.getActiveTrack();
|
|
|
|
const remoteImage = chooseSuitableRemoteImageFromTrack(activeTrack.track);
|
|
|
|
|
2022-12-17 17:56:55 +01:00
|
|
|
return {
|
|
|
|
embeds: [
|
2022-12-17 19:52:32 +01:00
|
|
|
this.discordMessageService.buildMessage({
|
|
|
|
title: 'Your Playlist',
|
2022-12-17 22:54:46 +01:00
|
|
|
description: `${tracklist}\n\nUse the /skip and /previous command to select a track`,
|
2022-12-25 21:57:37 +01:00
|
|
|
mixin(embedBuilder) {
|
|
|
|
if (remoteImage === undefined) {
|
|
|
|
return embedBuilder;
|
|
|
|
}
|
|
|
|
|
|
|
|
return embedBuilder.setThumbnail(remoteImage.Url);
|
|
|
|
},
|
2022-12-17 17:56:55 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
2022-12-16 16:10:16 +01:00
|
|
|
}
|
2022-12-17 19:52:32 +01:00
|
|
|
|
2022-12-17 22:54:46 +01:00
|
|
|
private getListPoint(isCurrent: boolean, index: number) {
|
2022-12-17 19:52:32 +01:00
|
|
|
if (isCurrent) {
|
2022-12-17 22:54:46 +01:00
|
|
|
return `${index + 1}. `;
|
2022-12-17 19:52:32 +01:00
|
|
|
}
|
|
|
|
|
2022-12-17 22:54:46 +01:00
|
|
|
return `${index + 1}. `;
|
2022-12-17 19:52:32 +01:00
|
|
|
}
|
2022-12-16 16:10:16 +01:00
|
|
|
}
|