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