pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { callback as roleMenu } from "../actions/roleMenu.js"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 2 | import verify from "../reflex/verify.js"; |
| 3 | import create from "../actions/tickets/create.js"; |
| 4 | import close from "../actions/tickets/delete.js"; |
| 5 | import createTranscript from "../premium/createTranscript.js"; |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 6 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 7 | import type { Interaction } from "discord.js"; |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 8 | import type Discord from "discord.js"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 9 | import type { NucleusClient } from "../utils/client.js"; |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 10 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 11 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | export const event = "interactionCreate"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 13 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 14 | async function interactionCreate(interaction: Interaction) { |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 15 | if (interaction.isButton()) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 16 | switch (interaction.customId) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 17 | case "rolemenu": { |
| 18 | return await roleMenu(interaction); |
| 19 | } |
| 20 | case "verifybutton": { |
| 21 | return await verify(interaction); |
| 22 | } |
| 23 | case "createticket": { |
| 24 | return await create(interaction); |
| 25 | } |
| 26 | case "closeticket": { |
| 27 | return await close(interaction); |
| 28 | } |
| 29 | case "createtranscript": { |
| 30 | return await createTranscript(interaction); |
| 31 | } |
| 32 | case "suggestionAccept": { |
| 33 | return await modifySuggestion(interaction, true); |
| 34 | } |
| 35 | case "suggestionDeny": { |
| 36 | return await modifySuggestion(interaction, false); |
| 37 | } |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 38 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 42 | async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) { |
| 43 | const message = await interaction.message; |
| 44 | await message.fetch(); |
| 45 | if (message.embeds.length === 0) return; |
| 46 | const embed = message.embeds[0]; |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 47 | const newcolor = accept ? "Success" : "Danger"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 48 | const footer = { |
| 49 | text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`, |
| 50 | iconURL: interaction.user.displayAvatarURL() |
| 51 | }; |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 52 | |
| 53 | const newEmbed = new EmojiEmbed() |
| 54 | .setTitle(embed!.title!) |
| 55 | .setDescription(embed!.description!) |
| 56 | .setFooter(footer) |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 57 | .setStatus(newcolor); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 58 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 59 | await interaction.update({ embeds: [newEmbed], components: [] }); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 60 | } |
| 61 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 62 | export async function callback(_client: NucleusClient, interaction: Interaction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 63 | await interactionCreate(interaction); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 64 | } |