blob: c91f8cdb7d66df03f2433ea95c17a39d836d4d31 [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
pineafan0f5cc782022-08-12 21:55:42 +010014async function interactionCreate(interaction: Interaction) {
PineaFana34d04b2023-01-03 22:05:42 +000015 if (interaction.isButton()) {
PineaFan538d3752023-01-12 21:48:23 +000016 switch (interaction.customId) {
Skyler Greyda16adf2023-03-05 10:22:12 +000017 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 }
pineafan02ba0232022-07-24 22:16:15 +010038 }
pineafanad54d752022-04-18 19:01:43 +010039 }
40}
41
PineaFan1dee28f2023-01-16 22:09:07 +000042async 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];
TheCodedProf46518a42023-02-18 17:08:23 -050047 const newcolor = accept ? "Success" : "Danger";
Skyler Greyda16adf2023-03-05 10:22:12 +000048 const footer = {
49 text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`,
50 iconURL: interaction.user.displayAvatarURL()
51 };
PineaFan1dee28f2023-01-16 22:09:07 +000052
53 const newEmbed = new EmojiEmbed()
54 .setTitle(embed!.title!)
55 .setDescription(embed!.description!)
56 .setFooter(footer)
TheCodedProf46518a42023-02-18 17:08:23 -050057 .setStatus(newcolor);
PineaFan1dee28f2023-01-16 22:09:07 +000058
Skyler Greyda16adf2023-03-05 10:22:12 +000059 await interaction.update({ embeds: [newEmbed], components: [] });
PineaFan1dee28f2023-01-16 22:09:07 +000060}
61
PineaFan752af462022-12-31 21:59:38 +000062export async function callback(_client: NucleusClient, interaction: Interaction) {
pineafan63fc5e22022-08-04 22:04:10 +010063 await interactionCreate(interaction);
Skyler Grey75ea9172022-08-06 10:22:23 +010064}