pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +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") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +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[] = []; |
| 21 | setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; } |
| 22 | setTitle(title: string) { this.title = title; return this; } |
| 23 | setDescription(description: string) { this.description = description; return this; } |
| 24 | setPageId(pageId: number) { this.pageId = pageId; return this; } |
| 25 | setComponents(components: MessageActionRow[]) { this.components = components; return this; } |
| 26 | } |
| 27 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 28 | const callback = async (interaction: CommandInteraction): Promise<void> => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 29 | const pages = [ |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 30 | new Embed() |
| 31 | .setEmbed(new EmojiEmbed() |
| 32 | .setTitle("Nucleus Privacy") |
| 33 | .setDescription( |
| 34 | "Nucleus is a bot that naturally needs to store data about servers.\n" + |
| 35 | "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" + |
| 36 | "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" + |
| 37 | "Any questions about Nucleus, how it works and data stored can be asked in [our server](https://discord.gg/bPaNnxe)." |
| 38 | ) |
| 39 | .setEmoji("NUCLEUS.LOGO") |
| 40 | .setStatus("Danger") |
| 41 | ).setTitle("Welcome").setDescription("General privacy information").setPageId(0), |
| 42 | new Embed() |
| 43 | .setEmbed(new EmojiEmbed() |
| 44 | .setTitle("Scanners") |
| 45 | .setDescription( |
| 46 | "Nucleus uses [unscan](https://unscan.co) to scan links, images and files for malware and other threats.\n" + |
| 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") |
| 51 | ).setTitle("Scanners").setDescription("About Unscan").setPageId(1), |
| 52 | new Embed() |
| 53 | .setEmbed(new EmojiEmbed() |
| 54 | .setTitle("Link scanning and Transcripts") |
| 55 | .setDescription( |
| 56 | "**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" + |
| 57 | "**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" + |
| 58 | "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" |
| 59 | ) |
| 60 | .setEmoji("NUCLEUS.LOGO") |
| 61 | .setStatus("Danger") |
| 62 | ).setTitle("Link scanning and Transcripts").setDescription("Regarding Facebook and AMP filter types, and ticket transcripts").setPageId(2) |
| 63 | ].concat((interaction.member as Discord.GuildMember).permissions.has("ADMINISTRATOR") ? [new Embed() |
| 64 | .setEmbed(new EmojiEmbed() |
| 65 | .setTitle("Options") |
| 66 | .setDescription( |
| 67 | "Below are buttons for controlling this servers privacy settings" |
| 68 | ) |
| 69 | .setEmoji("NUCLEUS.LOGO") |
| 70 | .setStatus("Danger") |
| 71 | ).setTitle("Options").setDescription("Options").setPageId(3).setComponents([new MessageActionRow().addComponents([ |
| 72 | new MessageButton().setLabel("Clear all data").setCustomId("clear-all-data").setStyle("DANGER") |
| 73 | ])]) |
| 74 | ] : []); |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 75 | const m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true}); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 76 | let page = 0; |
| 77 | |
| 78 | let selectPaneOpen = false; |
| 79 | let nextFooter = null; |
| 80 | |
| 81 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | let selectPane = []; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 83 | |
| 84 | if (selectPaneOpen) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 85 | const options = []; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 86 | pages.forEach(embed => { |
| 87 | options.push(new SelectMenuOption({ |
| 88 | label: embed.title, |
| 89 | value: embed.pageId.toString(), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 90 | description: embed.description || "" |
| 91 | })); |
| 92 | }); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 93 | selectPane = [new MessageActionRow().addComponents([ |
| 94 | new Discord.MessageSelectMenu() |
| 95 | .addOptions(options) |
| 96 | .setCustomId("page") |
| 97 | .setMaxValues(1) |
| 98 | .setPlaceholder("Choose a page...") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 99 | ])]; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 100 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 101 | const components = selectPane.concat([new MessageActionRow().addComponents([ |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 102 | new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0), |
| 103 | new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false), |
| 104 | new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 105 | ])]); |
| 106 | const em = new Discord.MessageEmbed(pages[page].embed); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 107 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 108 | em.setFooter({text: nextFooter ?? ""}); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 109 | await interaction.editReply({ |
| 110 | embeds: [em], |
| 111 | components: components.concat(pages[page].components) |
| 112 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 113 | let i; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 114 | try { |
| 115 | i = await m.awaitMessageComponent({time: 300000}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 116 | } catch(e) { break; } |
| 117 | nextFooter = null; |
| 118 | i.deferUpdate(); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 119 | if (i.component.customId === "left") { |
| 120 | if (page > 0) page--; |
| 121 | selectPaneOpen = false; |
| 122 | } else if (i.component.customId === "right") { |
| 123 | if (page < pages.length - 1) page++; |
| 124 | selectPaneOpen = false; |
| 125 | } else if (i.component.customId === "select") { |
| 126 | selectPaneOpen = !selectPaneOpen; |
| 127 | } else if (i.component.customId === "page") { |
| 128 | page = parseInt(i.values[0]); |
| 129 | selectPaneOpen = false; |
| 130 | } else if (i.component.customId === "clear-all-data") { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 131 | const confirmation = await new confirmationMessage(interaction) |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 132 | .setEmoji("CONTROL.BLOCKCROSS") |
| 133 | .setTitle("Clear All Data") |
| 134 | .setDescription( |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 135 | "Are you sure you want to delete all data on this server? This includes your settings and all punishment histories.\n\n" + |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 136 | "**This cannot be undone.**" |
| 137 | ) |
| 138 | .setColor("Danger") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 139 | .send(true); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 140 | if (confirmation.cancelled) { break; } |
| 141 | if (confirmation.success) { |
| 142 | client.database.guilds.delete(interaction.guild.id); |
| 143 | client.database.history.delete(interaction.guild.id); |
| 144 | nextFooter = "All data cleared"; |
| 145 | continue; |
| 146 | } else { |
| 147 | nextFooter = "No changes were made"; |
| 148 | continue; |
| 149 | } |
| 150 | } else { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 151 | const em = new Discord.MessageEmbed(pages[page].embed); |
| 152 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 153 | em.setFooter({text: "Message closed"}); |
| 154 | interaction.editReply({embeds: [em], components: []}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 155 | return; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 156 | } |
pineafan | 73a7c4a | 2022-07-24 10:38:04 +0100 | [diff] [blame] | 157 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 158 | const em = new Discord.MessageEmbed(pages[page].embed); |
| 159 | em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 160 | em.setFooter({text: "Message timed out"}); |
| 161 | await interaction.editReply({ |
| 162 | embeds: [em], |
| 163 | components: [] |
| 164 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 165 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 166 | |
pineafan | bd02b4a | 2022-08-05 22:01:38 +0100 | [diff] [blame^] | 167 | const check = (_interaction: CommandInteraction, _defaultCheck: WrappedCheck) => { |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 168 | return true; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 169 | }; |
pineafan | 4f164f3 | 2022-02-26 22:07:12 +0000 | [diff] [blame] | 170 | |
| 171 | export { command }; |
| 172 | export { callback }; |
| 173 | export { check }; |