blob: 7deb5f54ad76768e4c3858e43ddb526b5fc033dd [file] [log] [blame]
pineafan4f164f32022-02-26 22:07:12 +00001import Discord, { CommandInteraction, MessageActionRow, Message } from "discord.js";
2import EmojiEmbed from "./generateEmojiEmbed.js"
pineafan8b4b17f2022-02-27 20:42:52 +00003import getEmojiByName from "./getEmojiByName.js";
pineafan4f164f32022-02-26 22:07:12 +00004
5class confirmationMessage {
6 interaction: CommandInteraction;
7 title: string;
8 emoji: string;
9 description: string;
10 color: string;
11
12 constructor(interaction: CommandInteraction) {
13 this.interaction = interaction;
14
15 this.title = "";
16 this.emoji = "";
17 this.description = "";
18 this.color = "";
19 }
20
21 setTitle(title: string) { this.title = title; return this }
22 setEmoji(emoji: string) { this.emoji = emoji; return this }
23 setDescription(description: string) { this.description = description; return this }
24 setColor(color: string) { this.color = color; return this }
25
pineafan8b4b17f2022-02-27 20:42:52 +000026 async send(editOnly?: boolean) {
27 let object = {
pineafan4f164f32022-02-26 22:07:12 +000028 embeds: [
29 new EmojiEmbed()
30 .setEmoji(this.emoji)
31 .setTitle(this.title)
32 .setDescription(this.description)
33 .setStatus(this.color)
34 ],
35 components: [
36 new MessageActionRow().addComponents([
37 new Discord.MessageButton()
38 .setCustomId("yes")
39 .setLabel("Yes")
pineafan8b4b17f2022-02-27 20:42:52 +000040 .setStyle("SUCCESS")
41 .setEmoji(getEmojiByName("CONTROL.TICK", "id")),
pineafan4f164f32022-02-26 22:07:12 +000042 new Discord.MessageButton()
43 .setCustomId("no")
pineafan8b4b17f2022-02-27 20:42:52 +000044 .setLabel("Cancel")
pineafan4f164f32022-02-26 22:07:12 +000045 .setStyle("DANGER")
pineafan8b4b17f2022-02-27 20:42:52 +000046 .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
pineafan4f164f32022-02-26 22:07:12 +000047 ])
48 ],
49 ephemeral: true,
50 fetchReply: true
pineafan8b4b17f2022-02-27 20:42:52 +000051 }
52 let m;
53 if ( editOnly ) {
54 m = await this.interaction.editReply(object);
55 } else {
56 m = await this.interaction.reply(object)
57 }
pineafan4f164f32022-02-26 22:07:12 +000058 let component;
59 try {
60 component = await (m as Message).awaitMessageComponent({filter: (m) => m.user.id === this.interaction.user.id, time: 2.5 * 60 * 1000});
61 } catch (e) {
62 return false; // TODO: Check the type of the error; change the error message here
63 }
pineafan5d1908e2022-02-28 21:34:47 +000064 component.deferUpdate();
pineafan4f164f32022-02-26 22:07:12 +000065
66 return component.customId === "yes"
67 }
68}
69
70export default confirmationMessage;