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" |
| 3 | |
| 4 | class 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 | |
| 60 | export default confirmationMessage; |