blob: 8aba46db4e44df85b89b507ef705671985e27802 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001import { LoadingEmbed } from "./../utils/defaultEmbeds.js";
Skyler Greyf21323a2022-08-13 23:58:22 +01002import Discord, {
3 CommandInteraction,
4 GuildMember,
5 Interaction,
6 MessageComponentInteraction,
7 Permissions,
8 Role
9} from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +010010import EmojiEmbed from "../utils/generateEmojiEmbed.js";
11import fetch from "node-fetch";
12import { TestString, NSFWCheck } from "./scanners.js";
13import createPageIndicator from "../utils/createPageIndicator.js";
14import client from "../utils/client.js";
15
Skyler Grey11236ba2022-08-08 21:13:33 +010016export interface VerifySchema {
17 uID: string;
18 gID: string;
19 rID: string;
20 rName: string;
21 uName: string;
22 gName: string;
23 gIcon: string;
24 interaction: Interaction;
25}
26
Skyler Grey75ea9172022-08-06 10:22:23 +010027function step(i: number) {
pineafan813bdf42022-07-24 10:39:10 +010028 return "\n\n" + createPageIndicator(5, i);
29}
30
pineafan0f5cc782022-08-12 21:55:42 +010031export default async function (interaction: CommandInteraction | MessageComponentInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +010032 const verify = client.verify;
Skyler Grey75ea9172022-08-06 10:22:23 +010033 await interaction.reply({
34 embeds: LoadingEmbed,
35 ephemeral: true,
36 fetchReply: true
37 });
pineafan3a02ea32022-08-11 21:35:04 +010038 const config = await client.database.guilds.read(interaction.guild!.id);
Skyler Grey75ea9172022-08-06 10:22:23 +010039 if (!config.verify.enabled || !config.verify.role)
40 return interaction.editReply({
41 embeds: [
42 new EmojiEmbed()
43 .setTitle("Verify")
44 .setDescription("Verify is not enabled on this server")
45 .setFooter({
pineafan3a02ea32022-08-11 21:35:04 +010046 text: (interaction.member!.permissions as Permissions).has("MANAGE_GUILD")
Skyler Grey75ea9172022-08-06 10:22:23 +010047 ? "You can enable it by running /settings verify"
48 : ""
49 })
50 .setStatus("Danger")
51 .setEmoji("CONTROL.BLOCKCROSS")
pineafan3a02ea32022-08-11 21:35:04 +010052 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010053 });
Skyler Grey11236ba2022-08-08 21:13:33 +010054 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010055 return await interaction.editReply({
56 embeds: [
57 new EmojiEmbed()
58 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010059 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010060 .setStatus("Danger")
61 .setEmoji("CONTROL.BLOCKCROSS")
62 ]
63 });
pineafan813bdf42022-07-24 10:39:10 +010064 }
Skyler Grey75ea9172022-08-06 10:22:23 +010065 await interaction.editReply({
66 embeds: [
67 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010068 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010069 .setDescription("Checking our servers are up" + step(0))
70 .setStatus("Warning")
71 .setEmoji("NUCLEUS.LOADING")
72 ]
73 });
74 try {
Skyler Grey11236ba2022-08-08 21:13:33 +010075 const status = await fetch(client.config.baseUrl).then((res) => res.status);
Skyler Grey75ea9172022-08-06 10:22:23 +010076 if (status !== 200) {
77 return await interaction.editReply({
78 embeds: [
79 new EmojiEmbed()
80 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010081 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010082 .setStatus("Danger")
83 .setEmoji("CONTROL.BLOCKCROSS")
84 ]
85 });
pineafan813bdf42022-07-24 10:39:10 +010086 }
87 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010088 return await interaction.editReply({
89 embeds: [
90 new EmojiEmbed()
91 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010092 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010093 .setStatus("Danger")
94 .setEmoji("CONTROL.BLOCKCROSS")
95 ],
96 components: [
97 new Discord.MessageActionRow().addComponents([
98 new Discord.MessageButton()
99 .setLabel("Check webpage")
100 .setStyle("LINK")
101 .setURL(client.config.baseUrl),
102 new Discord.MessageButton()
103 .setLabel("Support")
104 .setStyle("LINK")
105 .setURL("https://discord.gg/bPaNnxe")
106 ])
107 ]
108 });
pineafan813bdf42022-07-24 10:39:10 +0100109 }
110 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100111 await interaction.editReply({
112 embeds: [
113 new EmojiEmbed()
114 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100115 .setDescription("Checking your avatar is safe for work" + step(1))
Skyler Grey75ea9172022-08-06 10:22:23 +0100116 .setStatus("Warning")
117 .setEmoji("NUCLEUS.LOADING")
118 ]
119 });
120 if (
121 await NSFWCheck(
pineafan3a02ea32022-08-11 21:35:04 +0100122 (interaction.member as GuildMember).user.displayAvatarURL({
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 format: "png"
124 })
125 )
126 ) {
127 return await interaction.editReply({
128 embeds: [
129 new EmojiEmbed()
130 .setTitle("Verify")
131 .setDescription(
132 "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" +
133 step(1)
134 )
135 .setStatus("Danger")
136 .setEmoji("CONTROL.BLOCKCROSS")
137 ]
138 });
pineafan813bdf42022-07-24 10:39:10 +0100139 }
140 }
141 if (config.filters.wordFilter) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100142 await interaction.editReply({
143 embeds: [
144 new EmojiEmbed()
145 .setTitle("Verify")
146 .setDescription("Checking your name is allowed" + step(2))
147 .setStatus("Warning")
148 .setEmoji("NUCLEUS.LOADING")
149 ]
150 });
151 if (
152 TestString(
153 (interaction.member as Discord.GuildMember).displayName,
154 config.filters.wordFilter.words.loose,
155 config.filters.wordFilter.words.strict
156 ) !== null
157 ) {
158 return await interaction.editReply({
159 embeds: [
160 new EmojiEmbed()
161 .setTitle("Verify")
162 .setDescription(
163 "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" +
164 step(2)
165 )
166 .setStatus("Danger")
167 .setEmoji("CONTROL.BLOCKCROSS")
168 ]
169 });
pineafan813bdf42022-07-24 10:39:10 +0100170 }
171 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100172 await interaction.editReply({
173 embeds: [
174 new EmojiEmbed()
175 .setTitle("Verify")
176 .setDescription("One moment..." + step(3))
177 .setStatus("Warning")
178 .setEmoji("NUCLEUS.LOADING")
179 ]
180 });
pineafan63fc5e22022-08-04 22:04:10 +0100181 let code = "";
182 let length = 5;
183 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100184 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Skyler Greyf21323a2022-08-13 23:58:22 +0100185 do {
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 (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100192 itt = 0;
193 length += 1;
pineafan813bdf42022-07-24 10:39:10 +0100194 }
Skyler Greyf21323a2022-08-13 23:58:22 +0100195 } while (code in verify);
pineafan3a02ea32022-08-11 21:35:04 +0100196 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
197 if (!role) {
198 await interaction.editReply({
199 embeds: [
200 new EmojiEmbed()
201 .setTitle("Verify")
202 .setDescription(
203 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
204 step(4)
205 )
206 .setStatus("Danger")
207 .setEmoji("CONTROL.BLOCKCROSS")
208 ]
209 });
210 return; // TODO: SEN
211 }
pineafan813bdf42022-07-24 10:39:10 +0100212 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100213 uID: interaction.member!.user.id,
214 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100215 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100216 rName: role.name,
217 uName: interaction.member!.user.username,
218 gName: interaction.guild!.name,
219 gIcon: interaction.guild!.iconURL({ format: "png" }),
pineafan813bdf42022-07-24 10:39:10 +0100220 interaction: interaction
pineafan63fc5e22022-08-04 22:04:10 +0100221 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100222 await interaction.editReply({
223 embeds: [
224 new EmojiEmbed()
225 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100226 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100227 .setStatus("Success")
228 .setEmoji("MEMBER.JOIN")
229 ],
230 components: [
231 new Discord.MessageActionRow().addComponents([
232 new Discord.MessageButton()
233 .setLabel("Verify")
234 .setStyle("LINK")
Skyler Grey11236ba2022-08-08 21:13:33 +0100235 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100236 ])
237 ]
238 });
pineafan813bdf42022-07-24 10:39:10 +0100239}