| import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
| import Discord, { CommandInteraction, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; |
| import { SlashCommandBuilder } from "@discordjs/builders"; |
| 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.EmbedBuilder; |
| title: string; |
| description = ""; |
| pageId = 0; |
| components?: ActionRowBuilder[] = []; |
| setEmbed(embed: Discord.EmbedBuilder) { |
| 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: ActionRowBuilder[]) { |
| this.components = components; |
| return this; |
| } |
| } |
| |
| const callback = async (interaction: CommandInteraction): Promise<void> => { |
| 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://rapidapi.com/abcdan/api/unscan/) 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 ActionRowBuilder().addComponents([ |
| new ButtonBuilder() |
| .setLabel("Clear all data") |
| .setCustomId("clear-all-data") |
| .setStyle(ButtonStyle.Danger) |
| ]) |
| ]) |
| ] |
| : [] |
| ); |
| const m = await interaction.reply({ |
| embeds: LoadingEmbed, |
| fetchReply: true, |
| ephemeral: true |
| }); |
| let page = 0; |
| |
| let selectPaneOpen = false; |
| let nextFooter = null; |
| |
| let timedOut = false; |
| while (!timedOut) { |
| 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 ActionRowBuilder().addComponents([ |
| new Discord.SelectMenuBuilder() |
| .addOptions(options) |
| .setCustomId("page") |
| .setMaxValues(1) |
| .setPlaceholder("Choose a page...") |
| ]) |
| ]; |
| } |
| const components = selectPane.concat([ |
| new ActionRowBuilder().addComponents([ |
| new ButtonBuilder() |
| .setCustomId("left") |
| .setEmoji(getEmojiByName("CONTROL.LEFT", "id")) |
| .setStyle(ButtonStyle.Secondary) |
| .setDisabled(page === 0), |
| new ButtonBuilder() |
| .setCustomId("select") |
| .setEmoji(getEmojiByName("CONTROL.MENU", "id")) |
| .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary) |
| .setDisabled(false), |
| new ButtonBuilder() |
| .setCustomId("right") |
| .setEmoji(getEmojiByName("CONTROL.RIGHT", "id")) |
| .setStyle(ButtonStyle.Secondary) |
| .setDisabled(page === pages.length - 1) |
| ]) |
| ]); |
| const em = new Discord.EmbedBuilder(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) { |
| timedOut = true; |
| continue; |
| } |
| 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.EmbedBuilder(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.EmbedBuilder(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) => { |
| return true; |
| }; |
| |
| export { command }; |
| export { callback }; |
| export { check }; |