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 | import { CommandConfig, CommandPermissions, ValidatedOptions } from "@/common/decorators/";
import { CommandConfigGuard, CommandPermissionsGuard } from "@/common/guards";
import { MessageTools } from "@/modules/bot/commands/Message";
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 type { IReaction } from "../../types";
import { ReactionRoles } from "../../types/constants";
import { CreateReactionDTO } from "./CreateReaction.dto";
@Injectable()
export class CreateReactionCommand {
public constructor(
@Inject(ReactionRoles.Service) private readonly reaction: IReactionRolesService,
@Inject(ReactionRoles.Embeds) private readonly Embeds: IReactionRolesEmbeds,
private readonly client: Client,
) {}
private readonly logger = new Logger(CreateReactionCommand.name);
@Subcommand({
name: "create",
description: "Create an ReactionRole in the server",
nameLocalizations: localizationMapByKey("ReactionRoles.create.name"),
descriptionLocalizations: localizationMapByKey("ReactionRoles.create.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: CreateReactionDTO) {
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;
let Option = dto.option;
if (!Option || Option > 6 || Number.isNaN(Option)) Option = 1;
await this.reaction.CheckParams(this.client, interaction, Channel, MessageID, Message, Role, Emoji);
const data: IReaction = {
Channel: Channel.id,
Message: Message.id,
Role: Role.id,
Emoji,
Option,
};
const Created = await this.reaction.Create(interaction.guild, data);
if (Created.status === "Created") {
await MessageTools.react(Message, Emoji);
return await interaction.reply({ embeds: [await this.Embeds.ReactionRoleCreatedEmbed(interaction, data)] });
}
return await interaction.reply({ embeds: [await this.Embeds.UnableToCreateReactionRoleEmbed(interaction)] });
}
}
|