blob: fecd0417560ed6b3a9d1e647da5247fba39f076b [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)
TheCodedProfe915a382023-03-05 16:44:29 -050087 .setDisabled(!(interaction.user.id === interaction.guild!.ownerId))
Skyler Greyda16adf2023-03-05 10:22:12 +000088 ])
89 ])
90 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010091 : []
92 );
93 const m = await interaction.reply({
94 embeds: LoadingEmbed,
95 fetchReply: true,
96 ephemeral: true
97 });
Skyler Greyda16adf2023-03-05 10:22:12 +000098 let page = parseInt(
99 client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0"
100 );
pineafane23c4ec2022-07-27 21:56:27 +0100101
102 let selectPaneOpen = false;
103 let nextFooter = null;
104
Skyler Greyad002172022-08-16 18:48:26 +0100105 let timedOut = false;
106 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +0000107 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +0100108
109 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000110 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 pages.forEach((embed) => {
112 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000113 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100114 label: embed.title,
115 value: embed.pageId.toString(),
116 description: embed.description || ""
117 })
118 );
pineafan63fc5e22022-08-04 22:04:10 +0100119 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100120 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000121 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
122 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 .addOptions(options)
124 .setCustomId("page")
125 .setMaxValues(1)
126 .setPlaceholder("Choose a page...")
127 ])
128 ];
pineafane23c4ec2022-07-27 21:56:27 +0100129 }
PineaFan0d06edc2023-01-17 22:10:31 +0000130 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
131 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400132 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100133 .setCustomId("left")
134 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400135 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100136 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400137 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100138 .setCustomId("select")
139 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400140 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100141 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400142 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100143 .setCustomId("right")
144 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400145 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100146 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000147 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100148 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000149 const em = new Discord.EmbedBuilder(pages[page]!.embed);
150 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
151 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100152 await interaction.editReply({
153 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000154 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100155 });
pineafan63fc5e22022-08-04 22:04:10 +0100156 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100157 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000158 i = await m.awaitMessageComponent({
159 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000160 filter: (i) => {
161 return (
162 i.user.id === interaction.user.id &&
163 i.channel!.id === interaction.channel!.id &&
164 i.message.id === m.id
165 );
166 }
PineaFan0d06edc2023-01-17 22:10:31 +0000167 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100168 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100169 timedOut = true;
170 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100171 }
pineafan63fc5e22022-08-04 22:04:10 +0100172 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500173 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000174 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100175 if (page > 0) page--;
176 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000177 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100178 if (page < pages.length - 1) page++;
179 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000180 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100181 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000182 } else if (i.customId === "page" && i.isStringSelectMenu()) {
183 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100184 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000185 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100186 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100187 .setEmoji("CONTROL.BLOCKCROSS")
188 .setTitle("Clear All Data")
189 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100190 "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 +0100191 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100192 )
193 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100194 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100195 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500196 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100197 }
pineafane23c4ec2022-07-27 21:56:27 +0100198 if (confirmation.success) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500199 await client.database.guilds.delete(interaction.guild!.id);
200 await client.database.history.delete(interaction.guild!.id);
201 await client.database.notes.delete(interaction.guild!.id);
202 await client.database.transcripts.deleteAll(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100203 nextFooter = "All data cleared";
204 continue;
205 } else {
206 nextFooter = "No changes were made";
207 continue;
208 }
209 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000210 const em = new Discord.EmbedBuilder(pages[page]!.embed);
211 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100212 em.setFooter({ text: "Message closed" });
213 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100214 return;
pineafane23c4ec2022-07-27 21:56:27 +0100215 }
pineafan73a7c4a2022-07-24 10:38:04 +0100216 }
PineaFan0d06edc2023-01-17 22:10:31 +0000217 const em = new Discord.EmbedBuilder(pages[page]!.embed);
218 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100219 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100220 await interaction.editReply({
221 embeds: [em],
222 components: []
223 });
pineafan63fc5e22022-08-04 22:04:10 +0100224};
pineafan4f164f32022-02-26 22:07:12 +0000225
pineafan4f164f32022-02-26 22:07:12 +0000226export { command };
227export { callback };