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