blob: d9fab66d6aa3c3b66f8a2da07854f4fa2bdd8b43 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +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) {
pineafan63fc5e22022-08-04 22:04:10 +010014 const verify = client.verify;
pineafane23c4ec2022-07-27 21:56:27 +010015 await interaction.reply({embeds: LoadingEmbed, ephemeral: true, fetchReply: true});
pineafan63fc5e22022-08-04 22:04:10 +010016 const config = await client.database.guilds.read(interaction.guild.id);
pineafan813bdf42022-07-24 10:39:10 +010017 if ((!config.verify.enabled ) || (!config.verify.role)) return interaction.editReply({embeds: [new EmojiEmbed()
18 .setTitle("Verify")
pineafan63fc5e22022-08-04 22:04:10 +010019 .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")
pineafan63fc5e22022-08-04 22:04:10 +010034 .setDescription("Checking our servers are up" + step(0))
pineafan813bdf42022-07-24 10:39:10 +010035 .setStatus("Warning")
36 .setEmoji("NUCLEUS.LOADING")
37 ]});
38 try {
pineafan63fc5e22022-08-04 22:04:10 +010039 const 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")
pineafan63fc5e22022-08-04 22:04:10 +010043 .setDescription("Our servers appear to be down, please try again later" + step(0))
pineafan813bdf42022-07-24 10:39:10 +010044 .setStatus("Danger")
45 .setEmoji("CONTROL.BLOCKCROSS")
46 ]});
47 }
48 } catch {
49 return await interaction.editReply({embeds: [new EmojiEmbed()
50 .setTitle("Verify")
pineafan63fc5e22022-08-04 22:04:10 +010051 .setDescription("Our servers appear to be down, please try again later" + step(0))
pineafan813bdf42022-07-24 10:39:10 +010052 .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")
pineafan63fc5e22022-08-04 22:04:10 +010068 .setDescription("Checking your avatar is safe for work" + step(1))
pineafan813bdf42022-07-24 10:39:10 +010069 .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")
pineafan63fc5e22022-08-04 22:04:10 +010075 .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))
pineafan813bdf42022-07-24 10:39:10 +010076 .setStatus("Danger")
77 .setEmoji("CONTROL.BLOCKCROSS")
78 ]});
79 }
80 }
81 if (config.filters.wordFilter) {
82 await interaction.editReply({embeds: [new EmojiEmbed()
83 .setTitle("Verify")
pineafan63fc5e22022-08-04 22:04:10 +010084 .setDescription("Checking your name is allowed" + step(2))
pineafan813bdf42022-07-24 10:39:10 +010085 .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")
pineafan63fc5e22022-08-04 22:04:10 +010091 .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))
pineafan813bdf42022-07-24 10:39:10 +010092 .setStatus("Danger")
93 .setEmoji("CONTROL.BLOCKCROSS")
94 ]});
95 }
96 }
97 await interaction.editReply({embeds: [new EmojiEmbed()
98 .setTitle("Verify")
pineafan63fc5e22022-08-04 22:04:10 +010099 .setDescription("One moment..." + step(3))
pineafan813bdf42022-07-24 10:39:10 +0100100 .setStatus("Warning")
101 .setEmoji("NUCLEUS.LOADING")
102 ]});
pineafan63fc5e22022-08-04 22:04:10 +0100103 let code = "";
104 let length = 5;
105 let itt = 0;
pineafan813bdf42022-07-24 10:39:10 +0100106 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
107 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100108 itt += 1;
109 code = "";
pineafan813bdf42022-07-24 10:39:10 +0100110 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) {
pineafan63fc5e22022-08-04 22:04:10 +0100113 itt = 0;
114 length += 1;
115 continue;
pineafan813bdf42022-07-24 10:39:10 +0100116 }
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
pineafan63fc5e22022-08-04 22:04:10 +0100128 };
pineafan813bdf42022-07-24 10:39:10 +0100129 await interaction.editReply({embeds: [new EmojiEmbed()
130 .setTitle("Verify")
pineafan63fc5e22022-08-04 22:04:10 +0100131 .setDescription("Looking good!\nClick the button below to get verified" + step(4))
pineafan813bdf42022-07-24 10:39:10 +0100132 .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}