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';
|
|
|
|
import { formatMillisecondsAsHumanReadable } from '../utils/timeUtils';
|
2022-12-16 16:10:16 +01:00
|
|
|
|
|
|
|
@Command({
|
|
|
|
name: 'current',
|
|
|
|
description: 'Print the current track information',
|
|
|
|
})
|
|
|
|
@UsePipes(TransformPipe)
|
2022-12-17 17:56:55 +01:00
|
|
|
export class CurrentTrackCommand 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
|
|
|
|
|
|
|
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)
|
|
|
|
.map((track) => {
|
|
|
|
const isCurrent = track.id === playList.activeTrack;
|
|
|
|
return `${this.getListPoint(isCurrent)} ${
|
|
|
|
track.track.name
|
|
|
|
}\n${Constants.Design.InvisibleSpace.repeat(
|
|
|
|
3,
|
|
|
|
)}${formatMillisecondsAsHumanReadable(
|
|
|
|
track.track.durationInMilliseconds,
|
|
|
|
)} ${isCurrent && ' *(active track)*'}`;
|
|
|
|
})
|
|
|
|
.join(',\n');
|
|
|
|
|
2022-12-17 17:56:55 +01:00
|
|
|
return {
|
|
|
|
embeds: [
|
2022-12-17 19:52:32 +01:00
|
|
|
this.discordMessageService.buildMessage({
|
|
|
|
title: 'Your Playlist',
|
|
|
|
description: tracklist,
|
2022-12-17 17:56:55 +01:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|
2022-12-16 16:10:16 +01:00
|
|
|
}
|
2022-12-17 19:52:32 +01:00
|
|
|
|
|
|
|
private getListPoint(isCurrent: boolean) {
|
|
|
|
if (isCurrent) {
|
|
|
|
return ':black_small_square:';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ':white_small_square:';
|
|
|
|
}
|
2022-12-16 16:10:16 +01:00
|
|
|
}
|