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

0% Statements 0/11
0% Branches 0/2
0% Functions 0/2
0% Lines 0/9

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                                                                                           
import { CommandConfig, CommandPermissions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import {
	CurrentTranslate,
	LOCALIZATION_ADAPTER,
	NestedLocalizationAdapter,
	TranslationFn,
	localizationMapByKey,
} from "@necord/localization";
import { Inject, Logger, UseGuards } from "@nestjs/common";
import { Ctx, SlashCommandContext, Subcommand } from "necord";
import { Music } from "../";
import { MusicCommand } from "../Music.decorator";
import type { IMusicService } from "../interfaces";
 
@MusicCommand()
export class StopCommand {
	public constructor(
		@Inject(Music.Service) private readonly service: IMusicService,
		@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
	) {}
 
	private readonly logger = new Logger(StopCommand.name);
 
	@Subcommand({
		name: "stop",
		description: "Stops the music queue",
		nameLocalizations: localizationMapByKey("Music.stop.name"),
		descriptionLocalizations: localizationMapByKey("Music.stop.description"),
	})
	@CommandConfig({ category: "🎵 Music", disable: false })
	@CommandPermissions({
		bot: ["SendMessages"],
		user: ["SendMessages"],
		guildOnly: false,
		ownerOnly: false,
	})
	@UseGuards(CommandConfigGuard, CommandPermissionsGuard)
	public async onCommandRun(@Ctx() [interaction]: SlashCommandContext, @CurrentTranslate() t: TranslationFn) {
		const player = await this.service.getPlayer(interaction);
		if (!(await this.service.checkers(interaction))) return;
		await player.destroy();
		return interaction.reply(this.translate.getTranslation("Tools.Music.Stop", interaction.guild.preferredLocale));
	}
}