blob: a60ed07bff6804dc597a7a6292f5cfa66e8e3f2a [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 {
pineafane625d782022-05-09 18:04:32 +010031 let status = await fetch(`https://clicks.codes`).then(res => res.status);
pineafanad54d752022-04-18 19:01:43 +010032 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()
pineafane625d782022-05-09 18:04:32 +010048 .setLabel("Check webpage")
pineafanad54d752022-04-18 19:01:43 +010049 .setStyle("LINK")
pineafane625d782022-05-09 18:04:32 +010050 .setURL("https://clicks.codes/"),
pineafanad54d752022-04-18 19:01:43 +010051 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,
pineafane625d782022-05-09 18:04:32 +0100114 rID: config.verify.role,
pineafanad54d752022-04-18 19:01:43 +0100115 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
116 mCount: interaction.guild.memberCount,
117 gName: interaction.guild.name,
pineafane625d782022-05-09 18:04:32 +0100118 gIcon: interaction.guild.iconURL({format: "png"}),
119 interaction: interaction
pineafanad54d752022-04-18 19:01:43 +0100120 }
121 await interaction.editReply({embeds: [new generateEmojiEmbed()
122 .setTitle("Verify")
123 .setDescription(`Looking good!\nClick the button below to get verified`)
124 .setStatus("Success")
125 .setEmoji("MEMBER.JOIN")
126 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
127 .setLabel("Verify")
128 .setStyle("LINK")
pineafane625d782022-05-09 18:04:32 +0100129 // .setURL(`https://clicks.codes/nucleus/verify?code=${code}`)
130 .setURL(`https://insulation-coin-hoping-nevertheless.trycloudflare.com/nucleus/verify?code=${code}`)
pineafanad54d752022-04-18 19:01:43 +0100131 ])]});
pineafane625d782022-05-09 18:04:32 +0100132}