| import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
| import Discord, { CommandInteraction, MessageActionRow, MessageButton } from "discord.js"; |
| import { SelectMenuOption, SlashCommandBuilder } from "@discordjs/builders"; |
| import { WrappedCheck } from "jshaiku"; |
| import { testLink, testMalware, testNSFW } from "../reflex/scanners.js"; |
| import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| import getEmojiByName from "../utils/getEmojiByName.js"; |
| import createPageIndicator from "../utils/createPageIndicator.js"; |
| import client from "../utils/client.js"; |
| import confirmationMessage from "../utils/confirmationMessage.js"; |
| |
| const command = new SlashCommandBuilder() |
| .setName("privacy") |
| .setDescription("Information and options for you and your server's settings"); |
| |
| class Embed { |
| embed: Discord.MessageEmbed; |
| title: string; |
| description = ""; |
| pageId = 0; |
| components?: MessageActionRow[] = []; |
| setEmbed(embed: Discord.MessageEmbed) { this.embed = embed; return this; } |
| setTitle(title: string) { this.title = title; return this; } |
| setDescription(description: string) { this.description = description; return this; } |
| setPageId(pageId: number) { this.pageId = pageId; return this; } |
| setComponents(components: MessageActionRow[]) { this.components = components; return this; } |
| } |
| |
| const callback = async (interaction: CommandInteraction): Promise<any> => { |
| const pages = [ |
| new Embed() |
| .setEmbed(new EmojiEmbed() |
| .setTitle("Nucleus Privacy") |
| .setDescription( |
| "Nucleus is a bot that naturally needs to store data about servers.\n" + |
| "We are entirely [open source](https://github.com/ClicksMinutePer/Nucleus), so you can check exactly what we store, and how it works.\n\n" + |
| "If you are a server administrator, you can view the options page in the dropdown under this message.\n\n" + |
| "Any questions about Nucleus, how it works and data stored can be asked in [our server](https://discord.gg/bPaNnxe)." |
| ) |
| .setEmoji("NUCLEUS.LOGO") |
| .setStatus("Danger") |
| ).setTitle("Welcome").setDescription("General privacy information").setPageId(0), |
| new Embed() |
| .setEmbed(new EmojiEmbed() |
| .setTitle("Scanners") |
| .setDescription( |
| "Nucleus uses [unscan](https://unscan.co) to scan links, images and files for malware and other threats.\n" + |
| "This service's [privacy policy](https://unscan.co/policies) is public, and they \"do not store or sell your data.\"" |
| ) |
| .setEmoji("NUCLEUS.LOGO") |
| .setStatus("Danger") |
| ).setTitle("Scanners").setDescription("About Unscan").setPageId(1), |
| new Embed() |
| .setEmbed(new EmojiEmbed() |
| .setTitle("Link scanning and Transcripts") |
| .setDescription( |
| "**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" + |
| "**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" + |
| "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" |
| ) |
| .setEmoji("NUCLEUS.LOGO") |
| .setStatus("Danger") |
| ).setTitle("Link scanning and Transcripts").setDescription("Regarding Facebook and AMP filter types, and ticket transcripts").setPageId(2) |
| ].concat((interaction.member as Discord.GuildMember).permissions.has("ADMINISTRATOR") ? [new Embed() |
| .setEmbed(new EmojiEmbed() |
| .setTitle("Options") |
| .setDescription( |
| "Below are buttons for controlling this servers privacy settings" |
| ) |
| .setEmoji("NUCLEUS.LOGO") |
| .setStatus("Danger") |
| ).setTitle("Options").setDescription("Options").setPageId(3).setComponents([new MessageActionRow().addComponents([ |
| new MessageButton().setLabel("Clear all data").setCustomId("clear-all-data").setStyle("DANGER") |
| ])]) |
| ] : []); |
| let m; |
| m = await interaction.reply({embeds: LoadingEmbed, fetchReply: true, ephemeral: true}); |
| let page = 0; |
| |
| let selectPaneOpen = false; |
| let nextFooter = null; |
| |
| while (true) { |
| let selectPane = []; |
| |
| if (selectPaneOpen) { |
| const options = []; |
| pages.forEach(embed => { |
| options.push(new SelectMenuOption({ |
| label: embed.title, |
| value: embed.pageId.toString(), |
| description: embed.description || "" |
| })); |
| }); |
| selectPane = [new MessageActionRow().addComponents([ |
| new Discord.MessageSelectMenu() |
| .addOptions(options) |
| .setCustomId("page") |
| .setMaxValues(1) |
| .setPlaceholder("Choose a page...") |
| ])]; |
| } |
| const components = selectPane.concat([new MessageActionRow().addComponents([ |
| new MessageButton().setCustomId("left").setEmoji(getEmojiByName("CONTROL.LEFT", "id")).setStyle("SECONDARY").setDisabled(page === 0), |
| new MessageButton().setCustomId("select").setEmoji(getEmojiByName("CONTROL.MENU", "id")).setStyle(selectPaneOpen ? "PRIMARY" : "SECONDARY").setDisabled(false), |
| new MessageButton().setCustomId("right").setEmoji(getEmojiByName("CONTROL.RIGHT", "id")).setStyle("SECONDARY").setDisabled(page === pages.length - 1) |
| ])]); |
| const em = new Discord.MessageEmbed(pages[page].embed); |
| em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
| em.setFooter({text: nextFooter ?? ""}); |
| await interaction.editReply({ |
| embeds: [em], |
| components: components.concat(pages[page].components) |
| }); |
| let i; |
| try { |
| i = await m.awaitMessageComponent({time: 300000}); |
| } catch(e) { break; } |
| nextFooter = null; |
| i.deferUpdate(); |
| if (i.component.customId === "left") { |
| if (page > 0) page--; |
| selectPaneOpen = false; |
| } else if (i.component.customId === "right") { |
| if (page < pages.length - 1) page++; |
| selectPaneOpen = false; |
| } else if (i.component.customId === "select") { |
| selectPaneOpen = !selectPaneOpen; |
| } else if (i.component.customId === "page") { |
| page = parseInt(i.values[0]); |
| selectPaneOpen = false; |
| } else if (i.component.customId === "clear-all-data") { |
| const confirmation = await new confirmationMessage(interaction) |
| .setEmoji("CONTROL.BLOCKCROSS") |
| .setTitle("Clear All Data") |
| .setDescription( |
| "Are you sure you want to delete all data on this server? This includes your settings and all punishment histories.\n\n" + |
| "**This cannot be undone.**" |
| ) |
| .setColor("Danger") |
| .send(true); |
| if (confirmation.cancelled) { break; } |
| if (confirmation.success) { |
| client.database.guilds.delete(interaction.guild.id); |
| client.database.history.delete(interaction.guild.id); |
| nextFooter = "All data cleared"; |
| continue; |
| } else { |
| nextFooter = "No changes were made"; |
| continue; |
| } |
| } else { |
| const em = new Discord.MessageEmbed(pages[page].embed); |
| em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
| em.setFooter({text: "Message closed"}); |
| interaction.editReply({embeds: [em], components: []}); |
| return; |
| } |
| } |
| const em = new Discord.MessageEmbed(pages[page].embed); |
| em.setDescription(em.description + "\n\n" + createPageIndicator(pages.length, page)); |
| em.setFooter({text: "Message timed out"}); |
| await interaction.editReply({ |
| embeds: [em], |
| components: [] |
| }); |
| }; |
| |
| const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => { |
| return true; |
| }; |
| |
| export { command }; |
| export { callback }; |
| export { check }; |