blob: cb6054df6f233c21816b086015bc9fd1ef201712 [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 "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" + // TODO
25 "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 +010026 )
27 .setEmoji("NUCLEUS.LOGO")
28 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010029 )
Skyler Grey75ea9172022-08-06 10:22:23 +010030 .setTitle("Welcome")
31 .setDescription("General privacy information")
32 .setPageId(0),
33 new Embed()
34 .setEmbed(
35 new EmojiEmbed()
36 .setTitle("Scanners")
37 .setDescription(
pineafan3a02ea32022-08-11 21:35:04 +010038 "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 +010039 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
40 )
41 .setEmoji("NUCLEUS.LOGO")
42 .setStatus("Danger")
43 )
44 .setTitle("Scanners")
45 .setDescription("About Unscan")
46 .setPageId(1),
47 new Embed()
48 .setEmbed(
49 new EmojiEmbed()
50 .setTitle("Link scanning and Transcripts")
51 .setDescription(
52 "**Facebook** - Facebook trackers include data such as your date of birth, and guess your age if not entered, your preferences, who you interact with and more.\n" +
53 "**AMP** - AMP is a technology that allows websites to be served by Google. This means Google can store and track data, and are pushing this to as many pages as possible.\n\n" +
PineaFan0d06edc2023-01-17 22:10:31 +000054 "Transcripts allow you to store all messages sent in a channel. This could be an issue in some cases, as they are hosted on [Pastebin](https://pastebin.com), so a leaked link could show all messages sent in the channel.\n" // TODO: Not on pastebin
Skyler Grey75ea9172022-08-06 10:22:23 +010055 )
56 .setEmoji("NUCLEUS.LOGO")
57 .setStatus("Danger")
58 )
59 .setTitle("Link scanning and Transcripts")
Skyler Grey11236ba2022-08-08 21:13:33 +010060 .setDescription("Regarding Facebook and AMP filter types, and ticket transcripts")
Skyler Grey75ea9172022-08-06 10:22:23 +010061 .setPageId(2)
62 ].concat(
PineaFan0d06edc2023-01-17 22:10:31 +000063 (interaction.member as Discord.GuildMember).permissions.has("Administrator")
Skyler Grey75ea9172022-08-06 10:22:23 +010064 ? [
65 new Embed()
66 .setEmbed(
67 new EmojiEmbed()
68 .setTitle("Options")
Skyler Grey11236ba2022-08-08 21:13:33 +010069 .setDescription("Below are buttons for controlling this servers privacy settings")
Skyler Grey75ea9172022-08-06 10:22:23 +010070 .setEmoji("NUCLEUS.LOGO")
71 .setStatus("Danger")
72 )
73 .setTitle("Options")
74 .setDescription("Options")
75 .setPageId(3)
76 .setComponents([
PineaFan0d06edc2023-01-17 22:10:31 +000077 new ActionRowBuilder<ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040078 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010079 .setLabel("Clear all data")
80 .setCustomId("clear-all-data")
TheCodedProf21c08592022-09-13 14:14:43 -040081 .setStyle(ButtonStyle.Danger)
Skyler Grey75ea9172022-08-06 10:22:23 +010082 ])
83 ])
84 ]
85 : []
86 );
87 const m = await interaction.reply({
88 embeds: LoadingEmbed,
89 fetchReply: true,
90 ephemeral: true
91 });
PineaFan0d06edc2023-01-17 22:10:31 +000092 let page = parseInt(client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0");
pineafane23c4ec2022-07-27 21:56:27 +010093
94 let selectPaneOpen = false;
95 let nextFooter = null;
96
Skyler Greyad002172022-08-16 18:48:26 +010097 let timedOut = false;
98 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +000099 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +0100100
101 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000102 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100103 pages.forEach((embed) => {
104 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000105 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 label: embed.title,
107 value: embed.pageId.toString(),
108 description: embed.description || ""
109 })
110 );
pineafan63fc5e22022-08-04 22:04:10 +0100111 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100112 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000113 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
114 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100115 .addOptions(options)
116 .setCustomId("page")
117 .setMaxValues(1)
118 .setPlaceholder("Choose a page...")
119 ])
120 ];
pineafane23c4ec2022-07-27 21:56:27 +0100121 }
PineaFan0d06edc2023-01-17 22:10:31 +0000122 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
123 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400124 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100125 .setCustomId("left")
126 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400127 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100128 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400129 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 .setCustomId("select")
131 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400132 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100133 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400134 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 .setCustomId("right")
136 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400137 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100138 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000139 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000141 const em = new Discord.EmbedBuilder(pages[page]!.embed);
142 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
143 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100144 await interaction.editReply({
145 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000146 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100147 });
pineafan63fc5e22022-08-04 22:04:10 +0100148 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100149 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000150 i = await m.awaitMessageComponent({
151 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -0500152 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 +0000153 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100154 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100155 timedOut = true;
156 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100157 }
pineafan63fc5e22022-08-04 22:04:10 +0100158 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500159 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000160 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100161 if (page > 0) page--;
162 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000163 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100164 if (page < pages.length - 1) page++;
165 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000166 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100167 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000168 } else if (i.customId === "page" && i.isStringSelectMenu()) {
169 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100170 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000171 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100172 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100173 .setEmoji("CONTROL.BLOCKCROSS")
174 .setTitle("Clear All Data")
175 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100176 "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 +0100177 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100178 )
179 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100180 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100181 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500182 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100183 }
pineafane23c4ec2022-07-27 21:56:27 +0100184 if (confirmation.success) {
PineaFan0d06edc2023-01-17 22:10:31 +0000185 client.database.guilds.delete(interaction.guild!.id);
186 client.database.history.delete(interaction.guild!.id);
TheCodedProf267563a2023-01-21 17:00:57 -0500187 client.database.notes.delete(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100188 nextFooter = "All data cleared";
189 continue;
190 } else {
191 nextFooter = "No changes were made";
192 continue;
193 }
194 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000195 const em = new Discord.EmbedBuilder(pages[page]!.embed);
196 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100197 em.setFooter({ text: "Message closed" });
198 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100199 return;
pineafane23c4ec2022-07-27 21:56:27 +0100200 }
pineafan73a7c4a2022-07-24 10:38:04 +0100201 }
PineaFan0d06edc2023-01-17 22:10:31 +0000202 const em = new Discord.EmbedBuilder(pages[page]!.embed);
203 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100204 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100205 await interaction.editReply({
206 embeds: [em],
207 components: []
208 });
pineafan63fc5e22022-08-04 22:04:10 +0100209};
pineafan4f164f32022-02-26 22:07:12 +0000210
pineafan4f164f32022-02-26 22:07:12 +0000211
212export { command };
213export { callback };