All files / src/modules/bot/reactionRoles ReactionRoles.embeds.ts

7.4% Statements 2/27
0% Branches 0/3
0% Functions 0/14
3.84% Lines 1/26

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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293                    3x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
import { MessageTools } from "@/modules/bot/commands/Message";
import { Config } from "@/modules/shared/config/types";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { Inject, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { CommandInteraction, EmbedBuilder, Message, TextChannel, channelMention, roleMention } from "discord.js";
import type { IReactionRolesEmbeds } from "./interfaces";
import type { IReaction, REACTION_OPTIONS } from "./types";
 
@Injectable()
export class ReactionRolesEmbeds implements IReactionRolesEmbeds {
	public constructor(
		@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
		private readonly config: ConfigService,
	) {}
 
	public async InvalidChannelEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.id,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.Channel.Invalid", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async InvalidIDEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.id,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.ID.Invalid", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async MessageNotFoundEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.id,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.ID.NotFound", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async InvalidRoleEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.id,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.Role.Invalid", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async InvalidEmojiEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.id,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.Emoji.Invalid", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async ReactionRoleCreatedEmbed(
		interaction: CommandInteraction,
		{ Channel, Message, Role, Emoji, Option }: IReaction,
	): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Author", interaction.guildLocale),
				iconURL: interaction.guild.iconURL(),
			})
			.setColor("#00c26f")
			.addFields([
				{
					name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Fields.1", interaction.guildLocale),
					value: channelMention(Channel),
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Fields.2", interaction.guildLocale),
					value: Emoji,
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Fields.3", interaction.guildLocale),
					value: String(Option),
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Fields.4", interaction.guildLocale),
					value: this.translate.getTranslation(
						"ReactionRoles.CreateReaction.Embed.Fields.Content.4",
						interaction.guildLocale,
						{
							MsgIdURL: (
								await MessageTools.get((await interaction.guild.channels.fetch(Channel)) as TextChannel, Message)
							).url,
						},
					),
				},
				{
					name: this.translate.getTranslation("ReactionRoles.CreateReaction.Embed.Fields.5", interaction.guildLocale),
					value: roleMention(Role),
				},
			]);
	}
 
	public async ReactionRoleRemovedEmbed(interaction: CommandInteraction, MsgID: Message): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#00c26f")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.DeleteReaction.Removed", interaction.guildLocale, {
					success: this.config.get<Config["Emojis"]>("Emojis").accept,
					URL: MsgID.url,
				}),
			);
	}
 
	public async ReactionRoleUpdatedEmbed(
		interaction: CommandInteraction,
		{ Channel, Message, Role, Emoji }: IReaction,
		newOption: REACTION_OPTIONS,
	): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#00c26f")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Description", interaction.guildLocale),
			)
			.addFields(
				{
					name: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Fields.1", interaction.guildLocale),
					value: channelMention(Channel),
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Fields.2", interaction.guildLocale),
					value: Emoji,
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Fields.3", interaction.guildLocale),
					value: this.translate.getTranslation(
						"ReactionRoles.UpdateReaction.Embed.Fields.Content.3",
						interaction.guildLocale,
						{
							MsgIdURL: (
								await ((await interaction.guild.channels.fetch(Channel)) as TextChannel).messages.fetch(Message)
							).url,
						},
					),
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Fields.4", interaction.guildLocale),
					value: roleMention(Role),
					inline: true,
				},
				{
					name: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Fields.5", interaction.guildLocale),
					value: newOption.toString(),
					inline: true,
				},
			)
 
			.setFooter({
				text: this.translate.getTranslation("ReactionRoles.UpdateReaction.Embed.Footer", interaction.guildLocale),
			});
	}
 
	public async ReactionRoleDeleteAllEmbed(
		interaction: CommandInteraction,
		status: "Confirm" | "Cancel" | "Success",
		ReactionCount: number | null,
	): Promise<EmbedBuilder> {
		let description: string;
		let color: number;
		switch (status) {
			case "Confirm":
				description = "ReactionRoles.DeleteAllReactions.Embed.Description.Confirm";
				color = 0x00c26f;
				break;
			case "Cancel":
				description = "ReactionRoles.DeleteAllReactions.Embed.Description.Cancel";
				color = 0xc20e00;
				break;
			case "Success":
				description = "ReactionRoles.DeleteAllReactions.Embed.Description.Success";
				color = 0x00c26f;
				break;
		}
		return new EmbedBuilder()
			.setTitle(this.translate.getTranslation("ReactionRoles.DeleteAllReactions.Embed.Title", interaction.guildLocale))
			.setAuthor({
				name: interaction.user.username,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setDescription(
				this.translate.getTranslation(description, interaction.guildLocale, {
					NUMBER: String(ReactionCount),
				}),
			)
			.setColor(color);
	}
 
	public async UnableToCreateReactionRoleEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.CreateReaction.UnableToCreate", interaction.guildLocale, {
					fail: this.config.get<Config["Emojis"]>("Emojis").fail,
				}),
			);
	}
 
	public async UnableToDeleteReactionRoleEmbed(interaction: CommandInteraction, MsgID: Message): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.DeleteReaction.UnableToDelete", interaction.guildLocale, {
					success: this.config.get<Config["Emojis"]>("Emojis").accept,
					URL: MsgID.url,
				}),
			);
	}
 
	public async UnableToDeleteAllReactionRoleEmbed(interaction: CommandInteraction): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.DeleteAllReaction.UnableToDelete", interaction.guildLocale),
			);
	}
 
	public async UnableToUpdateReactionRoleEmbed(interaction: CommandInteraction, MsgID: Message): Promise<EmbedBuilder> {
		return new EmbedBuilder()
			.setAuthor({
				name: interaction.user.tag,
				iconURL: interaction.user.displayAvatarURL(),
			})
			.setColor("#c20e00")
			.setDescription(
				this.translate.getTranslation("ReactionRoles.UpdateReaction.UnableToUpdate", interaction.guildLocale, {
					success: this.config.get<Config["Emojis"]>("Emojis").accept,
					URL: MsgID.url,
				}),
			);
	}
}