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({ |
| 22 | embeds: [new EmojiEmbed() |
| 23 | .setDescription(message) |
| 24 | .setStatus("Danger") |
| 25 | ], |
| 26 | ephemeral: true, |
| 27 | components: [] |
| 28 | }); |
| 29 | } |
| 30 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 31 | async function interactionCreate(interaction: Interaction) { |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 32 | if (interaction.isButton()) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 33 | switch (interaction.customId) { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 34 | 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 | } |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 55 | } |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame^] | 56 | // 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 | } |
pineafan | ad54d75 | 2022-04-18 19:01:43 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 88 | async 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]; |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 93 | const newcolor = accept ? "Success" : "Danger"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 94 | const footer = { |
| 95 | text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`, |
| 96 | iconURL: interaction.user.displayAvatarURL() |
| 97 | }; |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 98 | |
| 99 | const newEmbed = new EmojiEmbed() |
| 100 | .setTitle(embed!.title!) |
| 101 | .setDescription(embed!.description!) |
| 102 | .setFooter(footer) |
TheCodedProf | 46518a4 | 2023-02-18 17:08:23 -0500 | [diff] [blame] | 103 | .setStatus(newcolor); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 104 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 105 | await interaction.update({ embeds: [newEmbed], components: [] }); |
PineaFan | 1dee28f | 2023-01-16 22:09:07 +0000 | [diff] [blame] | 106 | } |
| 107 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 108 | export async function callback(_client: NucleusClient, interaction: Interaction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 109 | await interactionCreate(interaction); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 110 | } |