blob: 46784f5694ae36f2f53a5f226d91fb36367a045f [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../utils/defaults.js";
TheCodedProff86ba092023-01-27 17:10:07 -05002import Discord, { SlashCommandBuilder, CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuOptionBuilder, SelectMenuOptionBuilder, StringSelectMenuBuilder } from "discord.js";
pineafan73a7c4a2022-07-24 10:38:04 +01003import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafane23c4ec2022-07-27 21:56:27 +01004import getEmojiByName from "../utils/getEmojiByName.js";
5import createPageIndicator from "../utils/createPageIndicator.js";
6import client from "../utils/client.js";
7import confirmationMessage from "../utils/confirmationMessage.js";
PineaFan0d06edc2023-01-17 22:10:31 +00008import { Embed } from "../utils/defaults.js";
pineafan4f164f32022-02-26 22:07:12 +00009
10const command = new SlashCommandBuilder()
11 .setName("privacy")
Skyler Grey11236ba2022-08-08 21:13:33 +010012 .setDescription("Information and options for you and your server's settings");
pineafan4f164f32022-02-26 22:07:12 +000013
pineafane23c4ec2022-07-27 21:56:27 +010014
pineafanbd02b4a2022-08-05 22:01:38 +010015const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan63fc5e22022-08-04 22:04:10 +010016 const pages = [
pineafane23c4ec2022-07-27 21:56:27 +010017 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +010018 .setEmbed(
19 new EmojiEmbed()
20 .setTitle("Nucleus Privacy")
21 .setDescription(
22 "Nucleus is a bot that naturally needs to store data about servers.\n" +
23 "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" +
PineaFand471ccd2023-01-26 20:48:40 +000024 "Any questions about Nucleus, how it works, and what data is stored can be asked in [our server](https://discord.gg/bPaNnxe)."
Skyler Grey75ea9172022-08-06 10:22:23 +010025 )
26 .setEmoji("NUCLEUS.LOGO")
27 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010028 )
Skyler Grey75ea9172022-08-06 10:22:23 +010029 .setTitle("Welcome")
30 .setDescription("General privacy information")
31 .setPageId(0),
32 new Embed()
33 .setEmbed(
34 new EmojiEmbed()
35 .setTitle("Scanners")
36 .setDescription(
pineafan3a02ea32022-08-11 21:35:04 +010037 "Nucleus uses [unscan](https://rapidapi.com/abcdan/api/unscan/) to scan links, images and files for malware and other threats.\n" +
Skyler Grey75ea9172022-08-06 10:22:23 +010038 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
39 )
40 .setEmoji("NUCLEUS.LOGO")
41 .setStatus("Danger")
42 )
43 .setTitle("Scanners")
44 .setDescription("About Unscan")
45 .setPageId(1),
46 new Embed()
47 .setEmbed(
48 new EmojiEmbed()
49 .setTitle("Link scanning and Transcripts")
50 .setDescription(
TheCodedProf94ff6de2023-02-22 17:47:26 -050051 "Transcripts allow you to store all messages sent in a channel. Transcripts are stored in our database along with the rest of the server's settings but is accessible by anyone with the link, so a leaked link could show all messages sent in the channel.\n"
Skyler Grey75ea9172022-08-06 10:22:23 +010052 )
53 .setEmoji("NUCLEUS.LOGO")
54 .setStatus("Danger")
55 )
56 .setTitle("Link scanning and Transcripts")
TheCodedProf94ff6de2023-02-22 17:47:26 -050057 .setDescription("Information about how links and images are scanned, and transcripts are stored")
Skyler Grey75ea9172022-08-06 10:22:23 +010058 .setPageId(2)
59 ].concat(
PineaFan0d06edc2023-01-17 22:10:31 +000060 (interaction.member as Discord.GuildMember).permissions.has("Administrator")
Skyler Grey75ea9172022-08-06 10:22:23 +010061 ? [
TheCodedProf1f675042023-02-16 17:01:29 -050062 new Embed()
63 .setEmbed(
64 new EmojiEmbed()
65 .setTitle("Options")
66 .setDescription("Below are buttons for controlling this servers privacy settings")
67 .setEmoji("NUCLEUS.LOGO")
68 .setStatus("Danger")
69 )
70 .setTitle("Options")
71 .setDescription("Options")
72 .setPageId(3)
73 .setComponents([
74 new ActionRowBuilder<ButtonBuilder>().addComponents([
75 new ButtonBuilder()
76 .setLabel("Clear all data")
77 .setCustomId("clear-all-data")
78 .setStyle(ButtonStyle.Danger)
79 ])
80 ])
81 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010082 : []
83 );
84 const m = await interaction.reply({
85 embeds: LoadingEmbed,
86 fetchReply: true,
87 ephemeral: true
88 });
PineaFan0d06edc2023-01-17 22:10:31 +000089 let page = parseInt(client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0");
pineafane23c4ec2022-07-27 21:56:27 +010090
91 let selectPaneOpen = false;
92 let nextFooter = null;
93
Skyler Greyad002172022-08-16 18:48:26 +010094 let timedOut = false;
95 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +000096 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +010097
98 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +000099 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 pages.forEach((embed) => {
101 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000102 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100103 label: embed.title,
104 value: embed.pageId.toString(),
105 description: embed.description || ""
106 })
107 );
pineafan63fc5e22022-08-04 22:04:10 +0100108 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000110 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
111 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100112 .addOptions(options)
113 .setCustomId("page")
114 .setMaxValues(1)
115 .setPlaceholder("Choose a page...")
116 ])
117 ];
pineafane23c4ec2022-07-27 21:56:27 +0100118 }
PineaFan0d06edc2023-01-17 22:10:31 +0000119 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
120 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400121 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100122 .setCustomId("left")
123 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400124 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100125 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400126 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 .setCustomId("select")
128 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400129 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400131 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100132 .setCustomId("right")
133 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400134 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000136 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000138 const em = new Discord.EmbedBuilder(pages[page]!.embed);
139 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
140 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100141 await interaction.editReply({
142 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000143 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100144 });
pineafan63fc5e22022-08-04 22:04:10 +0100145 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100146 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000147 i = await m.awaitMessageComponent({
148 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -0500149 filter: (i) => { return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id && i.message.id === m.id }
PineaFan0d06edc2023-01-17 22:10:31 +0000150 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100151 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100152 timedOut = true;
153 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100154 }
pineafan63fc5e22022-08-04 22:04:10 +0100155 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500156 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000157 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100158 if (page > 0) page--;
159 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000160 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100161 if (page < pages.length - 1) page++;
162 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000163 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100164 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000165 } else if (i.customId === "page" && i.isStringSelectMenu()) {
166 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100167 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000168 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100169 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100170 .setEmoji("CONTROL.BLOCKCROSS")
171 .setTitle("Clear All Data")
172 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100173 "Are you sure you want to delete all data on this server? This includes your settings and all punishment histories.\n\n" +
Skyler Grey75ea9172022-08-06 10:22:23 +0100174 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100175 )
176 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100177 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100178 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500179 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100180 }
pineafane23c4ec2022-07-27 21:56:27 +0100181 if (confirmation.success) {
PineaFan0d06edc2023-01-17 22:10:31 +0000182 client.database.guilds.delete(interaction.guild!.id);
183 client.database.history.delete(interaction.guild!.id);
TheCodedProf267563a2023-01-21 17:00:57 -0500184 client.database.notes.delete(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100185 nextFooter = "All data cleared";
186 continue;
187 } else {
188 nextFooter = "No changes were made";
189 continue;
190 }
191 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000192 const em = new Discord.EmbedBuilder(pages[page]!.embed);
193 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100194 em.setFooter({ text: "Message closed" });
195 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100196 return;
pineafane23c4ec2022-07-27 21:56:27 +0100197 }
pineafan73a7c4a2022-07-24 10:38:04 +0100198 }
PineaFan0d06edc2023-01-17 22:10:31 +0000199 const em = new Discord.EmbedBuilder(pages[page]!.embed);
200 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100201 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100202 await interaction.editReply({
203 embeds: [em],
204 components: []
205 });
pineafan63fc5e22022-08-04 22:04:10 +0100206};
pineafan4f164f32022-02-26 22:07:12 +0000207
pineafan4f164f32022-02-26 22:07:12 +0000208
209export { command };
210export { callback };