blob: 0be488066cd3d1f6c2d2a640d55c8138421e0e3e [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")
TheCodedProf90d75022023-03-05 19:33:00 -050036 .setFooter({text: "https://clicksminuteper.github.io/policies/nucleus"})
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(
pineafan3a02ea32022-08-11 21:35:04 +010046 "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 +010047 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
48 )
49 .setEmoji("NUCLEUS.LOGO")
50 .setStatus("Danger")
TheCodedProf90d75022023-03-05 19:33:00 -050051 .setFooter({text: "https://clicksminuteper.github.io/policies/nucleus"})
Skyler Grey75ea9172022-08-06 10:22:23 +010052 )
53 .setTitle("Scanners")
54 .setDescription("About Unscan")
55 .setPageId(1),
56 new Embed()
57 .setEmbed(
58 new EmojiEmbed()
59 .setTitle("Link scanning and Transcripts")
60 .setDescription(
Skyler Greyda16adf2023-03-05 10:22:12 +000061 "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 +010062 )
63 .setEmoji("NUCLEUS.LOGO")
64 .setStatus("Danger")
TheCodedProf90d75022023-03-05 19:33:00 -050065 .setFooter({text: "https://clicksminuteper.github.io/policies/nucleus"})
Skyler Grey75ea9172022-08-06 10:22:23 +010066 )
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(
PineaFan0d06edc2023-01-17 22:10:31 +000071 (interaction.member as Discord.GuildMember).permissions.has("Administrator")
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")
TheCodedProf90d75022023-03-05 19:33:00 -050080 .setFooter({text: "https://clicksminuteper.github.io/policies/nucleus"})
Skyler Greyda16adf2023-03-05 10:22:12 +000081 )
82 .setTitle("Options")
83 .setDescription("Options")
84 .setPageId(3)
85 .setComponents([
86 new ActionRowBuilder<ButtonBuilder>().addComponents([
87 new ButtonBuilder()
88 .setLabel("Clear all data")
89 .setCustomId("clear-all-data")
90 .setStyle(ButtonStyle.Danger)
TheCodedProfe915a382023-03-05 16:44:29 -050091 .setDisabled(!(interaction.user.id === interaction.guild!.ownerId))
Skyler Greyda16adf2023-03-05 10:22:12 +000092 ])
93 ])
94 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010095 : []
96 );
97 const m = await interaction.reply({
98 embeds: LoadingEmbed,
99 fetchReply: true,
100 ephemeral: true
101 });
Skyler Greyda16adf2023-03-05 10:22:12 +0000102 let page = parseInt(
103 client.preloadPage[interaction.channel!.id] ? client.preloadPage[interaction.channel!.id]?.argument! : "0"
104 );
pineafane23c4ec2022-07-27 21:56:27 +0100105
106 let selectPaneOpen = false;
107 let nextFooter = null;
108
Skyler Greyad002172022-08-16 18:48:26 +0100109 let timedOut = false;
110 while (!timedOut) {
PineaFan0d06edc2023-01-17 22:10:31 +0000111 let selectPane: Discord.ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = [];
pineafane23c4ec2022-07-27 21:56:27 +0100112
113 if (selectPaneOpen) {
PineaFan0d06edc2023-01-17 22:10:31 +0000114 const options: SelectMenuOptionBuilder[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100115 pages.forEach((embed) => {
116 options.push(
PineaFan0d06edc2023-01-17 22:10:31 +0000117 new StringSelectMenuOptionBuilder({
Skyler Grey75ea9172022-08-06 10:22:23 +0100118 label: embed.title,
119 value: embed.pageId.toString(),
120 description: embed.description || ""
121 })
122 );
pineafan63fc5e22022-08-04 22:04:10 +0100123 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100124 selectPane = [
PineaFan0d06edc2023-01-17 22:10:31 +0000125 new ActionRowBuilder<StringSelectMenuBuilder>().addComponents([
126 new Discord.StringSelectMenuBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100127 .addOptions(options)
128 .setCustomId("page")
129 .setMaxValues(1)
130 .setPlaceholder("Choose a page...")
131 ])
132 ];
pineafane23c4ec2022-07-27 21:56:27 +0100133 }
PineaFan0d06edc2023-01-17 22:10:31 +0000134 const components: ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder>[] = selectPane.concat([
135 new ActionRowBuilder<ButtonBuilder>().addComponents(
TheCodedProf21c08592022-09-13 14:14:43 -0400136 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 .setCustomId("left")
138 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400139 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 .setDisabled(page === 0),
TheCodedProf21c08592022-09-13 14:14:43 -0400141 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100142 .setCustomId("select")
143 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400144 .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 .setDisabled(false),
TheCodedProf21c08592022-09-13 14:14:43 -0400146 new ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100147 .setCustomId("right")
148 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
TheCodedProf21c08592022-09-13 14:14:43 -0400149 .setStyle(ButtonStyle.Secondary)
Skyler Grey75ea9172022-08-06 10:22:23 +0100150 .setDisabled(page === pages.length - 1)
PineaFan0d06edc2023-01-17 22:10:31 +0000151 )
Skyler Grey75ea9172022-08-06 10:22:23 +0100152 ]);
PineaFan0d06edc2023-01-17 22:10:31 +0000153 const em = new Discord.EmbedBuilder(pages[page]!.embed);
154 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
155 if (nextFooter) em.setFooter({ text: nextFooter });
pineafane23c4ec2022-07-27 21:56:27 +0100156 await interaction.editReply({
157 embeds: [em],
PineaFan0d06edc2023-01-17 22:10:31 +0000158 components: components.concat(pages[page]?.componentsToSet ?? [])
pineafane23c4ec2022-07-27 21:56:27 +0100159 });
pineafan63fc5e22022-08-04 22:04:10 +0100160 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100161 try {
PineaFan0d06edc2023-01-17 22:10:31 +0000162 i = await m.awaitMessageComponent({
163 time: 300000,
Skyler Greyda16adf2023-03-05 10:22:12 +0000164 filter: (i) => {
165 return (
166 i.user.id === interaction.user.id &&
167 i.channel!.id === interaction.channel!.id &&
168 i.message.id === m.id
169 );
170 }
PineaFan0d06edc2023-01-17 22:10:31 +0000171 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100172 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100173 timedOut = true;
174 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100175 }
pineafan63fc5e22022-08-04 22:04:10 +0100176 nextFooter = null;
TheCodedProf267563a2023-01-21 17:00:57 -0500177 await i.deferUpdate();
PineaFan0d06edc2023-01-17 22:10:31 +0000178 if (i.customId === "left") {
pineafane23c4ec2022-07-27 21:56:27 +0100179 if (page > 0) page--;
180 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000181 } else if (i.customId === "right") {
pineafane23c4ec2022-07-27 21:56:27 +0100182 if (page < pages.length - 1) page++;
183 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000184 } else if (i.customId === "select") {
pineafane23c4ec2022-07-27 21:56:27 +0100185 selectPaneOpen = !selectPaneOpen;
PineaFan0d06edc2023-01-17 22:10:31 +0000186 } else if (i.customId === "page" && i.isStringSelectMenu()) {
187 page = parseInt(i.values[0]!);
pineafane23c4ec2022-07-27 21:56:27 +0100188 selectPaneOpen = false;
PineaFan0d06edc2023-01-17 22:10:31 +0000189 } else if (i.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100190 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100191 .setEmoji("CONTROL.BLOCKCROSS")
192 .setTitle("Clear All Data")
193 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100194 "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 +0100195 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100196 )
197 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100198 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100199 if (confirmation.cancelled) {
TheCodedProf267563a2023-01-21 17:00:57 -0500200 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100201 }
pineafane23c4ec2022-07-27 21:56:27 +0100202 if (confirmation.success) {
TheCodedProf75c51be2023-03-03 17:18:18 -0500203 await client.database.guilds.delete(interaction.guild!.id);
204 await client.database.history.delete(interaction.guild!.id);
205 await client.database.notes.delete(interaction.guild!.id);
206 await client.database.transcripts.deleteAll(interaction.guild!.id);
pineafane23c4ec2022-07-27 21:56:27 +0100207 nextFooter = "All data cleared";
208 continue;
209 } else {
210 nextFooter = "No changes were made";
211 continue;
212 }
213 } else {
PineaFan0d06edc2023-01-17 22:10:31 +0000214 const em = new Discord.EmbedBuilder(pages[page]!.embed);
215 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100216 em.setFooter({ text: "Message closed" });
217 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100218 return;
pineafane23c4ec2022-07-27 21:56:27 +0100219 }
pineafan73a7c4a2022-07-24 10:38:04 +0100220 }
PineaFan0d06edc2023-01-17 22:10:31 +0000221 const em = new Discord.EmbedBuilder(pages[page]!.embed);
222 em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100223 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100224 await interaction.editReply({
225 embeds: [em],
226 components: []
227 });
pineafan63fc5e22022-08-04 22:04:10 +0100228};
pineafan4f164f32022-02-26 22:07:12 +0000229
pineafan4f164f32022-02-26 22:07:12 +0000230export { command };
231export { callback };