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