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

0% Statements 0/14
0% Branches 0/6
0% Functions 0/2
0% Lines 0/12

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                                                                                                               
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { CurrentTranslate, TranslationFn, localizationMapByKey } from "@necord/localization";
import { Inject, Logger, UseGuards } from "@nestjs/common";
import { GuildMember, VoiceChannel, channelMention } from "discord.js";
import { Ctx, SlashCommandContext, Subcommand } from "necord";
import { Music } from "../";
import { MusicCommand } from "../Music.decorator";
import type { IMusicService } from "../interfaces";
 
@MusicCommand()
export class LeaveCommand {
	public constructor(@Inject(Music.Service) private readonly service: IMusicService) {}
 
	private readonly logger = new Logger(LeaveCommand.name);
 
	@Subcommand({
		name: "leave",
		description: "Leave the voice channel",
		nameLocalizations: localizationMapByKey("Music.leave.name"),
		descriptionLocalizations: localizationMapByKey("Music.leave.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) {
		let player = await this.service.getPlayer(interaction);
 
		if (!(await this.service.hasVoice(interaction))) return;
 
		if (!player) {
			player = await this.service.createPlayer(
				interaction,
				(interaction.member as GuildMember).voice.channel as VoiceChannel,
				interaction.channel.id,
			);
		}
 
		if (!player.connected) {
			player.playerAuthor = interaction.user.id;
			await player.connect();
		}
 
		return interaction.reply(
			t("Tools/Music:Join", {
				VoiceChannel: channelMention(player.voiceChannelId),
			}),
		);
	}
}