pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 2 | import Discord, { GuildMember } from "discord.js"; |
| 3 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 4 | import fetch from "node-fetch"; |
| 5 | import { TestString, NSFWCheck } from "./scanners.js"; |
| 6 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 7 | import client from "../utils/client.js"; |
| 8 | |
| 9 | function step(i) { |
| 10 | return "\n\n" + createPageIndicator(5, i); |
| 11 | } |
| 12 | |
| 13 | export default async function(interaction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 14 | const verify = client.verify; |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 15 | await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 16 | const config = await client.database.guilds.read(interaction.guild.id); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 17 | if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new EmojiEmbed() |
| 18 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 19 | .setDescription("Verify is not enabled on this server") |
pineafan | 41d9356 | 2022-07-30 22:10:15 +0100 | [diff] [blame] | 20 | .setFooter({text: interaction.member.permissions.has("MANAGE_GUILD") ? "You can enable it by running /settings verify" : ""}) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 21 | .setStatus("Danger") |
| 22 | .setEmoji("CONTROL.BLOCKCROSS") |
| 23 | ], ephemeral: true, fetchReply: true}); |
| 24 | if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) { |
| 25 | return await interaction.editReply({embeds: [new EmojiEmbed() |
| 26 | .setTitle("Verify") |
| 27 | .setDescription(`You already have the <@&${config.verify.role}> role` + step(0)) |
| 28 | .setStatus("Danger") |
| 29 | .setEmoji("CONTROL.BLOCKCROSS") |
| 30 | ]}); |
| 31 | } |
| 32 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 33 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 34 | .setDescription("Checking our servers are up" + step(0)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 35 | .setStatus("Warning") |
| 36 | .setEmoji("NUCLEUS.LOADING") |
| 37 | ]}); |
| 38 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 39 | const status = await fetch(client.config.baseUrl).then(res => res.status); |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 40 | if (status !== 200) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 41 | return await interaction.editReply({embeds: [new EmojiEmbed() |
| 42 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 43 | .setDescription("Our servers appear to be down, please try again later" + step(0)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 44 | .setStatus("Danger") |
| 45 | .setEmoji("CONTROL.BLOCKCROSS") |
| 46 | ]}); |
| 47 | } |
| 48 | } catch { |
| 49 | return await interaction.editReply({embeds: [new EmojiEmbed() |
| 50 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 51 | .setDescription("Our servers appear to be down, please try again later" + step(0)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 52 | .setStatus("Danger") |
| 53 | .setEmoji("CONTROL.BLOCKCROSS") |
| 54 | ], components: [new Discord.MessageActionRow().addComponents([ |
| 55 | new Discord.MessageButton() |
| 56 | .setLabel("Check webpage") |
| 57 | .setStyle("LINK") |
| 58 | .setURL(client.config.baseUrl), |
| 59 | new Discord.MessageButton() |
| 60 | .setLabel("Support") |
| 61 | .setStyle("LINK") |
| 62 | .setURL("https://discord.gg/bPaNnxe") |
| 63 | ])]}); |
| 64 | } |
| 65 | if (config.filters.images.NSFW) { |
| 66 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 67 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 68 | .setDescription("Checking your avatar is safe for work" + step(1)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 69 | .setStatus("Warning") |
| 70 | .setEmoji("NUCLEUS.LOADING") |
| 71 | ]}); |
| 72 | if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) { |
| 73 | return await interaction.editReply({embeds: [new EmojiEmbed() |
| 74 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 75 | .setDescription("Your avatar was detected as NSFW, which we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake" + step(1)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 76 | .setStatus("Danger") |
| 77 | .setEmoji("CONTROL.BLOCKCROSS") |
| 78 | ]}); |
| 79 | } |
| 80 | } |
| 81 | if (config.filters.wordFilter) { |
| 82 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 83 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 84 | .setDescription("Checking your name is allowed" + step(2)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 85 | .setStatus("Warning") |
| 86 | .setEmoji("NUCLEUS.LOADING") |
| 87 | ]}); |
| 88 | if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) !== null) { |
| 89 | return await interaction.editReply({embeds: [new EmojiEmbed() |
| 90 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 91 | .setDescription("Your name contained a word we do not allow in this server.\nPlease contact one of our staff members if you believe this is a mistake" + step(2)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 92 | .setStatus("Danger") |
| 93 | .setEmoji("CONTROL.BLOCKCROSS") |
| 94 | ]}); |
| 95 | } |
| 96 | } |
| 97 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 98 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 99 | .setDescription("One moment..." + step(3)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 100 | .setStatus("Warning") |
| 101 | .setEmoji("NUCLEUS.LOADING") |
| 102 | ]}); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 103 | let code = ""; |
| 104 | let length = 5; |
| 105 | let itt = 0; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 106 | const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
| 107 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 108 | itt += 1; |
| 109 | code = ""; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 110 | for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); } |
| 111 | if (code in verify) continue; |
| 112 | if (itt > 1000) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 113 | itt = 0; |
| 114 | length += 1; |
| 115 | continue; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 116 | } |
| 117 | break; |
| 118 | } |
| 119 | verify[code] = { |
| 120 | uID: interaction.member.user.id, |
| 121 | gID: interaction.guild.id, |
| 122 | rID: config.verify.role, |
| 123 | rName: (await interaction.guild.roles.fetch(config.verify.role)).name, |
| 124 | uName: interaction.member.user.username, |
| 125 | gName: interaction.guild.name, |
| 126 | gIcon: interaction.guild.iconURL({format: "png"}), |
| 127 | interaction: interaction |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 128 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 129 | await interaction.editReply({embeds: [new EmojiEmbed() |
| 130 | .setTitle("Verify") |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame^] | 131 | .setDescription("Looking good!\nClick the button below to get verified" + step(4)) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 132 | .setStatus("Success") |
| 133 | .setEmoji("MEMBER.JOIN") |
| 134 | ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton() |
| 135 | .setLabel("Verify") |
| 136 | .setStyle("LINK") |
pineafan | 6d53741 | 2022-07-28 12:35:33 +0100 | [diff] [blame] | 137 | .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`) |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 138 | ])]}); |
| 139 | } |