blob: 80c2c1be3317fd298af706e0783f0cd3dd4cd0b5 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { callback as roleMenu } from "../actions/roleMenu.js";
pineafan73a7c4a2022-07-24 10:38:04 +01002import verify from "../reflex/verify.js";
3import create from "../actions/tickets/create.js";
4import close from "../actions/tickets/delete.js";
5import createTranscript from "../premium/createTranscript.js";
PineaFana34d04b2023-01-03 22:05:42 +00006
PineaFan538d3752023-01-12 21:48:23 +00007import type { Interaction } from "discord.js";
PineaFan1dee28f2023-01-16 22:09:07 +00008import type Discord from "discord.js";
PineaFan752af462022-12-31 21:59:38 +00009import type { NucleusClient } from "../utils/client.js";
PineaFan1dee28f2023-01-16 22:09:07 +000010import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafanad54d752022-04-18 19:01:43 +010011
pineafan63fc5e22022-08-04 22:04:10 +010012export const event = "interactionCreate";
pineafanad54d752022-04-18 19:01:43 +010013
pineafan02ba0232022-07-24 22:16:15 +010014
pineafan0f5cc782022-08-12 21:55:42 +010015async function interactionCreate(interaction: Interaction) {
PineaFana34d04b2023-01-03 22:05:42 +000016 if (interaction.isButton()) {
PineaFan538d3752023-01-12 21:48:23 +000017 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); }
PineaFan1dee28f2023-01-16 22:09:07 +000023 case "suggestionAccept": { return await modifySuggestion(interaction, true); }
24 case "suggestionDeny": { return await modifySuggestion(interaction, false); }
pineafan02ba0232022-07-24 22:16:15 +010025 }
pineafanad54d752022-04-18 19:01:43 +010026 }
27}
28
PineaFan1dee28f2023-01-16 22:09:07 +000029async 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];
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050034 const newcolor = accept ? "Success" : "Danger";
PineaFan1dee28f2023-01-16 22:09:07 +000035 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)
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050041 .setStatus(newcolor);
PineaFan1dee28f2023-01-16 22:09:07 +000042
43 await interaction.update({embeds: [newEmbed], components: []});
44}
45
PineaFan752af462022-12-31 21:59:38 +000046export async function callback(_client: NucleusClient, interaction: Interaction) {
pineafan63fc5e22022-08-04 22:04:10 +010047 await interactionCreate(interaction);
Skyler Grey75ea9172022-08-06 10:22:23 +010048}