blob: aa17e7b11afd7f67ea80be50a88a69147ca1820d [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" +
TheCodedProf35e73712023-03-10 17:35:35 -050032 "Any questions about Nucleus, how it works, and what data is stored can be asked in [our server](https://discord.gg/bPaNnxe)." +
33 "\n\n[[Privacy Policy]](https://clicksminuteper.github.io/policies/nucleus) | [[Terms of Service]](https://clicksminuteper.github.io/policies/nucleustos)"
Skyler Grey75ea9172022-08-06 10:22:23 +010034 )
35 .setEmoji("NUCLEUS.LOGO")
36 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010037 )
Skyler Grey75ea9172022-08-06 10:22:23 +010038 .setTitle("Welcome")
39 .setDescription("General privacy information")
40 .setPageId(0),
41 new Embed()
42 .setEmbed(
43 new EmojiEmbed()
44 .setTitle("Scanners")
45 .setDescription(
TheCodedProf35e73712023-03-10 17:35:35 -050046 "Nucleus scans content sent by users for malware and NSFW content\n" +
PineappleFan9fa59a72023-03-12 15:34:37 +000047 "Malware is detected using [ClamAV](https://clamav.net/), and the standard ClamAV database.\n" +
TheCodedProfca29ebb2023-03-10 17:40:09 -050048 "NSFW detection is provided by [NsfwJS](https://nsfwjs.com/), with a model provided by [GantMan](https://github.com/GantMan/nsfw_model/releases/tag/1.1.0)\n\n" +
49 "All data is processed on our servers and is not processed by a 3rd party."
Skyler Grey75ea9172022-08-06 10:22:23 +010050 )
51 .setEmoji("NUCLEUS.LOGO")
52 .setStatus("Danger")
53 )
54 .setTitle("Scanners")
TheCodedProf35e73712023-03-10 17:35:35 -050055 .setDescription("About Scanners")
Skyler Grey75ea9172022-08-06 10:22:23 +010056 .setPageId(1),
57 new Embed()
58 .setEmbed(
59 new EmojiEmbed()
60 .setTitle("Link scanning and Transcripts")
61 .setDescription(
Skyler Greyda16adf2023-03-05 10:22:12 +000062 "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 +010063 )
64 .setEmoji("NUCLEUS.LOGO")
65 .setStatus("Danger")
66 )
67 .setTitle("Link scanning and Transcripts")
TheCodedProf94ff6de2023-02-22 17:47:26 -050068 .setDescription("Information about how links and images are scanned, and transcripts are stored")
Skyler Grey75ea9172022-08-06 10:22:23 +010069 .setPageId(2)
70 ].concat(
TheCodedProf35e73712023-03-10 17:35:35 -050071 (interaction.member as Discord.GuildMember).id === interaction.guild!.ownerId
Skyler Grey75ea9172022-08-06 10:22:23 +010072 ? [
Skyler Greyda16adf2023-03-05 10:22:12 +000073 new Embed()
74 .setEmbed(
75 new EmojiEmbed()
76 .setTitle("Options")
77 .setDescription("Below are buttons for controlling this servers privacy settings")
78 .setEmoji("NUCLEUS.LOGO")
79 .setStatus("Danger")
80 )
81 .setTitle("Options")
82 .setDescription("Options")
83 .setPageId(3)
84 .setComponents([
85 new ActionRowBuilder<ButtonBuilder>().addComponents([
86 new ButtonBuilder()
87 .setLabel("Clear all data")
88 .setCustomId("clear-all-data")
89 .setStyle(ButtonStyle.Danger)
90 ])
91 ])
92 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010093 : []
94 );
95 const m = await interaction.reply({
96 embeds: LoadingEmbed,
97 fetchReply: true,
98 ephemeral: true
99 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000100 let page = parseInt(
101 client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0"
102 );
pineafane23c4ec2022-07-27 21:56:27 +0100103
104 let selectPaneOpen = false;
105 let nextFooter = null;
106
Skyler Greyad002172022-08-16 18:48:26 +0100107 let timedOut = false;
108 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +0000109 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +0100110
111 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000112 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100113 pages.forEach((embed) => {
114 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000115 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 label: embed.title,
117 value: embed.pageId.toString(),
118 description: embed.description || ""
119 })
120 );
pineafan63fc5e22022-08-04 22:04:10 +0100121 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100122 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000123 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
124 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100125 .addOptions(options)
126 .setCustomId("page")
127 .setMaxValues(1)
128 .setPlaceholder("Choose a page...")
129 ])
130 ];
pineafane23c4ec2022-07-27 21:56:27 +0100131 }
PineaFan0d06edc2023-01-17 22:10:31 +0000132 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
133 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400134 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 .setCustomId("left")
136 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400137 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100138 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400139 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 .setCustomId("select")
141 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400142 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100143 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400144 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 .setCustomId("right")
146 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400147 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100148 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000149 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100150 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000151 const em = new Discord.EmbedBuilder(pages[page]!.embed);
152 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
153 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100154 await interaction.editReply({
155 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000156 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100157 });
pineafan63fc5e22022-08-04 22:04:10 +0100158 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100159 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000160 i = await m.awaitMessageComponent({
161 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000162 filter: (i) => {
163 return (
164 i.user.id === interaction.user.id &&
165 i.channel!.id === interaction.channel!.id &&
166 i.message.id === m.id
167 );
168 }
PineaFan0d06edc2023-01-17 22:10:31 +0000169 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100170 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100171 timedOut = true;
172 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100173 }
pineafan63fc5e22022-08-04 22:04:10 +0100174 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500175 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000176 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100177 if (page > 0) page--;
178 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000179 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100180 if (page < pages.length - 1) page++;
181 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000182 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100183 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000184 } else if (i.customId === "page" && i.isStringSelectMenu()) {
185 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100186 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000187 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100188 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100189 .setEmoji("CONTROL.BLOCKCROSS")
190 .setTitle("Clear All Data")
191 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100192 "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 +0100193 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100194 )
195 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100196 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100197 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500198 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100199 }
pineafane23c4ec2022-07-27 21:56:27 +0100200 if (confirmation.success) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500201 await client.database.guilds.delete(interaction.guild!.id);
202 await client.database.history.delete(interaction.guild!.id);
203 await client.database.notes.delete(interaction.guild!.id);
204 await client.database.transcripts.deleteAll(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100205 nextFooter = "All data cleared";
206 continue;
207 } else {
208 nextFooter = "No changes were made";
209 continue;
210 }
211 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000212 const em = new Discord.EmbedBuilder(pages[page]!.embed);
213 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100214 em.setFooter({ text: "Message closed" });
Skyler Greyf4f21c42023-03-08 14:36:29 +0000215 await interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100216 return;
pineafane23c4ec2022-07-27 21:56:27 +0100217 }
pineafan73a7c4a2022-07-24 10:38:04 +0100218 }
PineaFan0d06edc2023-01-17 22:10:31 +0000219 const em = new Discord.EmbedBuilder(pages[page]!.embed);
220 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100221 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100222 await interaction.editReply({
223 embeds: [em],
224 components: []
225 });
pineafan63fc5e22022-08-04 22:04:10 +0100226};
pineafan4f164f32022-02-26 22:07:12 +0000227
pineafan4f164f32022-02-26 22:07:12 +0000228export { command };
229export { callback };