pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 2 | import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 3 | import { SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 4 | import { WrappedCheck } from "jshaiku"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 5 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 6 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 7 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 8 | import client from "../utils/client.js"; |
| 9 | import confirmationMessage from "../utils/confirmationMessage.js"; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 10 | |
| 11 | const command = new SlashCommandBuilder() |
| 12 | .setName("privacy") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 13 | .setDescription("Information and options for you and your server's settings"); |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 14 | |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 15 | class Embed { |
| 16 | embed: Discord.MessageEmbed; |
| 17 | title: string; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | description = ""; |
| 19 | pageId = 0; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 20 | components?: MessageActionRow[] = []; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | 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 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 41 | } |
| 42 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame] | 43 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | const pages = [ |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 45 | new Embed() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 46 | .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") |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 57 | ) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 58 | .setTitle("Welcome") |
| 59 | .setDescription("General privacy information") |
| 60 | .setPageId(0), |
| 61 | new Embed() |
| 62 | .setEmbed( |
| 63 | new EmojiEmbed() |
| 64 | .setTitle("Scanners") |
| 65 | .setDescription( |
| 66 | "Nucleus uses [unscan](https://unscan.co) to scan links, images and files for malware and other threats.\n" + |
| 67 | '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 Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 88 | .setDescription("Regarding Facebook and AMP filter types, and ticket transcripts") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 89 | .setPageId(2) |
| 90 | ].concat( |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 91 | (interaction.member as Discord.GuildMember).permissions.has("ADMINISTRATOR") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 92 | ? [ |
| 93 | new Embed() |
| 94 | .setEmbed( |
| 95 | new EmojiEmbed() |
| 96 | .setTitle("Options") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 97 | .setDescription("Below are buttons for controlling this servers privacy settings") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 98 | .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 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 120 | let page = 0; |
| 121 | |
| 122 | let selectPaneOpen = false; |
| 123 | let nextFooter = null; |
| 124 | |
| 125 | while (true) { |
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 = [ |
| 140 | new MessageActionRow().addComponents([ |
| 141 | new Discord.MessageSelectMenu() |
| 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([ |
| 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 | ]); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 168 | const em = new Discord.MessageEmbed(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) { |
| 179 | break; |
| 180 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 181 | nextFooter = null; |
| 182 | i.deferUpdate(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 183 | 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") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 195 | const confirmation = await new confirmationMessage(interaction) |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 196 | .setEmoji("CONTROL.BLOCKCROSS") |
| 197 | .setTitle("Clear All Data") |
| 198 | .setDescription( |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 199 | "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] | 200 | "**This cannot be undone.**" |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 201 | ) |
| 202 | .setColor("Danger") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 203 | .send(true); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 204 | if (confirmation.cancelled) { |
| 205 | break; |
| 206 | } |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 207 | 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 { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 217 | const em = new Discord.MessageEmbed(pages[page].embed); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 218 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 219 | em.setFooter({ text: "Message closed" }); |
| 220 | interaction.editReply({ embeds: [em], components: [] }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 221 | return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 222 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 223 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 224 | const em = new Discord.MessageEmbed(pages[page].embed); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 225 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 226 | em.setFooter({ text: "Message timed out" }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 227 | await interaction.editReply({ |
| 228 | embeds: [em], |
| 229 | components: [] |
| 230 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 231 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 232 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame^] | 233 | const check = (_interaction: CommandInteraction, _defaultCheck: WrappedCheck) => { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 234 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 235 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 236 | |
| 237 | export { command }; |
| 238 | export { callback }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 239 | export { check }; |