blob: f84ba20da0d8901cbb594e19bb7cf050f8692826 [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) {
PineappleFanb3dd83c2022-06-17 10:53:48 +010013 let verify = client.verify
pineafanad54d752022-04-18 19:01:43 +010014 await interaction.reply({embeds: [new generateEmojiEmbed()
15 .setTitle("Loading")
pineafan34369e62022-05-18 16:52:37 +010016 .setDescription(step(-1))
pineafanad54d752022-04-18 19:01:43 +010017 .setStatus("Danger")
18 .setEmoji("NUCLEUS.LOADING")
19 ], ephemeral: true, fetchReply: true});
pineafan6702cef2022-06-13 17:52:37 +010020 let config = await client.database.read(interaction.guild.id);
21 if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new generateEmojiEmbed()
22 .setTitle("Verify")
23 .setDescription(`Verify is not enabled on this server`)
24 .setStatus("Danger")
25 .setEmoji("CONTROL.BLOCKCROSS")
26 ], ephemeral: true, fetchReply: true});
pineafanad54d752022-04-18 19:01:43 +010027 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
28 return await interaction.editReply({embeds: [new generateEmojiEmbed()
29 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010030 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
pineafanad54d752022-04-18 19:01:43 +010031 .setStatus("Danger")
32 .setEmoji("CONTROL.BLOCKCROSS")
33 ]});
34 }
35 await interaction.editReply({embeds: [new generateEmojiEmbed()
36 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010037 .setDescription(`Checking our servers are up` + step(0))
pineafanad54d752022-04-18 19:01:43 +010038 .setStatus("Warning")
39 .setEmoji("NUCLEUS.LOADING")
40 ]});
41 try {
pineafan6702cef2022-06-13 17:52:37 +010042 let status = await fetch(client.config.baseUrl).then(res => res.status);
pineafanad54d752022-04-18 19:01:43 +010043 if (status != 200) {
44 return await interaction.editReply({embeds: [new generateEmojiEmbed()
45 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010046 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010047 .setStatus("Danger")
48 .setEmoji("CONTROL.BLOCKCROSS")
49 ]});
50 }
51 } catch {
52 return await interaction.editReply({embeds: [new generateEmojiEmbed()
53 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010054 .setDescription(`Our servers appear to be down, please try again later` + step(0))
pineafanad54d752022-04-18 19:01:43 +010055 .setStatus("Danger")
56 .setEmoji("CONTROL.BLOCKCROSS")
57 ], components: [new Discord.MessageActionRow().addComponents([
58 new Discord.MessageButton()
pineafane625d782022-05-09 18:04:32 +010059 .setLabel("Check webpage")
pineafanad54d752022-04-18 19:01:43 +010060 .setStyle("LINK")
pineafan6702cef2022-06-13 17:52:37 +010061 .setURL(client.config.baseUrl),
pineafanad54d752022-04-18 19:01:43 +010062 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 generateEmojiEmbed()
70 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010071 .setDescription(`Checking your avatar is safe for work` + step(1))
pineafanad54d752022-04-18 19:01:43 +010072 .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 generateEmojiEmbed()
77 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010078 .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 +010079 .setStatus("Danger")
80 .setEmoji("CONTROL.BLOCKCROSS")
81 ]});
82 }
83 }
84 if (config.filters.wordFilter) {
85 await interaction.editReply({embeds: [new generateEmojiEmbed()
86 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010087 .setDescription(`Checking your name is allowed` + step(2))
pineafanad54d752022-04-18 19:01:43 +010088 .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) != "none") {
92 return await interaction.editReply({embeds: [new generateEmojiEmbed()
93 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +010094 .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 +010095 .setStatus("Danger")
96 .setEmoji("CONTROL.BLOCKCROSS")
97 ]});
98 }
99 }
100 await interaction.editReply({embeds: [new generateEmojiEmbed()
101 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +0100102 .setDescription(`One moment...` + step(3))
pineafanad54d752022-04-18 19:01:43 +0100103 .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,
pineafane625d782022-05-09 18:04:32 +0100125 rID: config.verify.role,
pineafanad54d752022-04-18 19:01:43 +0100126 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
127 mCount: interaction.guild.memberCount,
128 gName: interaction.guild.name,
pineafane625d782022-05-09 18:04:32 +0100129 gIcon: interaction.guild.iconURL({format: "png"}),
130 interaction: interaction
pineafanad54d752022-04-18 19:01:43 +0100131 }
132 await interaction.editReply({embeds: [new generateEmojiEmbed()
133 .setTitle("Verify")
pineafan34369e62022-05-18 16:52:37 +0100134 .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
pineafanad54d752022-04-18 19:01:43 +0100135 .setStatus("Success")
136 .setEmoji("MEMBER.JOIN")
137 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
138 .setLabel("Verify")
139 .setStyle("LINK")
pineafan6702cef2022-06-13 17:52:37 +0100140 .setURL(`${client.config.baseUrl}/nucleus/verify?code=${code}`)
pineafanad54d752022-04-18 19:01:43 +0100141 ])]});
pineafane625d782022-05-09 18:04:32 +0100142}