blob: 1b0c6bb3dca236b3dd3c36654718af2e27edfb0f [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed } from "../utils/defaults.js";
Skyler Greyda16adf2023-03-05 10:22:12 +00002import Discord, {
3 SlashCommandBuilder,
4 CommandInteraction,
5 ActionRowBuilder,
6 ButtonBuilder,
7 ButtonStyle,
8 StringSelectMenuOptionBuilder,
9 SelectMenuOptionBuilder,
10 StringSelectMenuBuilder
11} from "discord.js";
pineafan73a7c4a2022-07-24 10:38:04 +010012import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafane23c4ec2022-07-27 21:56:27 +010013import getEmojiByName from "../utils/getEmojiByName.js";
14import createPageIndicator from "../utils/createPageIndicator.js";
15import client from "../utils/client.js";
16import confirmationMessage from "../utils/confirmationMessage.js";
PineaFan0d06edc2023-01-17 22:10:31 +000017import { Embed } from "../utils/defaults.js";
pineafan4f164f32022-02-26 22:07:12 +000018
19const command = new SlashCommandBuilder()
20 .setName("privacy")
Skyler Grey11236ba2022-08-08 21:13:33 +010021 .setDescription("Information and options for you and your server's settings");
pineafan4f164f32022-02-26 22:07:12 +000022
pineafanbd02b4a2022-08-05 22:01:38 +010023const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan63fc5e22022-08-04 22:04:10 +010024 const pages = [
pineafane23c4ec2022-07-27 21:56:27 +010025 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +010026 .setEmbed(
27 new EmojiEmbed()
28 .setTitle("Nucleus Privacy")
29 .setDescription(
30 "Nucleus is a bot that naturally needs to store data about servers.\n" +
31 "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 +000032 "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 +010033 )
34 .setEmoji("NUCLEUS.LOGO")
35 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010036 )
Skyler Grey75ea9172022-08-06 10:22:23 +010037 .setTitle("Welcome")
38 .setDescription("General privacy information")
39 .setPageId(0),
40 new Embed()
41 .setEmbed(
42 new EmojiEmbed()
43 .setTitle("Scanners")
44 .setDescription(
pineafan3a02ea32022-08-11 21:35:04 +010045 "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 +010046 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
47 )
48 .setEmoji("NUCLEUS.LOGO")
49 .setStatus("Danger")
50 )
51 .setTitle("Scanners")
52 .setDescription("About Unscan")
53 .setPageId(1),
54 new Embed()
55 .setEmbed(
56 new EmojiEmbed()
57 .setTitle("Link scanning and Transcripts")
58 .setDescription(
Skyler Greyda16adf2023-03-05 10:22:12 +000059 "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 +010060 )
61 .setEmoji("NUCLEUS.LOGO")
62 .setStatus("Danger")
63 )
64 .setTitle("Link scanning and Transcripts")
TheCodedProf94ff6de2023-02-22 17:47:26 -050065 .setDescription("Information about how links and images are scanned, and transcripts are stored")
Skyler Grey75ea9172022-08-06 10:22:23 +010066 .setPageId(2)
67 ].concat(
PineaFan0d06edc2023-01-17 22:10:31 +000068 (interaction.member as Discord.GuildMember).permissions.has("Administrator")
Skyler Grey75ea9172022-08-06 10:22:23 +010069 ? [
Skyler Greyda16adf2023-03-05 10:22:12 +000070 new Embed()
71 .setEmbed(
72 new EmojiEmbed()
73 .setTitle("Options")
74 .setDescription("Below are buttons for controlling this servers privacy settings")
75 .setEmoji("NUCLEUS.LOGO")
76 .setStatus("Danger")
77 )
78 .setTitle("Options")
79 .setDescription("Options")
80 .setPageId(3)
81 .setComponents([
82 new ActionRowBuilder<ButtonBuilder>().addComponents([
83 new ButtonBuilder()
84 .setLabel("Clear all data")
85 .setCustomId("clear-all-data")
86 .setStyle(ButtonStyle.Danger)
87 ])
88 ])
89 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010090 : []
91 );
92 const m = await interaction.reply({
93 embeds: LoadingEmbed,
94 fetchReply: true,
95 ephemeral: true
96 });
Skyler Greyda16adf2023-03-05 10:22:12 +000097 let page = parseInt(
98 client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0"
99 );
pineafane23c4ec2022-07-27 21:56:27 +0100100
101 let selectPaneOpen = false;
102 let nextFooter = null;
103
Skyler Greyad002172022-08-16 18:48:26 +0100104 let timedOut = false;
105 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +0000106 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +0100107
108 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000109 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100110 pages.forEach((embed) => {
111 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000112 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100113 label: embed.title,
114 value: embed.pageId.toString(),
115 description: embed.description || ""
116 })
117 );
pineafan63fc5e22022-08-04 22:04:10 +0100118 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100119 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000120 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
121 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100122 .addOptions(options)
123 .setCustomId("page")
124 .setMaxValues(1)
125 .setPlaceholder("Choose a page...")
126 ])
127 ];
pineafane23c4ec2022-07-27 21:56:27 +0100128 }
PineaFan0d06edc2023-01-17 22:10:31 +0000129 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
130 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400131 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100132 .setCustomId("left")
133 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400134 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400136 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 .setCustomId("select")
138 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400139 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400141 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100142 .setCustomId("right")
143 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400144 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000146 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100147 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000148 const em = new Discord.EmbedBuilder(pages[page]!.embed);
149 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
150 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100151 await interaction.editReply({
152 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000153 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100154 });
pineafan63fc5e22022-08-04 22:04:10 +0100155 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100156 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000157 i = await m.awaitMessageComponent({
158 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000159 filter: (i) => {
160 return (
161 i.user.id === interaction.user.id &&
162 i.channel!.id === interaction.channel!.id &&
163 i.message.id === m.id
164 );
165 }
PineaFan0d06edc2023-01-17 22:10:31 +0000166 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100167 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100168 timedOut = true;
169 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100170 }
pineafan63fc5e22022-08-04 22:04:10 +0100171 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500172 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000173 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100174 if (page > 0) page--;
175 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000176 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100177 if (page < pages.length - 1) page++;
178 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000179 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100180 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000181 } else if (i.customId === "page" && i.isStringSelectMenu()) {
182 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100183 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000184 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100185 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100186 .setEmoji("CONTROL.BLOCKCROSS")
187 .setTitle("Clear All Data")
188 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100189 "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 +0100190 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100191 )
192 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100193 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100194 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500195 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100196 }
pineafane23c4ec2022-07-27 21:56:27 +0100197 if (confirmation.success) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500198 await client.database.guilds.delete(interaction.guild!.id);
199 await client.database.history.delete(interaction.guild!.id);
200 await client.database.notes.delete(interaction.guild!.id);
201 await client.database.transcripts.deleteAll(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100202 nextFooter = "All data cleared";
203 continue;
204 } else {
205 nextFooter = "No changes were made";
206 continue;
207 }
208 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000209 const em = new Discord.EmbedBuilder(pages[page]!.embed);
210 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100211 em.setFooter({ text: "Message closed" });
212 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100213 return;
pineafane23c4ec2022-07-27 21:56:27 +0100214 }
pineafan73a7c4a2022-07-24 10:38:04 +0100215 }
PineaFan0d06edc2023-01-17 22:10:31 +0000216 const em = new Discord.EmbedBuilder(pages[page]!.embed);
217 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100219 await interaction.editReply({
220 embeds: [em],
221 components: []
222 });
pineafan63fc5e22022-08-04 22:04:10 +0100223};
pineafan4f164f32022-02-26 22:07:12 +0000224
pineafan4f164f32022-02-26 22:07:12 +0000225export { command };
226export { callback };