blob: bc7aa4fec101195047d6683d22a0bcf46788b4b9 [file] [log] [blame]
pineafane23c4ec2022-07-27 21:56:27 +01001import { LoadingEmbed } from './../utils/defaultEmbeds.js';
pineafan813bdf42022-07-24 10:39:10 +01002import Discord, { GuildMember } from "discord.js";
3import EmojiEmbed from "../utils/generateEmojiEmbed.js";
4import fetch from "node-fetch";
5import { TestString, NSFWCheck } from "./scanners.js";
6import createPageIndicator from "../utils/createPageIndicator.js";
7import client from "../utils/client.js";
8
9function step(i) {
10 return "\n\n" + createPageIndicator(5, i);
11}
12
13export default async function(interaction) {
14 let verify = client.verify
pineafane23c4ec2022-07-27 21:56:27 +010015 await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true});
pineafan813bdf42022-07-24 10:39:10 +010016 let config = await client.database.guilds.read(interaction.guild.id);
17 if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new EmojiEmbed()
18 .setTitle("Verify")
19 .setDescription(`Verify is not enabled on this server`)
pineafan41d93562022-07-30 22:10:15 +010020 .setFooter({text: interaction.member.permissions.has("MANAGE_GUILD") ? "You can enable it by running /settings verify" : ""})
pineafan813bdf42022-07-24 10:39:10 +010021 .setStatus("Danger")
22 .setEmoji("CONTROL.BLOCKCROSS")
23 ], ephemeral: true, fetchReply: true});
24 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
25 return await interaction.editReply({embeds: [new EmojiEmbed()
26 .setTitle("Verify")
27 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
28 .setStatus("Danger")
29 .setEmoji("CONTROL.BLOCKCROSS")
30 ]});
31 }
32 await interaction.editReply({embeds: [new EmojiEmbed()
33 .setTitle("Verify")
34 .setDescription(`Checking our servers are up` + step(0))
35 .setStatus("Warning")
36 .setEmoji("NUCLEUS.LOADING")
37 ]});
38 try {
39 let status = await fetch(client.config.baseUrl).then(res => res.status);
pineafane23c4ec2022-07-27 21:56:27 +010040 if (status !== 200) {
pineafan813bdf42022-07-24 10:39:10 +010041 return await interaction.editReply({embeds: [new EmojiEmbed()
42 .setTitle("Verify")
43 .setDescription(`Our servers appear to be down, please try again later` + step(0))
44 .setStatus("Danger")
45 .setEmoji("CONTROL.BLOCKCROSS")
46 ]});
47 }
48 } catch {
49 return await interaction.editReply({embeds: [new EmojiEmbed()
50 .setTitle("Verify")
51 .setDescription(`Our servers appear to be down, please try again later` + step(0))
52 .setStatus("Danger")
53 .setEmoji("CONTROL.BLOCKCROSS")
54 ], components: [new Discord.MessageActionRow().addComponents([
55 new Discord.MessageButton()
56 .setLabel("Check webpage")
57 .setStyle("LINK")
58 .setURL(client.config.baseUrl),
59 new Discord.MessageButton()
60 .setLabel("Support")
61 .setStyle("LINK")
62 .setURL("https://discord.gg/bPaNnxe")
63 ])]});
64 }
65 if (config.filters.images.NSFW) {
66 await interaction.editReply({embeds: [new EmojiEmbed()
67 .setTitle("Verify")
68 .setDescription(`Checking your avatar is safe for work` + step(1))
69 .setStatus("Warning")
70 .setEmoji("NUCLEUS.LOADING")
71 ]});
72 if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) {
73 return await interaction.editReply({embeds: [new EmojiEmbed()
74 .setTitle("Verify")
75 .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))
76 .setStatus("Danger")
77 .setEmoji("CONTROL.BLOCKCROSS")
78 ]});
79 }
80 }
81 if (config.filters.wordFilter) {
82 await interaction.editReply({embeds: [new EmojiEmbed()
83 .setTitle("Verify")
84 .setDescription(`Checking your name is allowed` + step(2))
85 .setStatus("Warning")
86 .setEmoji("NUCLEUS.LOADING")
87 ]});
88 if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) !== null) {
89 return await interaction.editReply({embeds: [new EmojiEmbed()
90 .setTitle("Verify")
91 .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))
92 .setStatus("Danger")
93 .setEmoji("CONTROL.BLOCKCROSS")
94 ]});
95 }
96 }
97 await interaction.editReply({embeds: [new EmojiEmbed()
98 .setTitle("Verify")
99 .setDescription(`One moment...` + step(3))
100 .setStatus("Warning")
101 .setEmoji("NUCLEUS.LOADING")
102 ]});
103 let code = ""
104 let length = 5
105 let itt = 0
106 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
107 while (true) {
108 itt += 1
109 code = ""
110 for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
111 if (code in verify) continue;
112 if (itt > 1000) {
113 itt = 0
114 length += 1
115 continue
116 }
117 break;
118 }
119 verify[code] = {
120 uID: interaction.member.user.id,
121 gID: interaction.guild.id,
122 rID: config.verify.role,
123 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
124 uName: interaction.member.user.username,
125 gName: interaction.guild.name,
126 gIcon: interaction.guild.iconURL({format: "png"}),
127 interaction: interaction
128 }
129 await interaction.editReply({embeds: [new EmojiEmbed()
130 .setTitle("Verify")
131 .setDescription(`Looking good!\nClick the button below to get verified` + step(4))
132 .setStatus("Success")
133 .setEmoji("MEMBER.JOIN")
134 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
135 .setLabel("Verify")
136 .setStyle("LINK")
pineafan6d537412022-07-28 12:35:33 +0100137 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
pineafan813bdf42022-07-24 10:39:10 +0100138 ])]});
139}