blob: c04c7cf6bf4f30bef00a96da6a2532853cb1048e [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../../../utils/defaults.js";
TheCodedProf94ff6de2023-02-22 17:47:26 -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";
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")
TheCodedProf94ff6de2023-02-22 17:47:26 -050041 .setChannelTypes(ChannelType.GuildText)
TheCodedProf01cba762023-02-18 15:55:05 -050042 );
43 const buttons = new ActionRowBuilder<ButtonBuilder>()
44 .addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -040045 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010046 .setCustomId("clear")
47 .setLabel("Clear")
TheCodedProf01cba762023-02-18 15:55:05 -050048 .setStyle(ButtonStyle.Danger)
49 .setEmoji(getEmojiByName("CONTROL.CROSS", "id") as Discord.APIMessageComponentEmoji)
50 .setDisabled(!channel),
51 new ButtonBuilder()
52 .setCustomId("save")
53 .setLabel("Save")
54 .setStyle(ButtonStyle.Success)
55 .setEmoji(getEmojiByName("ICONS.SAVE", "id") as Discord.APIMessageComponentEmoji)
56 .setDisabled(channel === data.logging.staff.channel)
57 );
58
59 const embed = new EmojiEmbed()
60 .setTitle("Attachments")
61 .setDescription(
TheCodedProf94ff6de2023-02-22 17:47:26 -050062 `The channel to send all attachments from the server, allowing you to check them if they are deleted\n` +
TheCodedProf01cba762023-02-18 15:55:05 -050063 `**Channel:** ${channel ? `<#${channel}>` : "*None*"}\n`
64 )
65 .setStatus("Success")
66 .setEmoji("CHANNEL.TEXT.CREATE")
67
68 await interaction.editReply({
69 embeds: [embed],
70 components: [channelMenu, buttons]
71 });
72
73 let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction;
74 try {
75 i = (await interaction.channel!.awaitMessageComponent({
pineafan96228bd2023-02-21 14:22:55 +000076 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050077 time: 300000
78 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
79 } catch (e) {
80 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050081 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050082 }
83 await i.deferUpdate();
84 if(i.isButton()) {
85 switch (i.customId) {
86 case "clear": {
87 channel = null;
88 break;
89 }
90 case "save": {
91 await client.database.guilds.write(interaction.guild!.id, {
92 "logging.attachments.channel": channel
93 });
94 data = await client.database.guilds.read(interaction.guild!.id);
95 break;
96 }
97 }
98 } else {
99 channel = i.values[0]!;
100 }
101
102 } while (!closed);
103 await interaction.deleteReply()
pineafan63fc5e22022-08-04 22:04:10 +0100104};
pineafan708692b2022-07-24 22:16:22 +0100105
TheCodedProff86ba092023-01-27 17:10:07 -0500106const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100107 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000108 if (!member.permissions.has("ManageGuild"))
109 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100110 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100111};
pineafan708692b2022-07-24 22:16:22 +0100112
113export { command };
114export { callback };
115export { check };