blob: 9f63602f3b1ce3d0722e8f963dcc8c760438db2f [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
Skyler Greyad002172022-08-16 18:48:26 +0100125 let timedOut = false;
126 while (!timedOut) {
pineafan63fc5e22022-08-04 22:04:10 +0100127 let selectPane = [];
pineafane23c4ec2022-07-27 21:56:27 +0100128
129 if (selectPaneOpen) {
pineafan63fc5e22022-08-04 22:04:10 +0100130 const options = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100131 pages.forEach((embed) => {
132 options.push(
133 new SelectMenuOption({
134 label: embed.title,
135 value: embed.pageId.toString(),
136 description: embed.description || ""
137 })
138 );
pineafan63fc5e22022-08-04 22:04:10 +0100139 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 selectPane = [
141 new MessageActionRow().addComponents([
142 new Discord.MessageSelectMenu()
143 .addOptions(options)
144 .setCustomId("page")
145 .setMaxValues(1)
146 .setPlaceholder("Choose a page...")
147 ])
148 ];
pineafane23c4ec2022-07-27 21:56:27 +0100149 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100150 const components = selectPane.concat([
151 new MessageActionRow().addComponents([
152 new MessageButton()
153 .setCustomId("left")
154 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
155 .setStyle("SECONDARY")
156 .setDisabled(page === 0),
157 new MessageButton()
158 .setCustomId("select")
159 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
160 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
161 .setDisabled(false),
162 new MessageButton()
163 .setCustomId("right")
164 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
165 .setStyle("SECONDARY")
166 .setDisabled(page === pages.length - 1)
167 ])
168 ]);
pineafan63fc5e22022-08-04 22:04:10 +0100169 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100170 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100171 em.setFooter({ text: nextFooter ?? "" });
pineafane23c4ec2022-07-27 21:56:27 +0100172 await interaction.editReply({
173 embeds: [em],
174 components: components.concat(pages[page].components)
175 });
pineafan63fc5e22022-08-04 22:04:10 +0100176 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100177 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100178 i = await m.awaitMessageComponent({ time: 300000 });
179 } catch (e) {
Skyler Greyad002172022-08-16 18:48:26 +0100180 timedOut = true;
181 continue;
Skyler Grey75ea9172022-08-06 10:22:23 +0100182 }
pineafan63fc5e22022-08-04 22:04:10 +0100183 nextFooter = null;
184 i.deferUpdate();
pineafane23c4ec2022-07-27 21:56:27 +0100185 if (i.component.customId === "left") {
186 if (page > 0) page--;
187 selectPaneOpen = false;
188 } else if (i.component.customId === "right") {
189 if (page < pages.length - 1) page++;
190 selectPaneOpen = false;
191 } else if (i.component.customId === "select") {
192 selectPaneOpen = !selectPaneOpen;
193 } else if (i.component.customId === "page") {
194 page = parseInt(i.values[0]);
195 selectPaneOpen = false;
196 } else if (i.component.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100197 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100198 .setEmoji("CONTROL.BLOCKCROSS")
199 .setTitle("Clear All Data")
200 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100201 "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 +0100202 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100203 )
204 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100205 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100206 if (confirmation.cancelled) {
207 break;
208 }
pineafane23c4ec2022-07-27 21:56:27 +0100209 if (confirmation.success) {
210 client.database.guilds.delete(interaction.guild.id);
211 client.database.history.delete(interaction.guild.id);
212 nextFooter = "All data cleared";
213 continue;
214 } else {
215 nextFooter = "No changes were made";
216 continue;
217 }
218 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100219 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100220 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100221 em.setFooter({ text: "Message closed" });
222 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100223 return;
pineafane23c4ec2022-07-27 21:56:27 +0100224 }
pineafan73a7c4a2022-07-24 10:38:04 +0100225 }
pineafan63fc5e22022-08-04 22:04:10 +0100226 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey11236ba2022-08-08 21:13:33 +0100227 em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page));
Skyler Grey75ea9172022-08-06 10:22:23 +0100228 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100229 await interaction.editReply({
230 embeds: [em],
231 components: []
232 });
pineafan63fc5e22022-08-04 22:04:10 +0100233};
pineafan4f164f32022-02-26 22:07:12 +0000234
Skyler Grey11236ba2022-08-08 21:13:33 +0100235const check = (_interaction: CommandInteraction, _defaultCheck: WrappedCheck) => {
pineafan4f164f32022-02-26 22:07:12 +0000236 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100237};
pineafan4f164f32022-02-26 22:07:12 +0000238
239export { command };
240export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100241export { check };