blob: 1737387259379784aca760672108dc6176ee5caa [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
Skyler Grey75ea9172022-08-06 10:22:23 +01002import Discord, { CommandInteraction, GuildMember } 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 Grey75ea9172022-08-06 10:22:23 +01009function step(i: number) {
pineafan813bdf42022-07-24 10:39:10 +010010 return "\n\n" + createPageIndicator(5, i);
11}
12
Skyler Grey75ea9172022-08-06 10:22:23 +010013export default async function (interaction: CommandInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +010014 const verify = client.verify;
Skyler Grey75ea9172022-08-06 10:22:23 +010015 await interaction.reply({
16 embeds: LoadingEmbed,
17 ephemeral: true,
18 fetchReply: true
19 });
pineafan63fc5e22022-08-04 22:04:10 +010020 const config = await client.database.guilds.read(interaction.guild.id);
Skyler Grey75ea9172022-08-06 10:22:23 +010021 if (!config.verify.enabled || !config.verify.role)
22 return interaction.editReply({
23 embeds: [
24 new EmojiEmbed()
25 .setTitle("Verify")
26 .setDescription("Verify is not enabled on this server")
27 .setFooter({
28 text: interaction.member.permissions.has("MANAGE_GUILD")
29 ? "You can enable it by running /settings verify"
30 : ""
31 })
32 .setStatus("Danger")
33 .setEmoji("CONTROL.BLOCKCROSS")
34 ],
35 ephemeral: true,
36 fetchReply: true
37 });
38 if (
39 (interaction.member as GuildMember).roles.cache.has(config.verify.role)
40 ) {
41 return await interaction.editReply({
42 embeds: [
43 new EmojiEmbed()
44 .setTitle("Verify")
45 .setDescription(
46 `You already have the <@&${config.verify.role}> role` +
47 step(0)
48 )
49 .setStatus("Danger")
50 .setEmoji("CONTROL.BLOCKCROSS")
51 ]
52 });
pineafan813bdf42022-07-24 10:39:10 +010053 }
Skyler Grey75ea9172022-08-06 10:22:23 +010054 await interaction.editReply({
55 embeds: [
56 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010057 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010058 .setDescription("Checking our servers are up" + step(0))
59 .setStatus("Warning")
60 .setEmoji("NUCLEUS.LOADING")
61 ]
62 });
63 try {
64 const status = await fetch(client.config.baseUrl).then(
65 (res) => res.status
66 );
67 if (status !== 200) {
68 return await interaction.editReply({
69 embeds: [
70 new EmojiEmbed()
71 .setTitle("Verify")
72 .setDescription(
73 "Our servers appear to be down, please try again later" +
74 step(0)
75 )
76 .setStatus("Danger")
77 .setEmoji("CONTROL.BLOCKCROSS")
78 ]
79 });
pineafan813bdf42022-07-24 10:39:10 +010080 }
81 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010082 return await interaction.editReply({
83 embeds: [
84 new EmojiEmbed()
85 .setTitle("Verify")
86 .setDescription(
87 "Our servers appear to be down, please try again later" +
88 step(0)
89 )
90 .setStatus("Danger")
91 .setEmoji("CONTROL.BLOCKCROSS")
92 ],
93 components: [
94 new Discord.MessageActionRow().addComponents([
95 new Discord.MessageButton()
96 .setLabel("Check webpage")
97 .setStyle("LINK")
98 .setURL(client.config.baseUrl),
99 new Discord.MessageButton()
100 .setLabel("Support")
101 .setStyle("LINK")
102 .setURL("https://discord.gg/bPaNnxe")
103 ])
104 ]
105 });
pineafan813bdf42022-07-24 10:39:10 +0100106 }
107 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100108 await interaction.editReply({
109 embeds: [
110 new EmojiEmbed()
111 .setTitle("Verify")
112 .setDescription(
113 "Checking your avatar is safe for work" + step(1)
114 )
115 .setStatus("Warning")
116 .setEmoji("NUCLEUS.LOADING")
117 ]
118 });
119 if (
120 await NSFWCheck(
121 (interaction.member as GuildMember).user.avatarURL({
122 format: "png"
123 })
124 )
125 ) {
126 return await interaction.editReply({
127 embeds: [
128 new EmojiEmbed()
129 .setTitle("Verify")
130 .setDescription(
131 "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" +
132 step(1)
133 )
134 .setStatus("Danger")
135 .setEmoji("CONTROL.BLOCKCROSS")
136 ]
137 });
pineafan813bdf42022-07-24 10:39:10 +0100138 }
139 }
140 if (config.filters.wordFilter) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100141 await interaction.editReply({
142 embeds: [
143 new EmojiEmbed()
144 .setTitle("Verify")
145 .setDescription("Checking your name is allowed" + step(2))
146 .setStatus("Warning")
147 .setEmoji("NUCLEUS.LOADING")
148 ]
149 });
150 if (
151 TestString(
152 (interaction.member as Discord.GuildMember).displayName,
153 config.filters.wordFilter.words.loose,
154 config.filters.wordFilter.words.strict
155 ) !== null
156 ) {
157 return await interaction.editReply({
158 embeds: [
159 new EmojiEmbed()
160 .setTitle("Verify")
161 .setDescription(
162 "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" +
163 step(2)
164 )
165 .setStatus("Danger")
166 .setEmoji("CONTROL.BLOCKCROSS")
167 ]
168 });
pineafan813bdf42022-07-24 10:39:10 +0100169 }
170 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100171 await interaction.editReply({
172 embeds: [
173 new EmojiEmbed()
174 .setTitle("Verify")
175 .setDescription("One moment..." + step(3))
176 .setStatus("Warning")
177 .setEmoji("NUCLEUS.LOADING")
178 ]
179 });
pineafan63fc5e22022-08-04 22:04:10 +0100180 let code = "";
181 let length = 5;
182 let itt = 0;
Skyler Grey75ea9172022-08-06 10:22:23 +0100183 const chars =
184 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
pineafan813bdf42022-07-24 10:39:10 +0100185 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100186 itt += 1;
187 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100188 for (let i = 0; i < length; i++) {
189 code += chars.charAt(Math.floor(Math.random() * chars.length));
190 }
pineafan813bdf42022-07-24 10:39:10 +0100191 if (code in verify) continue;
192 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100193 itt = 0;
194 length += 1;
195 continue;
pineafan813bdf42022-07-24 10:39:10 +0100196 }
197 break;
198 }
199 verify[code] = {
200 uID: interaction.member.user.id,
201 gID: interaction.guild.id,
202 rID: config.verify.role,
203 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
204 uName: interaction.member.user.username,
205 gName: interaction.guild.name,
Skyler Grey75ea9172022-08-06 10:22:23 +0100206 gIcon: interaction.guild.iconURL({ format: "png" }),
pineafan813bdf42022-07-24 10:39:10 +0100207 interaction: interaction
pineafan63fc5e22022-08-04 22:04:10 +0100208 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100209 await interaction.editReply({
210 embeds: [
211 new EmojiEmbed()
212 .setTitle("Verify")
213 .setDescription(
214 "Looking good!\nClick the button below to get verified" +
215 step(4)
216 )
217 .setStatus("Success")
218 .setEmoji("MEMBER.JOIN")
219 ],
220 components: [
221 new Discord.MessageActionRow().addComponents([
222 new Discord.MessageButton()
223 .setLabel("Verify")
224 .setStyle("LINK")
225 .setURL(
226 `${client.config.baseUrl}nucleus/verify?code=${code}`
227 )
228 ])
229 ]
230 });
pineafan813bdf42022-07-24 10:39:10 +0100231}