blob: a3b24ff3f180e2f3587cd799d07e0f8d029e3d00 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf01cba762023-02-18 15:55:05 -05002import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelSelectMenuBuilder } 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";
TheCodedProff86ba092023-01-27 17:10:07 -05005import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan708692b2022-07-24 22:16:22 +01006import client from "../../../utils/client.js";
TheCodedProf01cba762023-02-18 15:55:05 -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> => {
TheCodedProf01cba762023-02-18 15:55:05 -050015 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010016 embeds: LoadingEmbed,
17 ephemeral: true,
18 fetchReply: true
TheCodedProf01cba762023-02-18 15:55:05 -050019 })
Skyler Greyad002172022-08-16 18:48:26 +010020
TheCodedProf1807fb32023-02-20 14:33:48 -050021 if(!await client.database.premium.hasPremium(interaction.guild!.id)) return interaction.editReply({
Skyler Grey75ea9172022-08-06 10:22:23 +010022 embeds: [
23 new EmojiEmbed()
TheCodedProf01cba762023-02-18 15:55:05 -050024 .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(
TheCodedProf21c08592022-09-13 14:14:43 -040044 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010045 .setCustomId("clear")
46 .setLabel("Clear")
TheCodedProf01cba762023-02-18 15:55:05 -050047 .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;
TheCodedProf1807fb32023-02-20 14:33:48 -050080 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050081 }
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()
pineafan63fc5e22022-08-04 22:04:10 +0100103};
pineafan708692b2022-07-24 22:16:22 +0100104
TheCodedProff86ba092023-01-27 17:10:07 -0500105const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000107 if (!member.permissions.has("ManageGuild"))
108 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100109 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100110};
pineafan708692b2022-07-24 22:16:22 +0100111
112export { command };
113export { callback };
114export { check };