blob: 37f8d6cb260ae865156c104403be1657c5dd34ec [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
pineafan3a02ea32022-08-11 21:35:04 +01002import Discord, { CommandInteraction, GuildMember, Interaction, Permissions, Role } 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 });
pineafan3a02ea32022-08-11 21:35:04 +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({
pineafan3a02ea32022-08-11 21:35:04 +010039 text: (interaction.member!.permissions as Permissions).has("MANAGE_GUILD")
Skyler Grey75ea9172022-08-06 10:22:23 +010040 ? "You can enable it by running /settings verify"
41 : ""
42 })
43 .setStatus("Danger")
44 .setEmoji("CONTROL.BLOCKCROSS")
pineafan3a02ea32022-08-11 21:35:04 +010045 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010046 });
Skyler Grey11236ba2022-08-08 21:13:33 +010047 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010048 return await interaction.editReply({
49 embeds: [
50 new EmojiEmbed()
51 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010052 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010053 .setStatus("Danger")
54 .setEmoji("CONTROL.BLOCKCROSS")
55 ]
56 });
pineafan813bdf42022-07-24 10:39:10 +010057 }
Skyler Grey75ea9172022-08-06 10:22:23 +010058 await interaction.editReply({
59 embeds: [
60 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010061 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010062 .setDescription("Checking our servers are up" + step(0))
63 .setStatus("Warning")
64 .setEmoji("NUCLEUS.LOADING")
65 ]
66 });
67 try {
Skyler Grey11236ba2022-08-08 21:13:33 +010068 const status = await fetch(client.config.baseUrl).then((res) => res.status);
Skyler Grey75ea9172022-08-06 10:22:23 +010069 if (status !== 200) {
70 return await interaction.editReply({
71 embeds: [
72 new EmojiEmbed()
73 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010074 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010075 .setStatus("Danger")
76 .setEmoji("CONTROL.BLOCKCROSS")
77 ]
78 });
pineafan813bdf42022-07-24 10:39:10 +010079 }
80 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010081 return await interaction.editReply({
82 embeds: [
83 new EmojiEmbed()
84 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010085 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010086 .setStatus("Danger")
87 .setEmoji("CONTROL.BLOCKCROSS")
88 ],
89 components: [
90 new Discord.MessageActionRow().addComponents([
91 new Discord.MessageButton()
92 .setLabel("Check webpage")
93 .setStyle("LINK")
94 .setURL(client.config.baseUrl),
95 new Discord.MessageButton()
96 .setLabel("Support")
97 .setStyle("LINK")
98 .setURL("https://discord.gg/bPaNnxe")
99 ])
100 ]
101 });
pineafan813bdf42022-07-24 10:39:10 +0100102 }
103 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100104 await interaction.editReply({
105 embeds: [
106 new EmojiEmbed()
107 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100108 .setDescription("Checking your avatar is safe for work" + step(1))
Skyler Grey75ea9172022-08-06 10:22:23 +0100109 .setStatus("Warning")
110 .setEmoji("NUCLEUS.LOADING")
111 ]
112 });
113 if (
114 await NSFWCheck(
pineafan3a02ea32022-08-11 21:35:04 +0100115 (interaction.member as GuildMember).user.displayAvatarURL({
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 format: "png"
117 })
118 )
119 ) {
120 return await interaction.editReply({
121 embeds: [
122 new EmojiEmbed()
123 .setTitle("Verify")
124 .setDescription(
125 "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" +
126 step(1)
127 )
128 .setStatus("Danger")
129 .setEmoji("CONTROL.BLOCKCROSS")
130 ]
131 });
pineafan813bdf42022-07-24 10:39:10 +0100132 }
133 }
134 if (config.filters.wordFilter) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100135 await interaction.editReply({
136 embeds: [
137 new EmojiEmbed()
138 .setTitle("Verify")
139 .setDescription("Checking your name is allowed" + step(2))
140 .setStatus("Warning")
141 .setEmoji("NUCLEUS.LOADING")
142 ]
143 });
144 if (
145 TestString(
146 (interaction.member as Discord.GuildMember).displayName,
147 config.filters.wordFilter.words.loose,
148 config.filters.wordFilter.words.strict
149 ) !== null
150 ) {
151 return await interaction.editReply({
152 embeds: [
153 new EmojiEmbed()
154 .setTitle("Verify")
155 .setDescription(
156 "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" +
157 step(2)
158 )
159 .setStatus("Danger")
160 .setEmoji("CONTROL.BLOCKCROSS")
161 ]
162 });
pineafan813bdf42022-07-24 10:39:10 +0100163 }
164 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100165 await interaction.editReply({
166 embeds: [
167 new EmojiEmbed()
168 .setTitle("Verify")
169 .setDescription("One moment..." + step(3))
170 .setStatus("Warning")
171 .setEmoji("NUCLEUS.LOADING")
172 ]
173 });
pineafan63fc5e22022-08-04 22:04:10 +0100174 let code = "";
175 let length = 5;
176 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100177 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
pineafan813bdf42022-07-24 10:39:10 +0100178 while (true) {
pineafan63fc5e22022-08-04 22:04:10 +0100179 itt += 1;
180 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100181 for (let i = 0; i < length; i++) {
182 code += chars.charAt(Math.floor(Math.random() * chars.length));
183 }
pineafan813bdf42022-07-24 10:39:10 +0100184 if (code in verify) continue;
185 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100186 itt = 0;
187 length += 1;
188 continue;
pineafan813bdf42022-07-24 10:39:10 +0100189 }
190 break;
191 }
pineafan3a02ea32022-08-11 21:35:04 +0100192 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
193 if (!role) {
194 await interaction.editReply({
195 embeds: [
196 new EmojiEmbed()
197 .setTitle("Verify")
198 .setDescription(
199 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
200 step(4)
201 )
202 .setStatus("Danger")
203 .setEmoji("CONTROL.BLOCKCROSS")
204 ]
205 });
206 return; // TODO: SEN
207 }
pineafan813bdf42022-07-24 10:39:10 +0100208 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100209 uID: interaction.member!.user.id,
210 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100211 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100212 rName: role.name,
213 uName: interaction.member!.user.username,
214 gName: interaction.guild!.name,
215 gIcon: interaction.guild!.iconURL({ format: "png" }),
pineafan813bdf42022-07-24 10:39:10 +0100216 interaction: interaction
pineafan63fc5e22022-08-04 22:04:10 +0100217 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100218 await interaction.editReply({
219 embeds: [
220 new EmojiEmbed()
221 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100222 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100223 .setStatus("Success")
224 .setEmoji("MEMBER.JOIN")
225 ],
226 components: [
227 new Discord.MessageActionRow().addComponents([
228 new Discord.MessageButton()
229 .setLabel("Verify")
230 .setStyle("LINK")
Skyler Grey11236ba2022-08-08 21:13:33 +0100231 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100232 ])
233 ]
234 });
pineafan813bdf42022-07-24 10:39:10 +0100235}