blob: 2b769bbffa8383c718f0de637d46bcf2424ac6b2 [file] [log] [blame]
pineafan4f164f32022-02-26 22:07:12 +00001import Discord, { CommandInteraction, MessageActionRow, Message } from "discord.js";
2import EmojiEmbed from "./generateEmojiEmbed.js"
3
4class confirmationMessage {
5 interaction: CommandInteraction;
6 title: string;
7 emoji: string;
8 description: string;
9 color: string;
10
11 constructor(interaction: CommandInteraction) {
12 this.interaction = interaction;
13
14 this.title = "";
15 this.emoji = "";
16 this.description = "";
17 this.color = "";
18 }
19
20 setTitle(title: string) { this.title = title; return this }
21 setEmoji(emoji: string) { this.emoji = emoji; return this }
22 setDescription(description: string) { this.description = description; return this }
23 setColor(color: string) { this.color = color; return this }
24
25 async send() {
26 let m = await this.interaction.reply({
27 embeds: [
28 new EmojiEmbed()
29 .setEmoji(this.emoji)
30 .setTitle(this.title)
31 .setDescription(this.description)
32 .setStatus(this.color)
33 ],
34 components: [
35 new MessageActionRow().addComponents([
36 new Discord.MessageButton()
37 .setCustomId("yes")
38 .setLabel("Yes")
39 .setStyle("SUCCESS"),
40 new Discord.MessageButton()
41 .setCustomId("no")
42 .setLabel("Cancel") // TODO:
43 .setStyle("DANGER")
44 ])
45 ],
46 ephemeral: true,
47 fetchReply: true
48 })
49 let component;
50 try {
51 component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 2.5 * 60 * 1000});
52 } catch (e) {
53 return false; // TODO: Check the type of the error; change the error message here
54 }
55
56 return component.customId === "yes"
57 }
58}
59
60export default confirmationMessage;