All files / src/modules/bot/commands Interaction.ts

0% Statements 0/10
0% Branches 0/5
0% Functions 0/5
0% Lines 0/10

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                                                                                                                                                       
import { Content } from "@/types";
import { messageOptions } from "@/utils/Tools";
import {
	BaseMessageOptions,
	CommandInteraction,
	EmbedBuilder,
	InteractionReplyOptions,
	InteractionUpdateOptions,
	Message,
	MessageComponentInteraction,
} from "discord.js";
 
export class InteractionTools {
	public static async deferReply(
		interaction: CommandInteraction | MessageComponentInteraction,
		ephemeral = false,
	): Promise<unknown> {
		return interaction.deferReply({
			ephemeral,
		});
	}
 
	public static async deferUpdate(interaction: MessageComponentInteraction): Promise<unknown> {
		return await interaction.deferUpdate();
	}
 
	/**
	 * @method Reply or followUp(reply again) the interaction
	 */
 
	public static async reply(
		interaction: CommandInteraction | MessageComponentInteraction,
		content: Content,
		ephemeral: boolean,
	): Promise<Message> {
		const msgOptions = messageOptions(content) as InteractionReplyOptions;
 
		if (interaction.deferred || interaction.replied) {
			return await interaction.followUp({
				...msgOptions,
				ephemeral,
			});
		}
		return await interaction.reply({
			...msgOptions,
			ephemeral,
			fetchReply: true,
		});
	}
 
	/**
	 * @method Edit the interaction
	 */
 
	public static async editReply(
		interaction: CommandInteraction | MessageComponentInteraction,
		content: string | EmbedBuilder | BaseMessageOptions,
	): Promise<Message> {
		const msgOptions = messageOptions(content);
		return await interaction.editReply({
			...msgOptions,
		});
	}
 
	public static async update(
		interaction: MessageComponentInteraction,
		content: string | EmbedBuilder | BaseMessageOptions,
	): Promise<Message> {
		const msgOptions = messageOptions(content) as InteractionUpdateOptions;
		return await interaction.update({
			...msgOptions,
			fetchReply: true,
		});
	}
}