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