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