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 | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 7 | import type { ButtonInteraction, 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 | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 12 | import { callback as banCallback, check as banCheck } from "../commands/mod/ban.js"; |
| 13 | import { callback as kickCallback, check as kickCheck } from "../commands/mod/kick.js"; |
| 14 | import { callback as muteCallback, check as muteCheck } from "../commands/mod/mute.js"; |
| 15 | import { callback as nicknameCallback, check as nicknameCheck } from "../commands/mod/nick.js"; |
| 16 | import { callback as warnCallback, check as warnCheck } from "../commands/mod/warn.js"; |
| 17 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | export const event = "interactionCreate"; |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 19 | |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 20 | async function errorMessage(interaction: ButtonInteraction, message: string) { |
| 21 | await interaction.reply({ |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 22 | embeds: [new EmojiEmbed().setDescription(message).setStatus("Danger")], |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 23 | ephemeral: true, |
| 24 | components: [] |
| 25 | }); |
| 26 | } |
| 27 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 28 | async function interactionCreate(interaction: Interaction) { |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 29 | if (interaction.isButton()) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 30 | switch (interaction.customId) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 31 | 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 | } |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 52 | } |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 53 | // 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": { |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 60 | const check = await kickCheck(interaction, false, member); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 61 | if (check !== true) return await errorMessage(interaction, check!); |
| 62 | return await kickCallback(interaction, member); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 63 | } |
| 64 | case "ban": { |
| 65 | const check = await banCheck(interaction, false, member); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 66 | if (check !== true) return await errorMessage(interaction, check!); |
| 67 | return await banCallback(interaction, member); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 68 | } |
| 69 | case "mute": { |
| 70 | const check = await muteCheck(interaction, false, member); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 71 | if (check !== true) return await errorMessage(interaction, check!); |
| 72 | return await muteCallback(interaction, member); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 73 | } |
| 74 | case "nickname": { |
| 75 | const check = await nicknameCheck(interaction, false, member); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 76 | if (check !== true) return await errorMessage(interaction, check || "Something went wrong"); |
| 77 | return await nicknameCallback(interaction, member); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 78 | } |
| 79 | case "warn": { |
| 80 | const check = await warnCheck(interaction, false, member); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 81 | if (check !== true) return await errorMessage(interaction, check!); |
| 82 | return await warnCallback(interaction, member); |
| 83 | } |
| 84 | } |
| 85 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 89 | async 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]; |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 94 | const newcolor = accept ? "Success" : "Danger"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 95 | const footer = { |
| 96 | text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`, |
| 97 | iconURL: interaction.user.displayAvatarURL() |
| 98 | }; |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 99 | |
| 100 | const newEmbed = new EmojiEmbed() |
| 101 | .setTitle(embed!.title!) |
| 102 | .setDescription(embed!.description!) |
| 103 | .setFooter(footer) |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 104 | .setStatus(newcolor); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 105 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 106 | await interaction.update({ embeds: [newEmbed], components: [] }); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 107 | } |
| 108 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 109 | export async function callback(_client: NucleusClient, interaction: Interaction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 110 | await interactionCreate(interaction); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 111 | } |