blob: c366c8b0454c281b73e421ebb5435859a0aa0f4d [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
Skyler Grey11236ba2022-08-08 21:13:33 +01002import Discord, { CommandInteraction, GuildMember, Interaction } from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +01003import 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
Skyler Grey11236ba2022-08-08 21:13:33 +01009export interface VerifySchema {
10 uID: string;
11 gID: string;
12 rID: string;
13 rName: string;
14 uName: string;
15 gName: string;
16 gIcon: string;
17 interaction: Interaction;
18}
19
Skyler Grey75ea9172022-08-06 10:22:23 +010020function step(i: number) {
pineafan813bdf42022-07-24 10:39:10 +010021 return "\n\n" + createPageIndicator(5, i);
22}
23
Skyler Grey75ea9172022-08-06 10:22:23 +010024export default async function (interaction: CommandInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +010025 const verify = client.verify;
Skyler Grey75ea9172022-08-06 10:22:23 +010026 await interaction.reply({
27 embeds: LoadingEmbed,
28 ephemeral: true,
29 fetchReply: true
30 });
pineafan63fc5e22022-08-04 22:04:10 +010031 const config = await client.database.guilds.read(interaction.guild.id);
Skyler Grey75ea9172022-08-06 10:22:23 +010032 if (!config.verify.enabled || !config.verify.role)
33 return interaction.editReply({
34 embeds: [
35 new EmojiEmbed()
36 .setTitle("Verify")
37 .setDescription("Verify is not enabled on this server")
38 .setFooter({
39 text: interaction.member.permissions.has("MANAGE_GUILD")
40 ? "You can enable it by running /settings verify"
41 : ""
42 })
43 .setStatus("Danger")
44 .setEmoji("CONTROL.BLOCKCROSS")
45 ],
46 ephemeral: true,
47 fetchReply: true
48 });
Skyler Grey11236ba2022-08-08 21:13:33 +010049 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010050 return await interaction.editReply({
51 embeds: [
52 new EmojiEmbed()
53 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010054 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010055 .setStatus("Danger")
56 .setEmoji("CONTROL.BLOCKCROSS")
57 ]
58 });
pineafan813bdf42022-07-24 10:39:10 +010059 }
Skyler Grey75ea9172022-08-06 10:22:23 +010060 await interaction.editReply({
61 embeds: [
62 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010063 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010064 .setDescription("Checking our servers are up" + step(0))
65 .setStatus("Warning")
66 .setEmoji("NUCLEUS.LOADING")
67 ]
68 });
69 try {
Skyler Grey11236ba2022-08-08 21:13:33 +010070 const status = await fetch(client.config.baseUrl).then((res) => res.status);
Skyler Grey75ea9172022-08-06 10:22:23 +010071 if (status !== 200) {
72 return await interaction.editReply({
73 embeds: [
74 new EmojiEmbed()
75 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010076 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010077 .setStatus("Danger")
78 .setEmoji("CONTROL.BLOCKCROSS")
79 ]
80 });
pineafan813bdf42022-07-24 10:39:10 +010081 }
82 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010083 return await interaction.editReply({
84 embeds: [
85 new EmojiEmbed()
86 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010087 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010088 .setStatus("Danger")
89 .setEmoji("CONTROL.BLOCKCROSS")
90 ],
91 components: [
92 new Discord.MessageActionRow().addComponents([
93 new Discord.MessageButton()
94 .setLabel("Check webpage")
95 .setStyle("LINK")
96 .setURL(client.config.baseUrl),
97 new Discord.MessageButton()
98 .setLabel("Support")
99 .setStyle("LINK")
100 .setURL("https://discord.gg/bPaNnxe")
101 ])
102 ]
103 });
pineafan813bdf42022-07-24 10:39:10 +0100104 }
105 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 await interaction.editReply({
107 embeds: [
108 new EmojiEmbed()
109 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100110 .setDescription("Checking your avatar is safe for work" + step(1))
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 .setStatus("Warning")
112 .setEmoji("NUCLEUS.LOADING")
113 ]
114 });
115 if (
116 await NSFWCheck(
117 (interaction.member as GuildMember).user.avatarURL({
118 format: "png"
119 })
120 )
121 ) {
122 return await interaction.editReply({
123 embeds: [
124 new EmojiEmbed()
125 .setTitle("Verify")
126 .setDescription(
127 "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" +
128 step(1)
129 )
130 .setStatus("Danger")
131 .setEmoji("CONTROL.BLOCKCROSS")
132 ]
133 });
pineafan813bdf42022-07-24 10:39:10 +0100134 }
135 }
136 if (config.filters.wordFilter) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100137 await interaction.editReply({
138 embeds: [
139 new EmojiEmbed()
140 .setTitle("Verify")
141 .setDescription("Checking your name is allowed" + step(2))
142 .setStatus("Warning")
143 .setEmoji("NUCLEUS.LOADING")
144 ]
145 });
146 if (
147 TestString(
148 (interaction.member as Discord.GuildMember).displayName,
149 config.filters.wordFilter.words.loose,
150 config.filters.wordFilter.words.strict
151 ) !== null
152 ) {
153 return await interaction.editReply({
154 embeds: [
155 new EmojiEmbed()
156 .setTitle("Verify")
157 .setDescription(
158 "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" +
159 step(2)
160 )
161 .setStatus("Danger")
162 .setEmoji("CONTROL.BLOCKCROSS")
163 ]
164 });
pineafan813bdf42022-07-24 10:39:10 +0100165 }
166 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100167 await interaction.editReply({
168 embeds: [
169 new EmojiEmbed()
170 .setTitle("Verify")
171 .setDescription("One moment..." + step(3))
172 .setStatus("Warning")
173 .setEmoji("NUCLEUS.LOADING")
174 ]
175 });
pineafan63fc5e22022-08-04 22:04:10 +0100176 let code = "";
177 let length = 5;
178 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100179 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
pineafan813bdf42022-07-24 10:39:10 +0100180 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100181 itt += 1;
182 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100183 for (let i = 0; i < length; i++) {
184 code += chars.charAt(Math.floor(Math.random() * chars.length));
185 }
pineafan813bdf42022-07-24 10:39:10 +0100186 if (code in verify) continue;
187 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100188 itt = 0;
189 length += 1;
190 continue;
pineafan813bdf42022-07-24 10:39:10 +0100191 }
192 break;
193 }
194 verify[code] = {
195 uID: interaction.member.user.id,
196 gID: interaction.guild.id,
197 rID: config.verify.role,
198 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
199 uName: interaction.member.user.username,
200 gName: interaction.guild.name,
Skyler Grey75ea9172022-08-06 10:22:23 +0100201 gIcon: interaction.guild.iconURL({ format: "png" }),
pineafan813bdf42022-07-24 10:39:10 +0100202 interaction: interaction
pineafan63fc5e22022-08-04 22:04:10 +0100203 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100204 await interaction.editReply({
205 embeds: [
206 new EmojiEmbed()
207 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100208 .setDescription("Looking good!\nClick the button below to get verified" + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100209 .setStatus("Success")
210 .setEmoji("MEMBER.JOIN")
211 ],
212 components: [
213 new Discord.MessageActionRow().addComponents([
214 new Discord.MessageButton()
215 .setLabel("Verify")
216 .setStyle("LINK")
Skyler Grey11236ba2022-08-08 21:13:33 +0100217 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 ])
219 ]
220 });
pineafan813bdf42022-07-24 10:39:10 +0100221}