blob: 9d90dde787e881cc486d51ee0d0fb7a2b752ef9b [file] [log] [blame]
pineafan813bdf42022-07-24 10:39:10 +01001import Discord, { GuildMember } from "discord.js";
2import EmojiEmbed from "../utils/generateEmojiEmbed.js";
3import fetch from "node-fetch";
4import { TestString, NSFWCheck } from "./scanners.js";
5import createPageIndicator from "../utils/createPageIndicator.js";
6import client from "../utils/client.js";
7
8function step(i) {
9 return "\n\n" + createPageIndicator(5, i);
10}
11
12export default async function(interaction) {
13 let verify = client.verify
14 await interaction.reply({embeds: [new EmojiEmbed()
15 .setTitle("Loading")
16 .setDescription(step(-1))
17 .setStatus("Danger")
18 .setEmoji("NUCLEUS.LOADING")
19 ], ephemeral: true, fetchReply: true});
20 let config = await client.database.guilds.read(interaction.guild.id);
21 if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new EmojiEmbed()
22 .setTitle("Verify")
23 .setDescription(`Verify is not enabled on this server`)
24 .setStatus("Danger")
25 .setEmoji("CONTROL.BLOCKCROSS")
26 ], ephemeral: true, fetchReply: true});
27 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
28 return await interaction.editReply({embeds: [new EmojiEmbed()
29 .setTitle("Verify")
30 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
31 .setStatus("Danger")
32 .setEmoji("CONTROL.BLOCKCROSS")
33 ]});
34 }
35 await interaction.editReply({embeds: [new EmojiEmbed()
36 .setTitle("Verify")
37 .setDescription(`Checking our servers are up` + step(0))
38 .setStatus("Warning")
39 .setEmoji("NUCLEUS.LOADING")
40 ]});
41 try {
42 let status = await fetch(client.config.baseUrl).then(res => res.status);
43 if (status != 200) {
44 return await interaction.editReply({embeds: [new EmojiEmbed()
45 .setTitle("Verify")
46 .setDescription(`Our servers appear to be down, please try again later` + step(0))
47 .setStatus("Danger")
48 .setEmoji("CONTROL.BLOCKCROSS")
49 ]});
50 }
51 } catch {
52 return await interaction.editReply({embeds: [new EmojiEmbed()
53 .setTitle("Verify")
54 .setDescription(`Our servers appear to be down, please try again later` + step(0))
55 .setStatus("Danger")
56 .setEmoji("CONTROL.BLOCKCROSS")
57 ], components: [new Discord.MessageActionRow().addComponents([
58 new Discord.MessageButton()
59 .setLabel("Check webpage")
60 .setStyle("LINK")
61 .setURL(client.config.baseUrl),
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 EmojiEmbed()
70 .setTitle("Verify")
71 .setDescription(`Checking your avatar is safe for work` + step(1))
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 EmojiEmbed()
77 .setTitle("Verify")
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))
79 .setStatus("Danger")
80 .setEmoji("CONTROL.BLOCKCROSS")
81 ]});
82 }
83 }
84 if (config.filters.wordFilter) {
85 await interaction.editReply({embeds: [new EmojiEmbed()
86 .setTitle("Verify")
87 .setDescription(`Checking your name is allowed` + step(2))
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) !== null) {
92 return await interaction.editReply({embeds: [new EmojiEmbed()
93 .setTitle("Verify")
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))
95 .setStatus("Danger")
96 .setEmoji("CONTROL.BLOCKCROSS")
97 ]});
98 }
99 }
100 await interaction.editReply({embeds: [new EmojiEmbed()
101 .setTitle("Verify")
102 .setDescription(`One moment...` + step(3))
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,
125 rID: config.verify.role,
126 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
127 uName: interaction.member.user.username,
128 gName: interaction.guild.name,
129 gIcon: interaction.guild.iconURL({format: "png"}),
130 interaction: interaction
131 }
132 await interaction.editReply({embeds: [new EmojiEmbed()
133 .setTitle("Verify")
134 .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
135 .setStatus("Success")
136 .setEmoji("MEMBER.JOIN")
137 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
138 .setLabel("Verify")
139 .setStyle("LINK")
140 .setURL(`${client.config.baseUrl}/nucleus/verify?code=${code}`)
141 ])]});
142}