pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 2 | import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame^] | 3 | import { SlashCommandBuilder } from "@discordjs/builders"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 4 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 5 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 6 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 7 | import client from "../utils/client.js"; |
| 8 | import confirmationMessage from "../utils/confirmationMessage.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 9 | |
| 10 | const command = new SlashCommandBuilder() |
| 11 | .setName("privacy") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 12 | .setDescription("Information and options for you and your server's settings"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 13 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 14 | class Embed { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 15 | embed: Discord.EmbedBuilder; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 16 | title: string; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | description = ""; |
| 18 | pageId = 0; |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 19 | components?: ActionRowBuilder[] = []; |
| 20 | setEmbed(embed: Discord.EmbedBuilder) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | this.embed = embed; |
| 22 | return this; |
| 23 | } |
| 24 | setTitle(title: string) { |
| 25 | this.title = title; |
| 26 | return this; |
| 27 | } |
| 28 | setDescription(description: string) { |
| 29 | this.description = description; |
| 30 | return this; |
| 31 | } |
| 32 | setPageId(pageId: number) { |
| 33 | this.pageId = pageId; |
| 34 | return this; |
| 35 | } |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 36 | setComponents(components: ActionRowBuilder[]) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 37 | this.components = components; |
| 38 | return this; |
| 39 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 40 | } |
| 41 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 42 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 43 | const pages = [ |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 44 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | .setEmbed( |
| 46 | new EmojiEmbed() |
| 47 | .setTitle("Nucleus Privacy") |
| 48 | .setDescription( |
| 49 | "Nucleus is a bot that naturally needs to store data about servers.\n" + |
| 50 | "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" + |
| 51 | "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" + |
| 52 | "Any questions about Nucleus, how it works and data stored can be asked in [our server](https://discord.gg/bPaNnxe)." |
| 53 | ) |
| 54 | .setEmoji("NUCLEUS.LOGO") |
| 55 | .setStatus("Danger") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 56 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 57 | .setTitle("Welcome") |
| 58 | .setDescription("General privacy information") |
| 59 | .setPageId(0), |
| 60 | new Embed() |
| 61 | .setEmbed( |
| 62 | new EmojiEmbed() |
| 63 | .setTitle("Scanners") |
| 64 | .setDescription( |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 65 | "Nucleus uses [unscan](https://rapidapi.com/abcdan/api/unscan/) to scan links, images and files for malware and other threats.\n" + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 66 | 'This service\'s [privacy policy](https://unscan.co/policies) is public, and they "do not store or sell your data."' |
| 67 | ) |
| 68 | .setEmoji("NUCLEUS.LOGO") |
| 69 | .setStatus("Danger") |
| 70 | ) |
| 71 | .setTitle("Scanners") |
| 72 | .setDescription("About Unscan") |
| 73 | .setPageId(1), |
| 74 | new Embed() |
| 75 | .setEmbed( |
| 76 | new EmojiEmbed() |
| 77 | .setTitle("Link scanning and Transcripts") |
| 78 | .setDescription( |
| 79 | "**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" + |
| 80 | "**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" + |
| 81 | "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" |
| 82 | ) |
| 83 | .setEmoji("NUCLEUS.LOGO") |
| 84 | .setStatus("Danger") |
| 85 | ) |
| 86 | .setTitle("Link scanning and Transcripts") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 87 | .setDescription("Regarding Facebook and AMP filter types, and ticket transcripts") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | .setPageId(2) |
| 89 | ].concat( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 90 | (interaction.member as Discord.GuildMember).permissions.has("ADMINISTRATOR") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 91 | ? [ |
| 92 | new Embed() |
| 93 | .setEmbed( |
| 94 | new EmojiEmbed() |
| 95 | .setTitle("Options") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 96 | .setDescription("Below are buttons for controlling this servers privacy settings") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | .setEmoji("NUCLEUS.LOGO") |
| 98 | .setStatus("Danger") |
| 99 | ) |
| 100 | .setTitle("Options") |
| 101 | .setDescription("Options") |
| 102 | .setPageId(3) |
| 103 | .setComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 104 | new ActionRowBuilder().addComponents([ |
| 105 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 106 | .setLabel("Clear all data") |
| 107 | .setCustomId("clear-all-data") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 108 | .setStyle(ButtonStyle.Danger) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 109 | ]) |
| 110 | ]) |
| 111 | ] |
| 112 | : [] |
| 113 | ); |
| 114 | const m = await interaction.reply({ |
| 115 | embeds: LoadingEmbed, |
| 116 | fetchReply: true, |
| 117 | ephemeral: true |
| 118 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 119 | let page = 0; |
| 120 | |
| 121 | let selectPaneOpen = false; |
| 122 | let nextFooter = null; |
| 123 | |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 124 | let timedOut = false; |
| 125 | while (!timedOut) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 126 | let selectPane = []; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 127 | |
| 128 | if (selectPaneOpen) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 129 | const options = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 130 | pages.forEach((embed) => { |
| 131 | options.push( |
| 132 | new SelectMenuOption({ |
| 133 | label: embed.title, |
| 134 | value: embed.pageId.toString(), |
| 135 | description: embed.description || "" |
| 136 | }) |
| 137 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 138 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 139 | selectPane = [ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 140 | new ActionRowBuilder().addComponents([ |
| 141 | new Discord.SelectMenuBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 142 | .addOptions(options) |
| 143 | .setCustomId("page") |
| 144 | .setMaxValues(1) |
| 145 | .setPlaceholder("Choose a page...") |
| 146 | ]) |
| 147 | ]; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 148 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 149 | const components = selectPane.concat([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 150 | new ActionRowBuilder().addComponents([ |
| 151 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 152 | .setCustomId("left") |
| 153 | .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 154 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 155 | .setDisabled(page === 0), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 156 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 157 | .setCustomId("select") |
| 158 | .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 159 | .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 160 | .setDisabled(false), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 161 | new ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 162 | .setCustomId("right") |
| 163 | .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 164 | .setStyle(ButtonStyle.Secondary) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 165 | .setDisabled(page === pages.length - 1) |
| 166 | ]) |
| 167 | ]); |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 168 | const em = new Discord.EmbedBuilder(pages[page].embed); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 169 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 170 | em.setFooter({ text: nextFooter ?? "" }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 171 | await interaction.editReply({ |
| 172 | embeds: [em], |
| 173 | components: components.concat(pages[page].components) |
| 174 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 175 | let i; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 176 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 177 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 178 | } catch (e) { |
Skyler Grey | ad00217 | 2022-08-16 18:48:26 +0100 | [diff] [blame] | 179 | timedOut = true; |
| 180 | continue; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 181 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 182 | nextFooter = null; |
| 183 | i.deferUpdate(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 184 | if (i.component.customId === "left") { |
| 185 | if (page > 0) page--; |
| 186 | selectPaneOpen = false; |
| 187 | } else if (i.component.customId === "right") { |
| 188 | if (page < pages.length - 1) page++; |
| 189 | selectPaneOpen = false; |
| 190 | } else if (i.component.customId === "select") { |
| 191 | selectPaneOpen = !selectPaneOpen; |
| 192 | } else if (i.component.customId === "page") { |
| 193 | page = parseInt(i.values[0]); |
| 194 | selectPaneOpen = false; |
| 195 | } else if (i.component.customId === "clear-all-data") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 196 | const confirmation = await new confirmationMessage(interaction) |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 197 | .setEmoji("CONTROL.BLOCKCROSS") |
| 198 | .setTitle("Clear All Data") |
| 199 | .setDescription( |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 200 | "Are you sure you want to delete all data on this server? This includes your settings and all punishment histories.\n\n" + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 201 | "**This cannot be undone.**" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 202 | ) |
| 203 | .setColor("Danger") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 204 | .send(true); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 205 | if (confirmation.cancelled) { |
| 206 | break; |
| 207 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 208 | if (confirmation.success) { |
| 209 | client.database.guilds.delete(interaction.guild.id); |
| 210 | client.database.history.delete(interaction.guild.id); |
| 211 | nextFooter = "All data cleared"; |
| 212 | continue; |
| 213 | } else { |
| 214 | nextFooter = "No changes were made"; |
| 215 | continue; |
| 216 | } |
| 217 | } else { |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 218 | const em = new Discord.EmbedBuilder(pages[page].embed); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 219 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 220 | em.setFooter({ text: "Message closed" }); |
| 221 | interaction.editReply({ embeds: [em], components: [] }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 222 | return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 223 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 224 | } |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 225 | const em = new Discord.EmbedBuilder(pages[page].embed); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 226 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 227 | em.setFooter({ text: "Message timed out" }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 228 | await interaction.editReply({ |
| 229 | embeds: [em], |
| 230 | components: [] |
| 231 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 232 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 233 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame^] | 234 | const check = (_interaction: CommandInteraction) => { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 235 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 236 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 237 | |
| 238 | export { command }; |
| 239 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 240 | export { check }; |