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