PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed } from "../../../utils/defaults.js"; |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | ActionRowBuilder, |
| 5 | ButtonBuilder, |
| 6 | ButtonStyle, |
| 7 | ChannelSelectMenuBuilder, |
| 8 | ChannelType |
| 9 | } from "discord.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 10 | import EmojiEmbed from "../../../utils/generateEmojiEmbed.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 11 | import getEmojiByName from "../../../utils/getEmojiByName.js"; |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 12 | import type { SlashCommandSubcommandBuilder } from "discord.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 13 | import client from "../../../utils/client.js"; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 14 | import { getCommandMentionByName } from "../../../utils/getCommandDataByName.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 15 | |
| 16 | const command = (builder: SlashCommandSubcommandBuilder) => |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 17 | builder.setName("attachments").setDescription("Where attachments should be logged to (Premium only)"); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 18 | |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 19 | const callback = async (interaction: CommandInteraction): Promise<unknown> => { |
TheCodedProf | 9c51a7e | 2023-02-27 17:11:13 -0500 | [diff] [blame] | 20 | if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {}); |
TheCodedProf | 80ad854 | 2023-03-10 12:52:33 -0500 | [diff] [blame] | 21 | const m = await interaction.reply({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | embeds: LoadingEmbed, |
| 23 | ephemeral: true, |
| 24 | fetchReply: true |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 25 | }); |
| 26 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 27 | if (!(await client.database.premium.hasPremium(interaction.guild!.id))) |
| 28 | return interaction.editReply({ |
| 29 | embeds: [ |
| 30 | new EmojiEmbed() |
| 31 | .setTitle("Premium Required") |
| 32 | .setDescription( |
| 33 | `This feature is exclusive to ${getCommandMentionByName("nucleus/premium")} servers.` |
| 34 | ) |
| 35 | .setStatus("Danger") |
| 36 | .setEmoji("NUCLEUS.PREMIUM") |
| 37 | ] |
| 38 | }); |
| 39 | |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 40 | let data = await client.database.guilds.read(interaction.guild!.id); |
| 41 | let channel = data.logging.staff.channel; |
| 42 | |
| 43 | let closed = false; |
| 44 | do { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 45 | const channelMenu = new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents( |
| 46 | new ChannelSelectMenuBuilder() |
| 47 | .setCustomId("channel") |
| 48 | .setPlaceholder("Select a channel") |
| 49 | .setChannelTypes(ChannelType.GuildText) |
| 50 | ); |
| 51 | const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 52 | new ButtonBuilder() |
| 53 | .setCustomId("clear") |
| 54 | .setLabel("Clear") |
| 55 | .setStyle(ButtonStyle.Danger) |
| 56 | .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji) |
| 57 | .setDisabled(!channel), |
| 58 | new ButtonBuilder() |
| 59 | .setCustomId("save") |
| 60 | .setLabel("Save") |
| 61 | .setStyle(ButtonStyle.Success) |
| 62 | .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji) |
| 63 | .setDisabled(channel === data.logging.staff.channel) |
| 64 | ); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 65 | |
| 66 | const embed = new EmojiEmbed() |
| 67 | .setTitle("Attachments") |
| 68 | .setDescription( |
TheCodedProf | 94ff6de | 2023-02-22 17:47:26 -0500 | [diff] [blame] | 69 | `The channel to send all attachments from the server, allowing you to check them if they are deleted\n` + |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 70 | `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n` |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 71 | ) |
| 72 | .setStatus("Success") |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 73 | .setEmoji("CHANNEL.TEXT.CREATE"); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 74 | |
| 75 | await interaction.editReply({ |
| 76 | embeds: [embed], |
| 77 | components: [channelMenu, buttons] |
| 78 | }); |
| 79 | |
| 80 | let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction; |
| 81 | try { |
TheCodedProf | 80ad854 | 2023-03-10 12:52:33 -0500 | [diff] [blame] | 82 | i = (await m.awaitMessageComponent({ |
pineafan | 96228bd | 2023-02-21 14:22:55 +0000 | [diff] [blame] | 83 | filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 84 | time: 300000 |
| 85 | })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction; |
| 86 | } catch (e) { |
| 87 | closed = true; |
TheCodedProf | 1807fb3 | 2023-02-20 14:33:48 -0500 | [diff] [blame] | 88 | continue; |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 89 | } |
| 90 | await i.deferUpdate(); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 91 | if (i.isButton()) { |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 92 | switch (i.customId) { |
| 93 | case "clear": { |
| 94 | channel = null; |
| 95 | break; |
| 96 | } |
| 97 | case "save": { |
| 98 | await client.database.guilds.write(interaction.guild!.id, { |
| 99 | "logging.attachments.channel": channel |
| 100 | }); |
| 101 | data = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 16ecb17 | 2023-03-05 07:30:32 +0000 | [diff] [blame] | 102 | await client.memory.forceUpdate(interaction.guild!.id); |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 103 | break; |
| 104 | } |
| 105 | } |
| 106 | } else { |
| 107 | channel = i.values[0]!; |
| 108 | } |
TheCodedProf | 01cba76 | 2023-02-18 15:55:05 -0500 | [diff] [blame] | 109 | } while (!closed); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 110 | await interaction.deleteReply(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 111 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 112 | |
TheCodedProf | f86ba09 | 2023-01-27 17:10:07 -0500 | [diff] [blame] | 113 | const check = (interaction: CommandInteraction, _partial: boolean = false) => { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 114 | const member = interaction.member as Discord.GuildMember; |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 115 | if (!member.permissions.has("ManageGuild")) |
| 116 | return "You must have the *Manage Server* permission to use this command"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 117 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 118 | }; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 119 | |
| 120 | export { command }; |
| 121 | export { callback }; |
| 122 | export { check }; |