blob: 238b8b99a5ca38d5622ae14022e72c820faa1503 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05002import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelSelectMenuBuilder, ChannelType } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +01003import EmojiEmbed from "../../../utils/generateEmojiEmbed.js";
pineafan708692b2022-07-24 22:16:22 +01004import getEmojiByName from "../../../utils/getEmojiByName.js";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05005import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +01006import client from "../../../utils/client.js";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05007import { getCommandMentionByName } from "../../../utils/getCommandDataByName.js";
pineafan708692b2022-07-24 22:16:22 +01008
9const command = (builder: SlashCommandSubcommandBuilder) =>
10 builder
pineafan63fc5e22022-08-04 22:04:10 +010011 .setName("attachments")
12 .setDescription("Where attachments should be logged to (Premium only)")
pineafan708692b2022-07-24 22:16:22 +010013
pineafan3a02ea32022-08-11 21:35:04 +010014const callback = async (interaction: CommandInteraction): Promise<unknown> => {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050015 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
16 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010017 embeds: LoadingEmbed,
18 ephemeral: true,
19 fetchReply: true
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050020 })
Skyler Greyad002172022-08-16 18:48:26 +010021
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050022 if(!await client.database.premium.hasPremium(interaction.guild!.id)) return interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010023 embeds: [
24 new EmojiEmbed()
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050025 .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")
42 .setChannelTypes(ChannelType.GuildText)
43 );
44 const buttons = new ActionRowBuilder<ButtonBuilder>()
45 .addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -040046 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010047 .setCustomId("clear")
48 .setLabel("Clear")
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050049 .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(
63 `The channel to send all attachments from the server, allowing you to check them if they are deleted\n` +
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({
77 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
78 time: 300000
79 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
80 } catch (e) {
81 closed = true;
82 continue;
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()
pineafan63fc5e22022-08-04 22:04:10 +0100105};
pineafan708692b2022-07-24 22:16:22 +0100106
Samuel Shuert27bf3cd2023-03-03 15:51:25 -0500107const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100108 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000109 if (!member.permissions.has("ManageGuild"))
110 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100111 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100112};
pineafan708692b2022-07-24 22:16:22 +0100113
114export { command };
115export { callback };
116export { check };