pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 1 | import Discord, { CommandInteraction, MessageActionRow, Message } from "discord.js"; |
| 2 | import EmojiEmbed from "./generateEmojiEmbed.js" |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 3 | import getEmojiByName from "./getEmojiByName.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 4 | |
| 5 | class 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 | |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 26 | async send(editOnly?: boolean) { |
| 27 | let object = { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 28 | 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") |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 40 | .setStyle("SUCCESS") |
| 41 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")), |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 42 | new Discord.MessageButton() |
| 43 | .setCustomId("no") |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 44 | .setLabel("Cancel") |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 45 | .setStyle("DANGER") |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 46 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 47 | ]) |
| 48 | ], |
| 49 | ephemeral: true, |
| 50 | fetchReply: true |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 51 | } |
| 52 | let m; |
| 53 | if ( editOnly ) { |
| 54 | m = await this.interaction.editReply(object); |
| 55 | } else { |
| 56 | m = await this.interaction.reply(object) |
| 57 | } |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 58 | 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 | } |
pineafan | 5d1908e | 2022-02-28 21:34:47 +0000 | [diff] [blame] | 64 | component.deferUpdate(); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 65 | |
| 66 | return component.customId === "yes" |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | export default confirmationMessage; |