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