blob: 8803e2549ea3b9485b56cffc0fc075ec9f8a02ba [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(
51 "**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" +
52 "**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" +
TheCodedProf1f675042023-02-16 17:01:29 -050053 "Transcripts allow you to store all messages sent in a channel. This is stored in our database along with the rest of the servers 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 +010054 )
55 .setEmoji("NUCLEUS.LOGO")
56 .setStatus("Danger")
57 )
58 .setTitle("Link scanning and Transcripts")
Skyler Grey11236ba2022-08-08 21:13:33 +010059 .setDescription("Regarding Facebook and AMP filter types, and ticket transcripts")
Skyler Grey75ea9172022-08-06 10:22:23 +010060 .setPageId(2)
61 ].concat(
PineaFan0d06edc2023-01-17 22:10:31 +000062 (interaction.member as Discord.GuildMember).permissions.has("Administrator")
Skyler Grey75ea9172022-08-06 10:22:23 +010063 ? [
TheCodedProf1f675042023-02-16 17:01:29 -050064 new Embed()
65 .setEmbed(
66 new EmojiEmbed()
67 .setTitle("Options")
68 .setDescription("Below are buttons for controlling this servers privacy settings")
69 .setEmoji("NUCLEUS.LOGO")
70 .setStatus("Danger")
71 )
72 .setTitle("Options")
73 .setDescription("Options")
74 .setPageId(3)
75 .setComponents([
76 new ActionRowBuilder<ButtonBuilder>().addComponents([
77 new ButtonBuilder()
78 .setLabel("Clear all data")
79 .setCustomId("clear-all-data")
80 .setStyle(ButtonStyle.Danger)
81 ])
82 ])
83 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010084 : []
85 );
86 const m = await interaction.reply({
87 embeds: LoadingEmbed,
88 fetchReply: true,
89 ephemeral: true
90 });
PineaFan0d06edc2023-01-17 22:10:31 +000091 let page = parseInt(client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0");
pineafane23c4ec2022-07-27 21:56:27 +010092
93 let selectPaneOpen = false;
94 let nextFooter = null;
95
Skyler Greyad002172022-08-16 18:48:26 +010096 let timedOut = false;
97 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +000098 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +010099
100 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000101 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 pages.forEach((embed) => {
103 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000104 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 label: embed.title,
106 value: embed.pageId.toString(),
107 description: embed.description || ""
108 })
109 );
pineafan63fc5e22022-08-04 22:04:10 +0100110 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000112 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
113 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100114 .addOptions(options)
115 .setCustomId("page")
116 .setMaxValues(1)
117 .setPlaceholder("Choose a page...")
118 ])
119 ];
pineafane23c4ec2022-07-27 21:56:27 +0100120 }
PineaFan0d06edc2023-01-17 22:10:31 +0000121 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
122 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400123 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100124 .setCustomId("left")
125 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400126 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400128 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100129 .setCustomId("select")
130 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400131 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100132 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400133 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100134 .setCustomId("right")
135 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400136 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000138 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100139 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000140 const em = new Discord.EmbedBuilder(pages[page]!.embed);
141 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
142 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100143 await interaction.editReply({
144 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000145 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100146 });
pineafan63fc5e22022-08-04 22:04:10 +0100147 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100148 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000149 i = await m.awaitMessageComponent({
150 time: 300000,
TheCodedProf267563a2023-01-21 17:00:57 -0500151 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 +0000152 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100153 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100154 timedOut = true;
155 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100156 }
pineafan63fc5e22022-08-04 22:04:10 +0100157 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500158 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000159 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100160 if (page > 0) page--;
161 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000162 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100163 if (page < pages.length - 1) page++;
164 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000165 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100166 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000167 } else if (i.customId === "page" && i.isStringSelectMenu()) {
168 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100169 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000170 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100171 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100172 .setEmoji("CONTROL.BLOCKCROSS")
173 .setTitle("Clear All Data")
174 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100175 "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 +0100176 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100177 )
178 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100179 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100180 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500181 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100182 }
pineafane23c4ec2022-07-27 21:56:27 +0100183 if (confirmation.success) {
PineaFan0d06edc2023-01-17 22:10:31 +0000184 client.database.guilds.delete(interaction.guild!.id);
185 client.database.history.delete(interaction.guild!.id);
TheCodedProf267563a2023-01-21 17:00:57 -0500186 client.database.notes.delete(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100187 nextFooter = "All data cleared";
188 continue;
189 } else {
190 nextFooter = "No changes were made";
191 continue;
192 }
193 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000194 const em = new Discord.EmbedBuilder(pages[page]!.embed);
195 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100196 em.setFooter({ text: "Message closed" });
197 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100198 return;
pineafane23c4ec2022-07-27 21:56:27 +0100199 }
pineafan73a7c4a2022-07-24 10:38:04 +0100200 }
PineaFan0d06edc2023-01-17 22:10:31 +0000201 const em = new Discord.EmbedBuilder(pages[page]!.embed);
202 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100203 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100204 await interaction.editReply({
205 embeds: [em],
206 components: []
207 });
pineafan63fc5e22022-08-04 22:04:10 +0100208};
pineafan4f164f32022-02-26 22:07:12 +0000209
pineafan4f164f32022-02-26 22:07:12 +0000210
211export { command };
212export { callback };