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