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

14.28% Statements 2/14
0% Branches 0/2
0% Functions 0/10
7.69% Lines 1/13

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                    3x                                                                                                                                                                                              
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Client, CommandInteraction, EmbedBuilder, Guild, Message, Role, TextChannel } from "discord.js";
import type { IDatabaseService } from "../../shared/database/interfaces/IDatabaseService";
import { ReactionRolesEntity } from "./entities/ReactionRole.entity";
import type { IReactionRolesEmbeds, IReactionRolesService } from "./interfaces";
import type { IReaction, REACTION_OPTIONS } from "./types";
import { ReactionRoles } from "./types/constants";
 
@Injectable()
export class ReactionRolesService implements IReactionRolesService {
	public constructor(
		@Inject(Services.Database) private readonly database: IDatabaseService,
		@Inject(ReactionRoles.Embeds) private readonly embeds: IReactionRolesEmbeds,
	) {}
 
	public async Embeds(): Promise<IReactionRolesEmbeds> {
		return this.embeds;
	}
 
	public async getAll(guild: Guild): Promise<ReactionRolesEntity[]> {
		return await this.database.ReactionRolesRepo().getAll(guild);
	}
 
	public async getInChannel(guild: Guild, channel: TextChannel): Promise<ReactionRolesEntity[]> {
		return await this.database.ReactionRolesRepo().getInChannel(guild, channel);
	}
 
	public async getOne(
		guild: Guild,
		{ Channel, Message, Role, Emoji, Option }: IReaction,
	): Promise<ReactionRolesEntity> {
		return await this.database.ReactionRolesRepo().getOne(guild, {
			Channel,
			Message,
			Role,
			Emoji,
			Option,
		});
	}
 
	public async Create(
		guild: Guild,
		{ Channel, Message, Role, Emoji, Option }: IReaction,
	): Promise<{ status: "UnableToCreate" | "Created" }> {
		return await this.database.ReactionRolesRepo().create(guild, {
			Channel,
			Message,
			Role,
			Emoji,
			Option,
		});
	}
 
	public async Delete(
		guild: Guild,
		{ Channel, Message, Role, Emoji }: IReaction,
	): Promise<{ status: "UnableToDelete" | "Deleted" }> {
		return await this.database.ReactionRolesRepo().delete(guild, {
			Channel,
			Message,
			Role,
			Emoji,
		});
	}
 
	public async DeleteAll(guild: Guild): Promise<{ status: "UnableToDelete" | "Deleted"; count: number }> {
		return await this.database.ReactionRolesRepo().deleteMany(guild);
	}
 
	public async Update(
		guild: Guild,
		{ Channel, Message, Role, Emoji, Option }: IReaction,
		newOption: REACTION_OPTIONS,
	): Promise<{
		status: "UnableToUpdate" | "Updated";
		oldOption?: REACTION_OPTIONS;
	}> {
		return await this.database.ReactionRolesRepo().update(
			guild,
			{
				Channel,
				Message,
				Role,
				Emoji,
				Option,
			},
			newOption,
		);
	}
 
	public async CheckParams(
		client: Client<boolean>,
		interaction: CommandInteraction,
		channel: TextChannel,
		messageId: string,
		message: Message<boolean>,
		role: Role,
		emoji: string,
	) {
		if (!message) {
			return await interaction.reply({ embeds: [await this.embeds.MessageNotFoundEmbed(interaction)] });
		}
	}
}