PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 1 | import { TextInputBuilder } from "@discordjs/builders"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 4 | Interaction, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 5 | Message, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 6 | ActionRowBuilder, |
| 7 | ButtonBuilder, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 8 | MessageComponentInteraction, |
| 9 | ModalSubmitInteraction, |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 10 | ButtonStyle, |
| 11 | TextInputStyle |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 12 | } from "discord.js"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 13 | import { modalInteractionCollector } from "./dualCollector.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | import EmojiEmbed from "./generateEmojiEmbed.js"; |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 15 | import getEmojiByName from "./getEmojiByName.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 16 | |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 17 | interface CustomBoolean<T> { |
| 18 | title: string; |
| 19 | disabled: boolean; |
| 20 | value: string | null; |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame^] | 21 | notValue: string | null; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 22 | emoji: string | undefined; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 23 | active: boolean; |
| 24 | onClick: () => Promise<T>; |
| 25 | response: T | null; |
| 26 | } |
| 27 | |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 28 | class confirmationMessage { |
| 29 | interaction: CommandInteraction; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | title = ""; |
| 31 | emoji = ""; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 32 | redEmoji: string | null = null; |
| 33 | timeoutText: string | null = null; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | description = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | color: "Danger" | "Warning" | "Success" = "Success"; |
| 36 | customButtons: Record<string, CustomBoolean<unknown>> = {}; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 37 | inverted = false; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 38 | reason: string | null = null; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 39 | |
| 40 | constructor(interaction: CommandInteraction) { |
| 41 | this.interaction = interaction; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 44 | setTitle(title: string) { |
| 45 | this.title = title; |
| 46 | return this; |
| 47 | } |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 48 | setEmoji(emoji: string, redEmoji?: string) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 49 | this.emoji = emoji; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 50 | if (redEmoji) this.redEmoji = redEmoji; // TODO: go through all confirmation messages and change them to use this, and not do their own edits |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 51 | return this; |
| 52 | } |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 53 | setDescription(description: string, timedOut?: string) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | this.description = description; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 55 | if (timedOut) this.timeoutText = timedOut; // TODO also this |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 56 | return this; |
| 57 | } |
| 58 | setColor(color: "Danger" | "Warning" | "Success") { |
| 59 | this.color = color; |
| 60 | return this; |
| 61 | } |
| 62 | setInverted(inverted: boolean) { |
| 63 | this.inverted = inverted; |
| 64 | return this; |
| 65 | } |
| 66 | addCustomBoolean( |
| 67 | customId: string, |
| 68 | title: string, |
| 69 | disabled: boolean, |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 70 | callback: (() => Promise<unknown>) | null = async () => null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 71 | callbackClicked: string | null, |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame^] | 72 | callbackNotClicked: string | null, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 73 | emoji?: string, |
| 74 | initial?: boolean |
| 75 | ) { |
| 76 | this.customButtons[customId] = { |
| 77 | title: title, |
| 78 | disabled: disabled, |
| 79 | value: callbackClicked, |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame^] | 80 | notValue: callbackNotClicked, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 81 | emoji: emoji, |
| 82 | active: initial ?? false, |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 83 | onClick: callback ?? (async () => null), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 84 | response: null |
| 85 | }; |
| 86 | return this; |
pineafan | 6fb3e07 | 2022-05-20 19:27:23 +0100 | [diff] [blame] | 87 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 88 | addReasonButton(reason: string) { |
| 89 | this.reason = reason; |
| 90 | return this; |
| 91 | } |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 92 | async send(editOnly?: boolean): Promise<{ |
| 93 | success?: boolean; |
| 94 | cancelled?: boolean; |
| 95 | components?: Record<string, CustomBoolean<unknown>>; |
| 96 | newReason?: string; |
| 97 | }> { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 98 | let cancelled = false; |
| 99 | let success: boolean | undefined = undefined; |
| 100 | let returnComponents = false; |
| 101 | let newReason = undefined; |
| 102 | |
| 103 | while (!cancelled && success === undefined && !returnComponents && !newReason) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 104 | const fullComponents = [ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 105 | new Discord.ButtonBuilder() |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 106 | .setCustomId("yes") |
| 107 | .setLabel("Confirm") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 108 | .setStyle(this.inverted ? ButtonStyle.Success : ButtonStyle.Danger) |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 109 | .setEmoji(getEmojiByName("CONTROL.TICK", "id")), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 110 | new Discord.ButtonBuilder() |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 111 | .setCustomId("no") |
| 112 | .setLabel("Cancel") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 113 | .setStyle(ButtonStyle.Secondary) |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 114 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id")) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 115 | ]; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 116 | Object.entries(this.customButtons).forEach(([k, v]) => { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 117 | const button = new Discord.ButtonBuilder() |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 118 | .setCustomId(k) |
| 119 | .setLabel(v.title) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 120 | .setStyle(v.active ? ButtonStyle.Success : ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 121 | .setDisabled(v.disabled); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 122 | if (v.emoji !== undefined) button.setEmoji(getEmojiByName(v.emoji, "id")); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | fullComponents.push(button); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 124 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 125 | if (this.reason !== null) |
| 126 | fullComponents.push( |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 127 | new Discord.ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 128 | .setCustomId("reason") |
| 129 | .setLabel("Edit Reason") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 130 | .setStyle(ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 131 | .setEmoji(getEmojiByName("ICONS.EDIT", "id")) |
| 132 | .setDisabled(false) |
| 133 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 134 | const components = []; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 135 | for (let i = 0; i < fullComponents.length; i += 5) { |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 136 | components.push(new ActionRowBuilder< |
| 137 | Discord.ButtonBuilder | Discord.StringSelectMenuBuilder | |
| 138 | Discord.RoleSelectMenuBuilder | Discord.UserSelectMenuBuilder |
| 139 | >().addComponents(fullComponents.slice(i, i + 5))); |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 140 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 141 | const object = { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 142 | embeds: [ |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 143 | new EmojiEmbed() |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 144 | .setEmoji(this.emoji) |
| 145 | .setTitle(this.title) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 146 | .setDescription( |
| 147 | this.description + |
| 148 | "\n\n" + |
| 149 | Object.values(this.customButtons) |
| 150 | .map((v) => { |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame^] | 151 | if (v.active) { |
| 152 | return v.value ? `*${v.value}*\n` : ""; |
| 153 | } else { |
| 154 | return v.notValue ? `*${v.notValue}*\n` : ""; |
| 155 | } |
| 156 | }).join("") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 157 | ) |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 158 | .setStatus(this.color) |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 159 | ], |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 160 | components: components, |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 161 | ephemeral: true, |
| 162 | fetchReply: true |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 163 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 164 | let m: Message; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 165 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 166 | if (editOnly) { |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 167 | m = (await this.interaction.editReply(object)) as unknown as Message; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 168 | } else { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 169 | m = (await this.interaction.reply(object)) as unknown as Message; |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 170 | } |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame^] | 171 | } catch (e) { |
| 172 | console.log(e); |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 173 | cancelled = true; |
| 174 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 175 | } |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 176 | let component; |
| 177 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 178 | component = await m.awaitMessageComponent({ |
| 179 | filter: (m) => m.user.id === this.interaction.user.id, |
| 180 | time: 300000 |
| 181 | }); |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 182 | } catch (e) { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 183 | success = false; |
| 184 | returnComponents = true; |
| 185 | continue; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 186 | } |
| 187 | if (component.customId === "yes") { |
| 188 | component.deferUpdate(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 189 | for (const v of Object.values(this.customButtons)) { |
| 190 | if (!v.active) continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 191 | try { |
| 192 | v.response = await v.onClick(); |
| 193 | } catch (e) { |
| 194 | console.log(e); |
| 195 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 196 | } |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 197 | success = true; |
| 198 | returnComponents = true; |
| 199 | continue; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 200 | } else if (component.customId === "no") { |
| 201 | component.deferUpdate(); |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 202 | success = false; |
| 203 | returnComponents = true; |
| 204 | continue; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 205 | } else if (component.customId === "reason") { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 206 | await component.showModal( |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 207 | new Discord.ModalBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 208 | .setCustomId("modal") |
| 209 | .setTitle("Editing reason") |
| 210 | .addComponents( |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 211 | new ActionRowBuilder<TextInputBuilder>().addComponents( |
| 212 | new TextInputBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 213 | .setCustomId("reason") |
| 214 | .setLabel("Reason") |
| 215 | .setMaxLength(2000) |
| 216 | .setRequired(false) |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 217 | .setStyle(TextInputStyle.Paragraph) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 218 | .setPlaceholder("Spammed in #general") |
| 219 | .setValue(this.reason ? this.reason : "") |
| 220 | ) |
| 221 | ) |
| 222 | ); |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 223 | await this.interaction.editReply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 224 | embeds: [ |
| 225 | new EmojiEmbed() |
| 226 | .setTitle(this.title) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 227 | .setDescription("Modal opened. If you can't see it, click back and try again.") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 228 | .setStatus(this.color) |
| 229 | .setEmoji(this.emoji) |
| 230 | ], |
| 231 | components: [ |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 232 | new ActionRowBuilder<Discord.ButtonBuilder>().addComponents( |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 233 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 234 | .setLabel("Back") |
| 235 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 236 | .setStyle(ButtonStyle.Primary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 237 | .setCustomId("back") |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 238 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 239 | ] |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 240 | }); |
| 241 | let out; |
| 242 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 243 | out = await modalInteractionCollector( |
| 244 | m, |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 245 | (m: Interaction) => |
| 246 | (m as MessageComponentInteraction | ModalSubmitInteraction).channelId === |
| 247 | this.interaction.channelId, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 248 | (m) => m.customId === "reason" |
| 249 | ); |
| 250 | } catch (e) { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 251 | cancelled = true; |
| 252 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 253 | } |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 254 | if (out === null) { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 255 | cancelled = true; |
| 256 | continue; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 257 | } |
| 258 | if (out instanceof ModalSubmitInteraction) { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 259 | newReason = out.fields.getTextInputValue("reason"); |
| 260 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 261 | } else { |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 262 | returnComponents = true; |
| 263 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 264 | } |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 265 | } else { |
| 266 | component.deferUpdate(); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 267 | this.customButtons[component.customId]!.active = !this.customButtons[component.customId]!.active; |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 268 | returnComponents = true; |
| 269 | continue; |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 270 | } |
pineafan | 8b4b17f | 2022-02-27 20:42:52 +0000 | [diff] [blame] | 271 | } |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 272 | const returnValue: Awaited<ReturnType<typeof this.send>> = {}; |
| 273 | |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 274 | if (returnComponents || success !== undefined) returnValue.components = this.customButtons; |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 275 | if (success !== undefined) returnValue.success = success; |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 276 | if (cancelled) { |
| 277 | await this.timeoutError() |
| 278 | returnValue.cancelled = true; |
| 279 | } |
Skyler Grey | a402d1c | 2022-08-13 23:18:16 +0100 | [diff] [blame] | 280 | if (newReason) returnValue.newReason = newReason; |
| 281 | |
PineaFan | 100df68 | 2023-01-02 13:26:08 +0000 | [diff] [blame] | 282 | const typedReturnValue = returnValue as {cancelled: true} | |
| 283 | { success: boolean, components: Record<string, CustomBoolean<unknown>>, newReason?: string} | |
| 284 | { newReason: string, components: Record<string, CustomBoolean<unknown>> } | |
| 285 | { components: Record<string, CustomBoolean<unknown>> }; |
| 286 | |
| 287 | return typedReturnValue; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 288 | } |
pineafan | 62ce192 | 2022-08-25 20:34:45 +0100 | [diff] [blame] | 289 | |
| 290 | async timeoutError(): Promise<void> { |
| 291 | await this.interaction.editReply({ |
| 292 | embeds: [ |
| 293 | new EmojiEmbed() |
| 294 | .setTitle(this.title) |
| 295 | .setDescription("We closed this message because it was not used for a while.") |
| 296 | .setStatus("Danger") |
| 297 | .setEmoji(this.redEmoji ?? this.emoji) |
| 298 | ], |
| 299 | components: [] |
| 300 | }) |
| 301 | } |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 302 | } |
| 303 | |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 304 | export default confirmationMessage; |