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