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