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 | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 14 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 15 | async function interactionCreate(interaction: Interaction) { |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 16 | if (interaction.isButton()) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 17 | switch (interaction.customId) { |
| 18 | case "rolemenu": { return await roleMenu(interaction); } |
| 19 | case "verifybutton": { return await verify(interaction); } |
| 20 | case "createticket": { return await create(interaction); } |
| 21 | case "closeticket": { return await close(interaction); } |
| 22 | case "createtranscript": { return await createTranscript(interaction); } |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 23 | case "suggestionAccept": { return await modifySuggestion(interaction, true); } |
| 24 | case "suggestionDeny": { return await modifySuggestion(interaction, false); } |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 25 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 29 | async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) { |
| 30 | const message = await interaction.message; |
| 31 | await message.fetch(); |
| 32 | if (message.embeds.length === 0) return; |
| 33 | const embed = message.embeds[0]; |
| 34 | const newColour = accept ? "Success" : "Danger"; |
| 35 | const footer = {text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL()}; |
| 36 | |
| 37 | const newEmbed = new EmojiEmbed() |
| 38 | .setTitle(embed!.title!) |
| 39 | .setDescription(embed!.description!) |
| 40 | .setFooter(footer) |
| 41 | .setStatus(newColour); |
| 42 | |
| 43 | await interaction.update({embeds: [newEmbed], components: []}); |
| 44 | } |
| 45 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 46 | export async function callback(_client: NucleusClient, interaction: Interaction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 47 | await interactionCreate(interaction); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | } |