All files / src/modules/bot/reactionRoles/commands/DeleteReaction DeleteReaction.command.ts

0% Statements 0/19
0% Branches 0/2
0% Functions 0/2
0% Lines 0/18

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                                                                                                                           
import { CommandConfig, CommandPermissions, ValidatedOptions } from "@/common/decorators";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { Buttons } from "@/modules/bot/components/Buttons.component";
import { Extends } from "@/types/Constants";
import { localizationMapByKey } from "@necord/localization";
import { Inject, Injectable, Logger, UseGuards } from "@nestjs/common";
import { Client, TextChannel } from "discord.js";
import { Ctx, SlashCommandContext, Subcommand } from "necord";
import type { IReactionRolesEmbeds, IReactionRolesService } from "../../interfaces";
import { ReactionRoles } from "../../types/constants";
import { DeleteReactionDTO } from "./DeleteReaction.dto";
 
@Injectable()
export class DeleteReactionCommand {
	public constructor(
		@Inject(ReactionRoles.Service) private readonly reaction: IReactionRolesService,
		@Inject(ReactionRoles.Embeds) private readonly Embeds: IReactionRolesEmbeds,
		@Inject(Extends.Buttons) private readonly Buttons: Buttons,
		private readonly client: Client,
	) {}
 
	private readonly logger = new Logger(DeleteReactionCommand.name);
 
	@Subcommand({
		name: "delete",
		description: "Delete an existent ReactionRole",
		nameLocalizations: localizationMapByKey("ReactionRoles.delete.name"),
		descriptionLocalizations: localizationMapByKey("ReactionRoles.delete.description"),
	})
	@CommandConfig({ category: "🎩 ReactionRole", disable: false })
	@CommandPermissions({
		user: ["SendMessages", "AddReactions", "ManageRoles"],
		bot: ["EmbedLinks", "AddReactions", "ManageRoles"],
		guildOnly: false,
		ownerOnly: false,
	})
	@UseGuards(CommandConfigGuard, CommandPermissionsGuard)
	public async onCommandRun(@Ctx() [interaction]: SlashCommandContext, @ValidatedOptions() dto: DeleteReactionDTO) {
		const Channel = dto.channel as TextChannel;
		const MessageID = dto.messageId;
		const Message = await Channel.messages.fetch(MessageID);
		const Role = dto.role;
		const Emoji = dto.emoji;
 
		await this.reaction.CheckParams(this.client, interaction, Channel, MessageID, Message, Role, Emoji);
 
		const REACT = await this.reaction.Delete(interaction.guild, {
			Channel: Channel.id,
			Message: Message.id,
			Role: Role.id,
			Emoji,
		});
 
		if (REACT.status === "Deleted") {
			await interaction.reply({ embeds: [await this.Embeds.ReactionRoleRemovedEmbed(interaction, Message)] });
			await Message.reactions.cache.get(Emoji).remove();
		} else {
			interaction.reply({ embeds: [await this.Embeds.UnableToDeleteReactionRoleEmbed(interaction, Message)] });
		}
	}
}