blob: 3d4e658d3534ac7a8af05e210f09fe65e8dfa9ab [file] [log] [blame]
pineafanad54d752022-04-18 19:01:43 +01001import Discord, { CommandInteraction, GuildMember } from "discord.js";
2import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
3import readConfig from "../utils/readConfig.js";
4import fetch from "node-fetch";
5import { TestString, NSFWCheck } from "../automations/unscan.js";
pineafan34369e62022-05-18 16:52:37 +01006import createPageIndicator from "../utils/createPageIndicator.js";
7
8function step(i) {
9 return "\n\n" + createPageIndicator(5, i);
10}
pineafanad54d752022-04-18 19:01:43 +010011
12export default async function(interaction) {
13 // @ts-ignore
14 let verify = interaction.client.verify
15 await interaction.reply({embeds: [new generateEmojiEmbed()
16 .setTitle("Loading")
pineafan34369e62022-05-18 16:52:37 +010017 .setDescription(step(-1))
pineafanad54d752022-04-18 19:01:43 +010018 .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")
pineafan34369e62022-05-18 16:52:37 +010025 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
pineafanad54d752022-04-18 19:01:43 +010026 .setStatus("Danger")
27 .setEmoji("CONTROL.BLOCKCROSS")
28 ]});
29 }
30 await interaction.editReply({embeds: [new generateEmojiEmbed()
31 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010032 .setDescription(`Checking our servers are up` + step(0))
pineafanad54d752022-04-18 19:01:43 +010033 .setStatus("Warning")
34 .setEmoji("NUCLEUS.LOADING")
35 ]});
36 try {
pineafan34369e62022-05-18 16:52:37 +010037 let status = await fetch(`https://clicks.codes/`).then(res => res.status);
pineafanad54d752022-04-18 19:01:43 +010038 if (status != 200) {
39 return await interaction.editReply({embeds: [new generateEmojiEmbed()
40 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010041 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010042 .setStatus("Danger")
43 .setEmoji("CONTROL.BLOCKCROSS")
44 ]});
45 }
46 } catch {
47 return await interaction.editReply({embeds: [new generateEmojiEmbed()
48 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010049 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010050 .setStatus("Danger")
51 .setEmoji("CONTROL.BLOCKCROSS")
52 ], components: [new Discord.MessageActionRow().addComponents([
53 new Discord.MessageButton()
pineafane625d782022-05-09 18:04:32 +010054 .setLabel("Check webpage")
pineafanad54d752022-04-18 19:01:43 +010055 .setStyle("LINK")
pineafane625d782022-05-09 18:04:32 +010056 .setURL("https://clicks.codes/"),
pineafanad54d752022-04-18 19:01:43 +010057 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")
pineafan34369e62022-05-18 16:52:37 +010066 .setDescription(`Checking your avatar is safe for work` + step(1))
pineafanad54d752022-04-18 19:01:43 +010067 .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")
pineafan34369e62022-05-18 16:52:37 +010073 .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))
pineafanad54d752022-04-18 19:01:43 +010074 .setStatus("Danger")
75 .setEmoji("CONTROL.BLOCKCROSS")
76 ]});
77 }
78 }
79 if (config.filters.wordFilter) {
80 await interaction.editReply({embeds: [new generateEmojiEmbed()
81 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010082 .setDescription(`Checking your name is allowed` + step(2))
pineafanad54d752022-04-18 19:01:43 +010083 .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")
pineafan34369e62022-05-18 16:52:37 +010089 .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))
pineafanad54d752022-04-18 19:01:43 +010090 .setStatus("Danger")
91 .setEmoji("CONTROL.BLOCKCROSS")
92 ]});
93 }
94 }
95 await interaction.editReply({embeds: [new generateEmojiEmbed()
96 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010097 .setDescription(`One moment...` + step(3))
pineafanad54d752022-04-18 19:01:43 +010098 .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,
pineafane625d782022-05-09 18:04:32 +0100120 rID: config.verify.role,
pineafanad54d752022-04-18 19:01:43 +0100121 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
122 mCount: interaction.guild.memberCount,
123 gName: interaction.guild.name,
pineafane625d782022-05-09 18:04:32 +0100124 gIcon: interaction.guild.iconURL({format: "png"}),
125 interaction: interaction
pineafanad54d752022-04-18 19:01:43 +0100126 }
127 await interaction.editReply({embeds: [new generateEmojiEmbed()
128 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +0100129 .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
pineafanad54d752022-04-18 19:01:43 +0100130 .setStatus("Success")
131 .setEmoji("MEMBER.JOIN")
132 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
133 .setLabel("Verify")
134 .setStyle("LINK")
pineafane625d782022-05-09 18:04:32 +0100135 // .setURL(`https://clicks.codes/nucleus/verify?code=${code}`)
136 .setURL(`https://insulation-coin-hoping-nevertheless.trycloudflare.com/nucleus/verify?code=${code}`)
pineafanad54d752022-04-18 19:01:43 +0100137 ])]});
pineafane625d782022-05-09 18:04:32 +0100138}