blob: bf265059fd497fad6f26111d54a4314f558a3513 [file] [log] [blame]
pineafan6702cef2022-06-13 17:52:37 +01001import Discord, { GuildMember } from "discord.js";
pineafanad54d752022-04-18 19:01:43 +01002import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
pineafanad54d752022-04-18 19:01:43 +01003import fetch from "node-fetch";
4import { TestString, NSFWCheck } from "../automations/unscan.js";
pineafan34369e62022-05-18 16:52:37 +01005import createPageIndicator from "../utils/createPageIndicator.js";
pineafan6702cef2022-06-13 17:52:37 +01006import client from "../utils/client.js";
pineafan34369e62022-05-18 16:52:37 +01007
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});
pineafan6702cef2022-06-13 17:52:37 +010021 let config = await client.database.read(interaction.guild.id);
22 if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new generateEmojiEmbed()
23 .setTitle("Verify")
24 .setDescription(`Verify is not enabled on this server`)
25 .setStatus("Danger")
26 .setEmoji("CONTROL.BLOCKCROSS")
27 ], ephemeral: true, fetchReply: true});
pineafanad54d752022-04-18 19:01:43 +010028 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
29 return await interaction.editReply({embeds: [new generateEmojiEmbed()
30 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010031 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
pineafanad54d752022-04-18 19:01:43 +010032 .setStatus("Danger")
33 .setEmoji("CONTROL.BLOCKCROSS")
34 ]});
35 }
36 await interaction.editReply({embeds: [new generateEmojiEmbed()
37 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010038 .setDescription(`Checking our servers are up` + step(0))
pineafanad54d752022-04-18 19:01:43 +010039 .setStatus("Warning")
40 .setEmoji("NUCLEUS.LOADING")
41 ]});
42 try {
pineafan6702cef2022-06-13 17:52:37 +010043 let status = await fetch(client.config.baseUrl).then(res => res.status);
pineafanad54d752022-04-18 19:01:43 +010044 if (status != 200) {
45 return await interaction.editReply({embeds: [new generateEmojiEmbed()
46 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010047 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010048 .setStatus("Danger")
49 .setEmoji("CONTROL.BLOCKCROSS")
50 ]});
51 }
52 } catch {
53 return await interaction.editReply({embeds: [new generateEmojiEmbed()
54 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010055 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010056 .setStatus("Danger")
57 .setEmoji("CONTROL.BLOCKCROSS")
58 ], components: [new Discord.MessageActionRow().addComponents([
59 new Discord.MessageButton()
pineafane625d782022-05-09 18:04:32 +010060 .setLabel("Check webpage")
pineafanad54d752022-04-18 19:01:43 +010061 .setStyle("LINK")
pineafan6702cef2022-06-13 17:52:37 +010062 .setURL(client.config.baseUrl),
pineafanad54d752022-04-18 19:01:43 +010063 new Discord.MessageButton()
64 .setLabel("Support")
65 .setStyle("LINK")
66 .setURL("https://discord.gg/bPaNnxe")
67 ])]});
68 }
69 if (config.filters.images.NSFW) {
70 await interaction.editReply({embeds: [new generateEmojiEmbed()
71 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010072 .setDescription(`Checking your avatar is safe for work` + step(1))
pineafanad54d752022-04-18 19:01:43 +010073 .setStatus("Warning")
74 .setEmoji("NUCLEUS.LOADING")
75 ]});
76 if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) {
77 return await interaction.editReply({embeds: [new generateEmojiEmbed()
78 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010079 .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 +010080 .setStatus("Danger")
81 .setEmoji("CONTROL.BLOCKCROSS")
82 ]});
83 }
84 }
85 if (config.filters.wordFilter) {
86 await interaction.editReply({embeds: [new generateEmojiEmbed()
87 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010088 .setDescription(`Checking your name is allowed` + step(2))
pineafanad54d752022-04-18 19:01:43 +010089 .setStatus("Warning")
90 .setEmoji("NUCLEUS.LOADING")
91 ]});
92 if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) != "none") {
93 return await interaction.editReply({embeds: [new generateEmojiEmbed()
94 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010095 .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 +010096 .setStatus("Danger")
97 .setEmoji("CONTROL.BLOCKCROSS")
98 ]});
99 }
100 }
101 await interaction.editReply({embeds: [new generateEmojiEmbed()
102 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +0100103 .setDescription(`One moment...` + step(3))
pineafanad54d752022-04-18 19:01:43 +0100104 .setStatus("Warning")
105 .setEmoji("NUCLEUS.LOADING")
106 ]});
107 let code = ""
108 let length = 5
109 let itt = 0
110 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
111 while (true) {
112 itt += 1
113 code = ""
114 for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
115 if (code in verify) continue;
116 if (itt > 1000) {
117 itt = 0
118 length += 1
119 continue
120 }
121 break;
122 }
123 verify[code] = {
124 uID: interaction.member.user.id,
125 gID: interaction.guild.id,
pineafane625d782022-05-09 18:04:32 +0100126 rID: config.verify.role,
pineafanad54d752022-04-18 19:01:43 +0100127 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
128 mCount: interaction.guild.memberCount,
129 gName: interaction.guild.name,
pineafane625d782022-05-09 18:04:32 +0100130 gIcon: interaction.guild.iconURL({format: "png"}),
131 interaction: interaction
pineafanad54d752022-04-18 19:01:43 +0100132 }
133 await interaction.editReply({embeds: [new generateEmojiEmbed()
134 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +0100135 .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
pineafanad54d752022-04-18 19:01:43 +0100136 .setStatus("Success")
137 .setEmoji("MEMBER.JOIN")
138 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
139 .setLabel("Verify")
140 .setStyle("LINK")
pineafan6702cef2022-06-13 17:52:37 +0100141 .setURL(`${client.config.baseUrl}/nucleus/verify?code=${code}`)
pineafanad54d752022-04-18 19:01:43 +0100142 ])]});
pineafane625d782022-05-09 18:04:32 +0100143}