blob: 4de0c6306c2470bf5831403a7486fc82de67e26d [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
Skyler Grey11236ba2022-08-08 21:13:33 +01002import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js";
pineafane23c4ec2022-07-27 21:56:27 +01003import { SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders";
pineafan4f164f32022-02-26 22:07:12 +00004import { WrappedCheck } from "jshaiku";
pineafan73a7c4a2022-07-24 10:38:04 +01005import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafane23c4ec2022-07-27 21:56:27 +01006import getEmojiByName from "../utils/getEmojiByName.js";
7import createPageIndicator from "../utils/createPageIndicator.js";
8import client from "../utils/client.js";
9import confirmationMessage from "../utils/confirmationMessage.js";
pineafan4f164f32022-02-26 22:07:12 +000010
11const command = new SlashCommandBuilder()
12 .setName("privacy")
Skyler Grey11236ba2022-08-08 21:13:33 +010013 .setDescription("Information and options for you and your server's settings");
pineafan4f164f32022-02-26 22:07:12 +000014
pineafane23c4ec2022-07-27 21:56:27 +010015class Embed {
16 embed: Discord.MessageEmbed;
17 title: string;
pineafan63fc5e22022-08-04 22:04:10 +010018 description = "";
19 pageId = 0;
pineafane23c4ec2022-07-27 21:56:27 +010020 components?: MessageActionRow[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010021 setEmbed(embed: Discord.MessageEmbed) {
22 this.embed = embed;
23 return this;
24 }
25 setTitle(title: string) {
26 this.title = title;
27 return this;
28 }
29 setDescription(description: string) {
30 this.description = description;
31 return this;
32 }
33 setPageId(pageId: number) {
34 this.pageId = pageId;
35 return this;
36 }
37 setComponents(components: MessageActionRow[]) {
38 this.components = components;
39 return this;
40 }
pineafane23c4ec2022-07-27 21:56:27 +010041}
42
pineafanbd02b4a2022-08-05 22:01:38 +010043const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan63fc5e22022-08-04 22:04:10 +010044 const pages = [
pineafane23c4ec2022-07-27 21:56:27 +010045 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +010046 .setEmbed(
47 new EmojiEmbed()
48 .setTitle("Nucleus Privacy")
49 .setDescription(
50 "Nucleus is a bot that naturally needs to store data about servers.\n" +
51 "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" +
52 "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" +
53 "Any questions about Nucleus, how it works and data stored can be asked in [our server](https://discord.gg/bPaNnxe)."
54 )
55 .setEmoji("NUCLEUS.LOGO")
56 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010057 )
Skyler Grey75ea9172022-08-06 10:22:23 +010058 .setTitle("Welcome")
59 .setDescription("General privacy information")
60 .setPageId(0),
61 new Embed()
62 .setEmbed(
63 new EmojiEmbed()
64 .setTitle("Scanners")
65 .setDescription(
pineafan3a02ea32022-08-11 21:35:04 +010066 "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 +010067 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
68 )
69 .setEmoji("NUCLEUS.LOGO")
70 .setStatus("Danger")
71 )
72 .setTitle("Scanners")
73 .setDescription("About Unscan")
74 .setPageId(1),
75 new Embed()
76 .setEmbed(
77 new EmojiEmbed()
78 .setTitle("Link scanning and Transcripts")
79 .setDescription(
80 "**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" +
81 "**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" +
82 "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"
83 )
84 .setEmoji("NUCLEUS.LOGO")
85 .setStatus("Danger")
86 )
87 .setTitle("Link scanning and Transcripts")
Skyler Grey11236ba2022-08-08 21:13:33 +010088 .setDescription("Regarding Facebook and AMP filter types, and ticket transcripts")
Skyler Grey75ea9172022-08-06 10:22:23 +010089 .setPageId(2)
90 ].concat(
Skyler Grey11236ba2022-08-08 21:13:33 +010091 (interaction.member as Discord.GuildMember).permissions.has("ADMINISTRATOR")
Skyler Grey75ea9172022-08-06 10:22:23 +010092 ? [
93 new Embed()
94 .setEmbed(
95 new EmojiEmbed()
96 .setTitle("Options")
Skyler Grey11236ba2022-08-08 21:13:33 +010097 .setDescription("Below are buttons for controlling this servers privacy settings")
Skyler Grey75ea9172022-08-06 10:22:23 +010098 .setEmoji("NUCLEUS.LOGO")
99 .setStatus("Danger")
100 )
101 .setTitle("Options")
102 .setDescription("Options")
103 .setPageId(3)
104 .setComponents([
105 new MessageActionRow().addComponents([
106 new MessageButton()
107 .setLabel("Clear all data")
108 .setCustomId("clear-all-data")
109 .setStyle("DANGER")
110 ])
111 ])
112 ]
113 : []
114 );
115 const m = await interaction.reply({
116 embeds: LoadingEmbed,
117 fetchReply: true,
118 ephemeral: true
119 });
pineafane23c4ec2022-07-27 21:56:27 +0100120 let page = 0;
121
122 let selectPaneOpen = false;
123 let nextFooter = null;
124
125 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100126 let selectPane = [];
pineafane23c4ec2022-07-27 21:56:27 +0100127
128 if (selectPaneOpen) {
pineafan63fc5e22022-08-04 22:04:10 +0100129 const options = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100130 pages.forEach((embed) => {
131 options.push(
132 new SelectMenuOption({
133 label: embed.title,
134 value: embed.pageId.toString(),
135 description: embed.description || ""
136 })
137 );
pineafan63fc5e22022-08-04 22:04:10 +0100138 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100139 selectPane = [
140 new MessageActionRow().addComponents([
141 new Discord.MessageSelectMenu()
142 .addOptions(options)
143 .setCustomId("page")
144 .setMaxValues(1)
145 .setPlaceholder("Choose a page...")
146 ])
147 ];
pineafane23c4ec2022-07-27 21:56:27 +0100148 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100149 const components = selectPane.concat([
150 new MessageActionRow().addComponents([
151 new MessageButton()
152 .setCustomId("left")
153 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
154 .setStyle("SECONDARY")
155 .setDisabled(page === 0),
156 new MessageButton()
157 .setCustomId("select")
158 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
159 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
160 .setDisabled(false),
161 new MessageButton()
162 .setCustomId("right")
163 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
164 .setStyle("SECONDARY")
165 .setDisabled(page === pages.length - 1)
166 ])
167 ]);
pineafan63fc5e22022-08-04 22:04:10 +0100168 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100169 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100170 em.setFooter({ text: nextFooter ?? "" });
pineafane23c4ec2022-07-27 21:56:27 +0100171 await interaction.editReply({
172 embeds: [em],
173 components: components.concat(pages[page].components)
174 });
pineafan63fc5e22022-08-04 22:04:10 +0100175 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100176 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100177 i = await m.awaitMessageComponent({ time: 300000 });
178 } catch (e) {
179 break;
180 }
pineafan63fc5e22022-08-04 22:04:10 +0100181 nextFooter = null;
182 i.deferUpdate();
pineafane23c4ec2022-07-27 21:56:27 +0100183 if (i.component.customId === "left") {
184 if (page > 0) page--;
185 selectPaneOpen = false;
186 } else if (i.component.customId === "right") {
187 if (page < pages.length - 1) page++;
188 selectPaneOpen = false;
189 } else if (i.component.customId === "select") {
190 selectPaneOpen = !selectPaneOpen;
191 } else if (i.component.customId === "page") {
192 page = parseInt(i.values[0]);
193 selectPaneOpen = false;
194 } else if (i.component.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100195 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100196 .setEmoji("CONTROL.BLOCKCROSS")
197 .setTitle("Clear All Data")
198 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100199 "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 +0100200 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100201 )
202 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100203 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100204 if (confirmation.cancelled) {
205 break;
206 }
pineafane23c4ec2022-07-27 21:56:27 +0100207 if (confirmation.success) {
208 client.database.guilds.delete(interaction.guild.id);
209 client.database.history.delete(interaction.guild.id);
210 nextFooter = "All data cleared";
211 continue;
212 } else {
213 nextFooter = "No changes were made";
214 continue;
215 }
216 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100217 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100218 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100219 em.setFooter({ text: "Message closed" });
220 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100221 return;
pineafane23c4ec2022-07-27 21:56:27 +0100222 }
pineafan73a7c4a2022-07-24 10:38:04 +0100223 }
pineafan63fc5e22022-08-04 22:04:10 +0100224 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100225 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100226 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100227 await interaction.editReply({
228 embeds: [em],
229 components: []
230 });
pineafan63fc5e22022-08-04 22:04:10 +0100231};
pineafan4f164f32022-02-26 22:07:12 +0000232
Skyler Grey11236ba2022-08-08 21:13:33 +0100233const check = (_interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
pineafan4f164f32022-02-26 22:07:12 +0000234 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100235};
pineafan4f164f32022-02-26 22:07:12 +0000236
237export { command };
238export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100239export { check };