pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | MessageActionRow, |
| 5 | MessageButton |
| 6 | } from "discord.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 7 | import { SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 8 | import { WrappedCheck } from "jshaiku"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 9 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 10 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 11 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 12 | import client from "../utils/client.js"; |
| 13 | import confirmationMessage from "../utils/confirmationMessage.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 14 | |
| 15 | const command = new SlashCommandBuilder() |
| 16 | .setName("privacy") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 17 | .setDescription( |
| 18 | "Information and options for you and your server's settings" |
| 19 | ); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 20 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 21 | class Embed { |
| 22 | embed: Discord.MessageEmbed; |
| 23 | title: string; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 24 | description = ""; |
| 25 | pageId = 0; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 26 | components?: MessageActionRow[] = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 27 | 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 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 47 | } |
| 48 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 49 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | const pages = [ |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 51 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 52 | .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") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 63 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 64 | .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 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 132 | let page = 0; |
| 133 | |
| 134 | let selectPaneOpen = false; |
| 135 | let nextFooter = null; |
| 136 | |
| 137 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 138 | let selectPane = []; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 139 | |
| 140 | if (selectPaneOpen) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 141 | const options = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 142 | pages.forEach((embed) => { |
| 143 | options.push( |
| 144 | new SelectMenuOption({ |
| 145 | label: embed.title, |
| 146 | value: embed.pageId.toString(), |
| 147 | description: embed.description || "" |
| 148 | }) |
| 149 | ); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 150 | }); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 151 | 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 | ]; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 160 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 161 | 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 | ]); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 180 | const em = new Discord.MessageEmbed(pages[page].embed); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 181 | em.setDescription( |
| 182 | em.description + "\n\n" + createPageIndicator(pages.length, page) |
| 183 | ); |
| 184 | em.setFooter({ text: nextFooter ?? "" }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 185 | await interaction.editReply({ |
| 186 | embeds: [em], |
| 187 | components: components.concat(pages[page].components) |
| 188 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 189 | let i; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 190 | try { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 191 | i = await m.awaitMessageComponent({ time: 300000 }); |
| 192 | } catch (e) { |
| 193 | break; |
| 194 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 195 | nextFooter = null; |
| 196 | i.deferUpdate(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 197 | 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") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 209 | const confirmation = await new confirmationMessage(interaction) |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 210 | .setEmoji("CONTROL.BLOCKCROSS") |
| 211 | .setTitle("Clear All Data") |
| 212 | .setDescription( |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 213 | "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^] | 214 | "**This cannot be undone.**" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 215 | ) |
| 216 | .setColor("Danger") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 217 | .send(true); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 218 | if (confirmation.cancelled) { |
| 219 | break; |
| 220 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 221 | 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 { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 231 | const em = new Discord.MessageEmbed(pages[page].embed); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 232 | 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: [] }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 239 | return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 240 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 241 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 242 | const em = new Discord.MessageEmbed(pages[page].embed); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 243 | em.setDescription( |
| 244 | em.description + "\n\n" + createPageIndicator(pages.length, page) |
| 245 | ); |
| 246 | em.setFooter({ text: "Message timed out" }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 247 | await interaction.editReply({ |
| 248 | embeds: [em], |
| 249 | components: [] |
| 250 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 251 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 252 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 253 | const check = ( |
| 254 | _interaction: CommandInteraction, |
| 255 | _defaultCheck: WrappedCheck |
| 256 | ) => { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 257 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 258 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 259 | |
| 260 | export { command }; |
| 261 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 262 | export { check }; |