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