blob: 8f0b257dd6d1541d144c625f482581419726abf7 [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> => {
TheCodedProf9c51a7e2023-02-27 17:11:13 -050015 if (interaction.guild) client.database.premium.hasPremium(interaction.guild.id).finally(() => {});
TheCodedProf01cba762023-02-18 15:55:05 -050016 await interaction.reply({
Skyler Grey75ea9172022-08-06 10:22:23 +010017 embeds: LoadingEmbed,
18 ephemeral: true,
19 fetchReply: true
TheCodedProf01cba762023-02-18 15:55:05 -050020 })
Skyler Greyad002172022-08-16 18:48:26 +010021
TheCodedProf1807fb32023-02-20 14:33:48 -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()
TheCodedProf01cba762023-02-18 15:55:05 -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")
TheCodedProf94ff6de2023-02-22 17:47:26 -050042 .setChannelTypes(ChannelType.GuildText)
TheCodedProf01cba762023-02-18 15:55:05 -050043 );
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")
TheCodedProf01cba762023-02-18 15:55:05 -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(
TheCodedProf94ff6de2023-02-22 17:47:26 -050063 `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 -050064 `**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({
pineafan96228bd2023-02-21 14:22:55 +000077 filter: (i: Discord.Interaction) => i.user.id === interaction.user.id,
TheCodedProf01cba762023-02-18 15:55:05 -050078 time: 300000
79 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction;
80 } catch (e) {
81 closed = true;
TheCodedProf1807fb32023-02-20 14:33:48 -050082 continue;
TheCodedProf01cba762023-02-18 15:55:05 -050083 }
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);
Skyler Grey16ecb172023-03-05 07:30:32 +000096 await client.memory.forceUpdate(interaction.guild!.id);
TheCodedProf01cba762023-02-18 15:55:05 -050097 break;
98 }
99 }
100 } else {
101 channel = i.values[0]!;
102 }
103
104 } while (!closed);
105 await interaction.deleteReply()
pineafan63fc5e22022-08-04 22:04:10 +0100106};
pineafan708692b2022-07-24 22:16:22 +0100107
TheCodedProff86ba092023-01-27 17:10:07 -0500108const check = (interaction: CommandInteraction, _partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 const member = interaction.member as Discord.GuildMember;
PineaFan0d06edc2023-01-17 22:10:31 +0000110 if (!member.permissions.has("ManageGuild"))
111 return "You must have the *Manage Server* permission to use this command";
pineafan708692b2022-07-24 22:16:22 +0100112 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100113};
pineafan708692b2022-07-24 22:16:22 +0100114
115export { command };
116export { callback };
117export { check };