blob: 3b0cd625d6c6caf957b22046eb433df32db23c59 [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({
pineafan1e462ab2023-03-07 21:34:06 +000022 embeds: [new EmojiEmbed().setDescription(message).setStatus("Danger")],
pineafan6de4da52023-03-07 20:43:44 +000023 ephemeral: true,
24 components: []
25 });
26}
27
pineafan0f5cc782022-08-12 21:55:42 +010028async function interactionCreate(interaction: Interaction) {
PineaFana34d04b2023-01-03 22:05:42 +000029 if (interaction.isButton()) {
PineaFan538d3752023-01-12 21:48:23 +000030 switch (interaction.customId) {
Skyler Greyda16adf2023-03-05 10:22:12 +000031 case "rolemenu": {
32 return await roleMenu(interaction);
33 }
34 case "verifybutton": {
35 return await verify(interaction);
36 }
37 case "createticket": {
38 return await create(interaction);
39 }
40 case "closeticket": {
41 return await close(interaction);
42 }
43 case "createtranscript": {
44 return await createTranscript(interaction);
45 }
46 case "suggestionAccept": {
47 return await modifySuggestion(interaction, true);
48 }
49 case "suggestionDeny": {
50 return await modifySuggestion(interaction, false);
51 }
pineafan02ba0232022-07-24 22:16:15 +010052 }
pineafan6de4da52023-03-07 20:43:44 +000053 // Mod actions
54 if (interaction.customId.startsWith("mod:")) {
55 const action = interaction.customId.split(":")[1];
56 const memberId = interaction.customId.split(":")[2];
57 const member = await interaction.guild?.members.fetch(memberId!);
58 switch (action) {
59 case "kick": {
pineafan1e462ab2023-03-07 21:34:06 +000060 const check = await kickCheck(interaction, false, member);
pineafan6de4da52023-03-07 20:43:44 +000061 if (check !== true) return await errorMessage(interaction, check!);
62 return await kickCallback(interaction, member);
pineafan1e462ab2023-03-07 21:34:06 +000063 }
64 case "ban": {
65 const check = await banCheck(interaction, false, member);
pineafan6de4da52023-03-07 20:43:44 +000066 if (check !== true) return await errorMessage(interaction, check!);
67 return await banCallback(interaction, member);
pineafan1e462ab2023-03-07 21:34:06 +000068 }
69 case "mute": {
70 const check = await muteCheck(interaction, false, member);
pineafan6de4da52023-03-07 20:43:44 +000071 if (check !== true) return await errorMessage(interaction, check!);
72 return await muteCallback(interaction, member);
pineafan1e462ab2023-03-07 21:34:06 +000073 }
74 case "nickname": {
75 const check = await nicknameCheck(interaction, false, member);
pineafan6de4da52023-03-07 20:43:44 +000076 if (check !== true) return await errorMessage(interaction, check || "Something went wrong");
77 return await nicknameCallback(interaction, member);
pineafan1e462ab2023-03-07 21:34:06 +000078 }
79 case "warn": {
80 const check = await warnCheck(interaction, false, member);
pineafan6de4da52023-03-07 20:43:44 +000081 if (check !== true) return await errorMessage(interaction, check!);
82 return await warnCallback(interaction, member);
83 }
84 }
85 }
pineafanad54d752022-04-18 19:01:43 +010086 }
87}
88
PineaFan1dee28f2023-01-16 22:09:07 +000089async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) {
90 const message = await interaction.message;
91 await message.fetch();
92 if (message.embeds.length === 0) return;
93 const embed = message.embeds[0];
TheCodedProf46518a42023-02-18 17:08:23 -050094 const newcolor = accept ? "Success" : "Danger";
Skyler Greyda16adf2023-03-05 10:22:12 +000095 const footer = {
96 text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`,
97 iconURL: interaction.user.displayAvatarURL()
98 };
PineaFan1dee28f2023-01-16 22:09:07 +000099
100 const newEmbed = new EmojiEmbed()
101 .setTitle(embed!.title!)
102 .setDescription(embed!.description!)
103 .setFooter(footer)
TheCodedProf46518a42023-02-18 17:08:23 -0500104 .setStatus(newcolor);
PineaFan1dee28f2023-01-16 22:09:07 +0000105
Skyler Greyda16adf2023-03-05 10:22:12 +0000106 await interaction.update({ embeds: [newEmbed], components: [] });
PineaFan1dee28f2023-01-16 22:09:07 +0000107}
108
PineaFan752af462022-12-31 21:59:38 +0000109export async function callback(_client: NucleusClient, interaction: Interaction) {
pineafan63fc5e22022-08-04 22:04:10 +0100110 await interactionCreate(interaction);
Skyler Grey75ea9172022-08-06 10:22:23 +0100111}