All files / src/modules/bot/core NDB.service.ts

0% Statements 0/14
0% Branches 0/2
0% Functions 0/3
0% Lines 0/12

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                                                                                                                   
import { Content } from "@/types";
import { LOCALIZATION_ADAPTER, NestedLocalizationAdapter } from "@necord/localization";
import { ButtonsAppearance, NecordPaginationService, PageBuilder } from "@necord/pagination";
import { Inject, Injectable } from "@nestjs/common";
import { ButtonStyle, CommandInteraction, EmbedBuilder } from "discord.js";
import type { INDBService } from "./interfaces/INDBService";
 
@Injectable()
export class NDBService implements INDBService {
	public constructor(
		@Inject(LOCALIZATION_ADAPTER) private readonly translate: NestedLocalizationAdapter,
		private readonly paginator: NecordPaginationService,
	) {}
 
	public async buildPaginator(interaction: CommandInteraction, embeds: EmbedBuilder[], id: string): Promise<Content> {
		const buttons: ButtonsAppearance = {
			back: {
				emoji: "⬅️",
				label: this.translate.getTranslation("Tools.Paginator.Labels.Previous", interaction.guildLocale),
				style: ButtonStyle.Secondary,
			},
			next: {
				emoji: "➡️",
				label: this.translate.getTranslation("Tools.Paginator.Labels.Next", interaction.guildLocale),
				style: ButtonStyle.Secondary,
			},
		};
		this.paginator.delete(id);
		for (let i = 0; i < embeds.length; i++) {
			embeds[i].setFooter({
				text: embeds[i].data.footer?.text
					? `${embeds[i].data.footer?.text} | ${this.translate.getTranslation(
							"Tools.Paginator.Embed.Footer",
							interaction.guildLocale,
							{
								Current: String(i + 1),
								Total: String(embeds.length),
							},
						)}`
					: this.translate.getTranslation("Tools.Paginator.Embed.Footer", interaction.guildLocale, {
							Current: String(i + 1),
							Total: String(embeds.length),
						}),
			});
		}
 
		const pages: PageBuilder[] = [];
		for (const embed of embeds) {
			pages.push(new PageBuilder().addEmbed(embed));
		}
 
		return this.paginator
			.register((builder) => builder.setCustomId(id).setPages(pages).setMaxPages(embeds.length))
			.setButtonsAppearance(buttons)
			.build();
	}
}