All files / src/modules/bot/music/commands Queue.command.ts

0% Statements 0/17
0% Branches 0/4
0% Functions 0/2
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116                                                                                                                                                                                                                                       
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import type { INDBService } from "@/modules/bot/core/interfaces/INDBService";
import { Services } from "@/types/Constants";
import { Timer } from "@/utils/Tools";
import { CurrentTranslate, TranslationFn, localizationMapByKey } from "@necord/localization";
import { Inject, Logger, UseGuards } from "@nestjs/common";
import { Client, EmbedBuilder, Message, UserManager } from "discord.js";
import { Track, UnresolvedTrack } from "lavalink-client";
import { Ctx, SlashCommandContext, Subcommand } from "necord";
import { Music } from "..";
import { MusicCommand } from "../Music.decorator";
import type { IMusicService } from "../interfaces";
 
@MusicCommand()
export class QueueCommand {
	public constructor(
		@Inject(Services.NDB) private readonly NDBService: INDBService,
		@Inject(Music.Service) private readonly service: IMusicService,
		private readonly client: Client,
		private readonly users: UserManager,
	) {}
 
	private readonly logger = new Logger(QueueCommand.name);
 
	@Subcommand({
		name: "queue",
		description: "Shows the music queue",
		nameLocalizations: localizationMapByKey("Music.queue.name"),
		descriptionLocalizations: localizationMapByKey("Music.queue.description"),
	})
	@CommandConfig({ category: "🎵 Music", disable: false })
	@CommandPermissions({
		bot: ["Connect", "EmbedLinks", "DeafenMembers", "Speak"],
		user: ["Connect", "SendMessages"],
		guildOnly: false,
		ownerOnly: false,
	})
	@UseGuards(CommandConfigGuard, CommandPermissionsGuard)
	public async onCommandRun(
		@Ctx() [interaction]: SlashCommandContext,
		@CurrentTranslate() t: TranslationFn,
	): Promise<Message> {
		if (!(await this.service.checkers(interaction))) {
			return;
		}
 
		const player = await this.service.getPlayer(interaction);
 
		const embeds: EmbedBuilder[] = [];
		const queue: (Track | UnresolvedTrack)[] = player.queue.tracks;
 
		for (const track of queue) {
			const Requester = await this.users.fetch(track.requester as string);
 
			embeds.push(
				new EmbedBuilder()
					.setAuthor({
						name: this.client.user.username,
						iconURL: this.client.user.displayAvatarURL(),
					})
					.setTitle(
						t("Events.PlayerEvents.trackStart.Embed.Title", {
							TITLE: track.info.title,
						}),
					)
					.setThumbnail(track.info.artworkUrl)
					.addFields([
						{
							name: t("Events.PlayerEvents.trackStart.Embed.Fields.1", {
								EMOJI: (await this.service.URLChecker(false, track.info.uri)).Emoji,
							}),
							value: `> ${t("Events.PlayerEvents.trackStart.Embed.Fields.Content.1", {
								Platform: this.service.formatSourceName(track.info.sourceName),
								URI: track.info.uri,
							})}`,
							inline: true,
						},
						{
							name: t("Events.PlayerEvents.trackStart.Embed.Fields.2", interaction.guild.preferredLocale),
							value: `> ${t("Events.PlayerEvents.trackStart.Embed.Fields.Content.2", {
								AUTHOR: track.info.author,
							})}`,
							inline: true,
						},
						{
							name: t("Events.PlayerEvents.trackStart.Embed.Fields.3", interaction.guild.preferredLocale),
							value: `> ${
								track.info.isStream
									? t("Events.PlayerEvents.trackStart.Embed.Fields.Content.3²", interaction.guild.preferredLocale)
									: t("Events.PlayerEvents.trackStart.Embed.Fields.Content.3", {
											TIMER: await Timer(t, "normal", track.info.duration, interaction.guildLocale),
										})
							}`,
							inline: true,
						},
					])
					.setColor("#00c26f")
					.setFooter({
						text: t("Events.PlayerEvents.trackStart.Embed.Footer", {
							REQUESTER: Requester.username,
						}),
						iconURL: Requester.displayAvatarURL(),
					})
					.setTimestamp(),
			);
		}
 
		await interaction.reply({
			embeds: [
				(await this.NDBService.buildPaginator(interaction, embeds, `queue-${interaction.guild.id}`)) as EmbedBuilder,
			],
		});
	}
}