blob: 3c36ea1a1eb6936c4292064b042c843c5300e828 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01002import Discord, {
3 CommandInteraction,
4 MessageActionRow,
5 MessageButton
6} from "discord.js";
pineafane23c4ec2022-07-27 21:56:27 +01007import { SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders";
pineafan4f164f32022-02-26 22:07:12 +00008import { WrappedCheck } from "jshaiku";
pineafan73a7c4a2022-07-24 10:38:04 +01009import EmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafane23c4ec2022-07-27 21:56:27 +010010import getEmojiByName from "../utils/getEmojiByName.js";
11import createPageIndicator from "../utils/createPageIndicator.js";
12import client from "../utils/client.js";
13import confirmationMessage from "../utils/confirmationMessage.js";
pineafan4f164f32022-02-26 22:07:12 +000014
15const command = new SlashCommandBuilder()
16 .setName("privacy")
Skyler Grey75ea9172022-08-06 10:22:23 +010017 .setDescription(
18 "Information and options for you and your server's settings"
19 );
pineafan4f164f32022-02-26 22:07:12 +000020
pineafane23c4ec2022-07-27 21:56:27 +010021class Embed {
22 embed: Discord.MessageEmbed;
23 title: string;
pineafan63fc5e22022-08-04 22:04:10 +010024 description = "";
25 pageId = 0;
pineafane23c4ec2022-07-27 21:56:27 +010026 components?: MessageActionRow[] = [];
Skyler Grey75ea9172022-08-06 10:22:23 +010027 setEmbed(embed: Discord.MessageEmbed) {
28 this.embed = embed;
29 return this;
30 }
31 setTitle(title: string) {
32 this.title = title;
33 return this;
34 }
35 setDescription(description: string) {
36 this.description = description;
37 return this;
38 }
39 setPageId(pageId: number) {
40 this.pageId = pageId;
41 return this;
42 }
43 setComponents(components: MessageActionRow[]) {
44 this.components = components;
45 return this;
46 }
pineafane23c4ec2022-07-27 21:56:27 +010047}
48
pineafanbd02b4a2022-08-05 22:01:38 +010049const callback = async (interaction: CommandInteraction): Promise<void> => {
pineafan63fc5e22022-08-04 22:04:10 +010050 const pages = [
pineafane23c4ec2022-07-27 21:56:27 +010051 new Embed()
Skyler Grey75ea9172022-08-06 10:22:23 +010052 .setEmbed(
53 new EmojiEmbed()
54 .setTitle("Nucleus Privacy")
55 .setDescription(
56 "Nucleus is a bot that naturally needs to store data about servers.\n" +
57 "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" +
58 "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" +
59 "Any questions about Nucleus, how it works and data stored can be asked in [our server](https://discord.gg/bPaNnxe)."
60 )
61 .setEmoji("NUCLEUS.LOGO")
62 .setStatus("Danger")
pineafane23c4ec2022-07-27 21:56:27 +010063 )
Skyler Grey75ea9172022-08-06 10:22:23 +010064 .setTitle("Welcome")
65 .setDescription("General privacy information")
66 .setPageId(0),
67 new Embed()
68 .setEmbed(
69 new EmojiEmbed()
70 .setTitle("Scanners")
71 .setDescription(
72 "Nucleus uses [unscan](https://unscan.co) to scan links, images and files for malware and other threats.\n" +
73 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."'
74 )
75 .setEmoji("NUCLEUS.LOGO")
76 .setStatus("Danger")
77 )
78 .setTitle("Scanners")
79 .setDescription("About Unscan")
80 .setPageId(1),
81 new Embed()
82 .setEmbed(
83 new EmojiEmbed()
84 .setTitle("Link scanning and Transcripts")
85 .setDescription(
86 "**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" +
87 "**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" +
88 "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"
89 )
90 .setEmoji("NUCLEUS.LOGO")
91 .setStatus("Danger")
92 )
93 .setTitle("Link scanning and Transcripts")
94 .setDescription(
95 "Regarding Facebook and AMP filter types, and ticket transcripts"
96 )
97 .setPageId(2)
98 ].concat(
99 (interaction.member as Discord.GuildMember).permissions.has(
100 "ADMINISTRATOR"
101 )
102 ? [
103 new Embed()
104 .setEmbed(
105 new EmojiEmbed()
106 .setTitle("Options")
107 .setDescription(
108 "Below are buttons for controlling this servers privacy settings"
109 )
110 .setEmoji("NUCLEUS.LOGO")
111 .setStatus("Danger")
112 )
113 .setTitle("Options")
114 .setDescription("Options")
115 .setPageId(3)
116 .setComponents([
117 new MessageActionRow().addComponents([
118 new MessageButton()
119 .setLabel("Clear all data")
120 .setCustomId("clear-all-data")
121 .setStyle("DANGER")
122 ])
123 ])
124 ]
125 : []
126 );
127 const m = await interaction.reply({
128 embeds: LoadingEmbed,
129 fetchReply: true,
130 ephemeral: true
131 });
pineafane23c4ec2022-07-27 21:56:27 +0100132 let page = 0;
133
134 let selectPaneOpen = false;
135 let nextFooter = null;
136
137 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100138 let selectPane = [];
pineafane23c4ec2022-07-27 21:56:27 +0100139
140 if (selectPaneOpen) {
pineafan63fc5e22022-08-04 22:04:10 +0100141 const options = [];
Skyler Grey75ea9172022-08-06 10:22:23 +0100142 pages.forEach((embed) => {
143 options.push(
144 new SelectMenuOption({
145 label: embed.title,
146 value: embed.pageId.toString(),
147 description: embed.description || ""
148 })
149 );
pineafan63fc5e22022-08-04 22:04:10 +0100150 });
Skyler Grey75ea9172022-08-06 10:22:23 +0100151 selectPane = [
152 new MessageActionRow().addComponents([
153 new Discord.MessageSelectMenu()
154 .addOptions(options)
155 .setCustomId("page")
156 .setMaxValues(1)
157 .setPlaceholder("Choose a page...")
158 ])
159 ];
pineafane23c4ec2022-07-27 21:56:27 +0100160 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100161 const components = selectPane.concat([
162 new MessageActionRow().addComponents([
163 new MessageButton()
164 .setCustomId("left")
165 .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
166 .setStyle("SECONDARY")
167 .setDisabled(page === 0),
168 new MessageButton()
169 .setCustomId("select")
170 .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
171 .setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY")
172 .setDisabled(false),
173 new MessageButton()
174 .setCustomId("right")
175 .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
176 .setStyle("SECONDARY")
177 .setDisabled(page === pages.length - 1)
178 ])
179 ]);
pineafan63fc5e22022-08-04 22:04:10 +0100180 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey75ea9172022-08-06 10:22:23 +0100181 em.setDescription(
182 em.description + "\n\n" + createPageIndicator(pages.length, page)
183 );
184 em.setFooter({ text: nextFooter ?? "" });
pineafane23c4ec2022-07-27 21:56:27 +0100185 await interaction.editReply({
186 embeds: [em],
187 components: components.concat(pages[page].components)
188 });
pineafan63fc5e22022-08-04 22:04:10 +0100189 let i;
pineafane23c4ec2022-07-27 21:56:27 +0100190 try {
Skyler Grey75ea9172022-08-06 10:22:23 +0100191 i = await m.awaitMessageComponent({ time: 300000 });
192 } catch (e) {
193 break;
194 }
pineafan63fc5e22022-08-04 22:04:10 +0100195 nextFooter = null;
196 i.deferUpdate();
pineafane23c4ec2022-07-27 21:56:27 +0100197 if (i.component.customId === "left") {
198 if (page > 0) page--;
199 selectPaneOpen = false;
200 } else if (i.component.customId === "right") {
201 if (page < pages.length - 1) page++;
202 selectPaneOpen = false;
203 } else if (i.component.customId === "select") {
204 selectPaneOpen = !selectPaneOpen;
205 } else if (i.component.customId === "page") {
206 page = parseInt(i.values[0]);
207 selectPaneOpen = false;
208 } else if (i.component.customId === "clear-all-data") {
pineafan63fc5e22022-08-04 22:04:10 +0100209 const confirmation = await new confirmationMessage(interaction)
pineafane23c4ec2022-07-27 21:56:27 +0100210 .setEmoji("CONTROL.BLOCKCROSS")
211 .setTitle("Clear All Data")
212 .setDescription(
pineafan63fc5e22022-08-04 22:04:10 +0100213 "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 +0100214 "**This cannot be undone.**"
pineafane23c4ec2022-07-27 21:56:27 +0100215 )
216 .setColor("Danger")
pineafan63fc5e22022-08-04 22:04:10 +0100217 .send(true);
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 if (confirmation.cancelled) {
219 break;
220 }
pineafane23c4ec2022-07-27 21:56:27 +0100221 if (confirmation.success) {
222 client.database.guilds.delete(interaction.guild.id);
223 client.database.history.delete(interaction.guild.id);
224 nextFooter = "All data cleared";
225 continue;
226 } else {
227 nextFooter = "No changes were made";
228 continue;
229 }
230 } else {
pineafan63fc5e22022-08-04 22:04:10 +0100231 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey75ea9172022-08-06 10:22:23 +0100232 em.setDescription(
233 em.description +
234 "\n\n" +
235 createPageIndicator(pages.length, page)
236 );
237 em.setFooter({ text: "Message closed" });
238 interaction.editReply({ embeds: [em], components: [] });
pineafan63fc5e22022-08-04 22:04:10 +0100239 return;
pineafane23c4ec2022-07-27 21:56:27 +0100240 }
pineafan73a7c4a2022-07-24 10:38:04 +0100241 }
pineafan63fc5e22022-08-04 22:04:10 +0100242 const em = new Discord.MessageEmbed(pages[page].embed);
Skyler Grey75ea9172022-08-06 10:22:23 +0100243 em.setDescription(
244 em.description + "\n\n" + createPageIndicator(pages.length, page)
245 );
246 em.setFooter({ text: "Message timed out" });
pineafane23c4ec2022-07-27 21:56:27 +0100247 await interaction.editReply({
248 embeds: [em],
249 components: []
250 });
pineafan63fc5e22022-08-04 22:04:10 +0100251};
pineafan4f164f32022-02-26 22:07:12 +0000252
Skyler Grey75ea9172022-08-06 10:22:23 +0100253const check = (
254 _interaction: CommandInteraction,
255 _defaultCheck: WrappedCheck
256) => {
pineafan4f164f32022-02-26 22:07:12 +0000257 return true;
pineafan63fc5e22022-08-04 22:04:10 +0100258};
pineafan4f164f32022-02-26 22:07:12 +0000259
260export { command };
261export { callback };
Skyler Grey75ea9172022-08-06 10:22:23 +0100262export { check };