blob: 4a8d94181a47b5e71fa8e36fcdbad2f64a772a45 [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
pineafan6de4da52023-03-07 20:43:44 +00007import type { ButtonInteraction, 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
pineafan6de4da52023-03-07 20:43:44 +000012import { callback as banCallback, check as banCheck } from "../commands/mod/ban.js";
13import { callback as kickCallback, check as kickCheck } from "../commands/mod/kick.js";
14import { callback as muteCallback, check as muteCheck } from "../commands/mod/mute.js";
15import { callback as nicknameCallback, check as nicknameCheck } from "../commands/mod/nick.js";
16import { callback as warnCallback, check as warnCheck } from "../commands/mod/warn.js";
17
pineafan63fc5e22022-08-04 22:04:10 +010018export const event = "interactionCreate";
pineafanad54d752022-04-18 19:01:43 +010019
pineafan6de4da52023-03-07 20:43:44 +000020async function errorMessage(interaction: ButtonInteraction, message: string) {
21 await interaction.reply({
22 embeds: [new EmojiEmbed()
23 .setDescription(message)
24 .setStatus("Danger")
25 ],
26 ephemeral: true,
27 components: []
28 });
29}
30
pineafan0f5cc782022-08-12 21:55:42 +010031async function interactionCreate(interaction: Interaction) {
PineaFana34d04b2023-01-03 22:05:42 +000032 if (interaction.isButton()) {
PineaFan538d3752023-01-12 21:48:23 +000033 switch (interaction.customId) {
Skyler Greyda16adf2023-03-05 10:22:12 +000034 case "rolemenu": {
35 return await roleMenu(interaction);
36 }
37 case "verifybutton": {
38 return await verify(interaction);
39 }
40 case "createticket": {
41 return await create(interaction);
42 }
43 case "closeticket": {
44 return await close(interaction);
45 }
46 case "createtranscript": {
47 return await createTranscript(interaction);
48 }
49 case "suggestionAccept": {
50 return await modifySuggestion(interaction, true);
51 }
52 case "suggestionDeny": {
53 return await modifySuggestion(interaction, false);
54 }
pineafan02ba0232022-07-24 22:16:15 +010055 }
pineafan6de4da52023-03-07 20:43:44 +000056 // Mod actions
57 if (interaction.customId.startsWith("mod:")) {
58 const action = interaction.customId.split(":")[1];
59 const memberId = interaction.customId.split(":")[2];
60 const member = await interaction.guild?.members.fetch(memberId!);
61 switch (action) {
62 case "kick": {
63 const check = await kickCheck(interaction, false, member)
64 if (check !== true) return await errorMessage(interaction, check!);
65 return await kickCallback(interaction, member);
66 } case "ban": {
67 const check = await banCheck(interaction, false, member)
68 if (check !== true) return await errorMessage(interaction, check!);
69 return await banCallback(interaction, member);
70 } case "mute": {
71 const check = await muteCheck(interaction, false, member)
72 if (check !== true) return await errorMessage(interaction, check!);
73 return await muteCallback(interaction, member);
74 } case "nickname": {
75 const check = await nicknameCheck(interaction, false, member)
76 if (check !== true) return await errorMessage(interaction, check || "Something went wrong");
77 return await nicknameCallback(interaction, member);
78 } case "warn": {
79 const check = await warnCheck(interaction, false, member)
80 if (check !== true) return await errorMessage(interaction, check!);
81 return await warnCallback(interaction, member);
82 }
83 }
84 }
pineafanad54d752022-04-18 19:01:43 +010085 }
86}
87
PineaFan1dee28f2023-01-16 22:09:07 +000088async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) {
89 const message = await interaction.message;
90 await message.fetch();
91 if (message.embeds.length === 0) return;
92 const embed = message.embeds[0];
TheCodedProf46518a42023-02-18 17:08:23 -050093 const newcolor = accept ? "Success" : "Danger";
Skyler Greyda16adf2023-03-05 10:22:12 +000094 const footer = {
95 text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`,
96 iconURL: interaction.user.displayAvatarURL()
97 };
PineaFan1dee28f2023-01-16 22:09:07 +000098
99 const newEmbed = new EmojiEmbed()
100 .setTitle(embed!.title!)
101 .setDescription(embed!.description!)
102 .setFooter(footer)
TheCodedProf46518a42023-02-18 17:08:23 -0500103 .setStatus(newcolor);
PineaFan1dee28f2023-01-16 22:09:07 +0000104
Skyler Greyda16adf2023-03-05 10:22:12 +0000105 await interaction.update({ embeds: [newEmbed], components: [] });
PineaFan1dee28f2023-01-16 22:09:07 +0000106}
107
PineaFan752af462022-12-31 21:59:38 +0000108export async function callback(_client: NucleusClient, interaction: Interaction) {
pineafan63fc5e22022-08-04 22:04:10 +0100109 await interactionCreate(interaction);
Skyler Grey75ea9172022-08-06 10:22:23 +0100110}