blob: bbb09929b46132dcce66499cdcbf0fdc44b2ec17 [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,
TheCodedProf21c08592022-09-13 14:14:43 -04008 Role,
9 ButtonStyle
Skyler Greyf21323a2022-08-13 23:58:22 +010010} from "discord.js";
pineafan813bdf42022-07-24 10:39:10 +010011import EmojiEmbed from "../utils/generateEmojiEmbed.js";
12import fetch from "node-fetch";
13import { TestString, NSFWCheck } from "./scanners.js";
14import createPageIndicator from "../utils/createPageIndicator.js";
15import client from "../utils/client.js";
16
Skyler Grey11236ba2022-08-08 21:13:33 +010017export interface VerifySchema {
18 uID: string;
19 gID: string;
20 rID: string;
21 rName: string;
22 uName: string;
23 gName: string;
24 gIcon: string;
25 interaction: Interaction;
26}
27
Skyler Grey75ea9172022-08-06 10:22:23 +010028function step(i: number) {
pineafan813bdf42022-07-24 10:39:10 +010029 return "\n\n" + createPageIndicator(5, i);
30}
31
pineafan0f5cc782022-08-12 21:55:42 +010032export default async function (interaction: CommandInteraction | MessageComponentInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +010033 const verify = client.verify;
Skyler Grey75ea9172022-08-06 10:22:23 +010034 await interaction.reply({
35 embeds: LoadingEmbed,
36 ephemeral: true,
37 fetchReply: true
38 });
pineafan3a02ea32022-08-11 21:35:04 +010039 const config = await client.database.guilds.read(interaction.guild!.id);
Skyler Grey75ea9172022-08-06 10:22:23 +010040 if (!config.verify.enabled || !config.verify.role)
41 return interaction.editReply({
42 embeds: [
43 new EmojiEmbed()
44 .setTitle("Verify")
45 .setDescription("Verify is not enabled on this server")
46 .setFooter({
pineafan3a02ea32022-08-11 21:35:04 +010047 text: (interaction.member!.permissions as Permissions).has("MANAGE_GUILD")
Skyler Grey75ea9172022-08-06 10:22:23 +010048 ? "You can enable it by running /settings verify"
49 : ""
50 })
51 .setStatus("Danger")
52 .setEmoji("CONTROL.BLOCKCROSS")
pineafan3a02ea32022-08-11 21:35:04 +010053 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010054 });
Skyler Grey11236ba2022-08-08 21:13:33 +010055 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010056 return await interaction.editReply({
57 embeds: [
58 new EmojiEmbed()
59 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010060 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010061 .setStatus("Danger")
62 .setEmoji("CONTROL.BLOCKCROSS")
63 ]
64 });
pineafan813bdf42022-07-24 10:39:10 +010065 }
Skyler Grey75ea9172022-08-06 10:22:23 +010066 await interaction.editReply({
67 embeds: [
68 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010069 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010070 .setDescription("Checking our servers are up" + step(0))
71 .setStatus("Warning")
72 .setEmoji("NUCLEUS.LOADING")
73 ]
74 });
75 try {
Skyler Grey11236ba2022-08-08 21:13:33 +010076 const status = await fetch(client.config.baseUrl).then((res) => res.status);
Skyler Grey75ea9172022-08-06 10:22:23 +010077 if (status !== 200) {
78 return await interaction.editReply({
79 embeds: [
80 new EmojiEmbed()
81 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010082 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010083 .setStatus("Danger")
84 .setEmoji("CONTROL.BLOCKCROSS")
85 ]
86 });
pineafan813bdf42022-07-24 10:39:10 +010087 }
88 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010089 return await interaction.editReply({
90 embeds: [
91 new EmojiEmbed()
92 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010093 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010094 .setStatus("Danger")
95 .setEmoji("CONTROL.BLOCKCROSS")
96 ],
97 components: [
TheCodedProf21c08592022-09-13 14:14:43 -040098 new Discord.ActionRowBuilder().addComponents([
99 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100100 .setLabel("Check webpage")
TheCodedProf21c08592022-09-13 14:14:43 -0400101 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 .setURL(client.config.baseUrl),
TheCodedProf21c08592022-09-13 14:14:43 -0400103 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100104 .setLabel("Support")
TheCodedProf21c08592022-09-13 14:14:43 -0400105 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 .setURL("https://discord.gg/bPaNnxe")
107 ])
108 ]
109 });
pineafan813bdf42022-07-24 10:39:10 +0100110 }
111 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100112 await interaction.editReply({
113 embeds: [
114 new EmojiEmbed()
115 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100116 .setDescription("Checking your avatar is safe for work" + step(1))
Skyler Grey75ea9172022-08-06 10:22:23 +0100117 .setStatus("Warning")
118 .setEmoji("NUCLEUS.LOADING")
119 ]
120 });
121 if (
122 await NSFWCheck(
pineafan3a02ea32022-08-11 21:35:04 +0100123 (interaction.member as GuildMember).user.displayAvatarURL({
Skyler Grey75ea9172022-08-06 10:22:23 +0100124 format: "png"
125 })
126 )
127 ) {
128 return await interaction.editReply({
129 embeds: [
130 new EmojiEmbed()
131 .setTitle("Verify")
132 .setDescription(
133 "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" +
134 step(1)
135 )
136 .setStatus("Danger")
137 .setEmoji("CONTROL.BLOCKCROSS")
138 ]
139 });
pineafan813bdf42022-07-24 10:39:10 +0100140 }
141 }
142 if (config.filters.wordFilter) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100143 await interaction.editReply({
144 embeds: [
145 new EmojiEmbed()
146 .setTitle("Verify")
147 .setDescription("Checking your name is allowed" + step(2))
148 .setStatus("Warning")
149 .setEmoji("NUCLEUS.LOADING")
150 ]
151 });
152 if (
153 TestString(
154 (interaction.member as Discord.GuildMember).displayName,
155 config.filters.wordFilter.words.loose,
156 config.filters.wordFilter.words.strict
157 ) !== null
158 ) {
159 return await interaction.editReply({
160 embeds: [
161 new EmojiEmbed()
162 .setTitle("Verify")
163 .setDescription(
164 "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" +
165 step(2)
166 )
167 .setStatus("Danger")
168 .setEmoji("CONTROL.BLOCKCROSS")
169 ]
170 });
pineafan813bdf42022-07-24 10:39:10 +0100171 }
172 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100173 await interaction.editReply({
174 embeds: [
175 new EmojiEmbed()
176 .setTitle("Verify")
177 .setDescription("One moment..." + step(3))
178 .setStatus("Warning")
179 .setEmoji("NUCLEUS.LOADING")
180 ]
181 });
pineafan63fc5e22022-08-04 22:04:10 +0100182 let code = "";
183 let length = 5;
184 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100185 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Skyler Greyf21323a2022-08-13 23:58:22 +0100186 do {
pineafan63fc5e22022-08-04 22:04:10 +0100187 itt += 1;
188 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100189 for (let i = 0; i < length; i++) {
190 code += chars.charAt(Math.floor(Math.random() * chars.length));
191 }
pineafan813bdf42022-07-24 10:39:10 +0100192 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100193 itt = 0;
194 length += 1;
pineafan813bdf42022-07-24 10:39:10 +0100195 }
Skyler Greyf21323a2022-08-13 23:58:22 +0100196 } while (code in verify);
pineafan3a02ea32022-08-11 21:35:04 +0100197 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
198 if (!role) {
199 await interaction.editReply({
200 embeds: [
201 new EmojiEmbed()
202 .setTitle("Verify")
203 .setDescription(
204 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
205 step(4)
206 )
207 .setStatus("Danger")
208 .setEmoji("CONTROL.BLOCKCROSS")
209 ]
210 });
211 return; // TODO: SEN
212 }
pineafan813bdf42022-07-24 10:39:10 +0100213 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100214 uID: interaction.member!.user.id,
215 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100216 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100217 rName: role.name,
218 uName: interaction.member!.user.username,
219 gName: interaction.guild!.name,
220 gIcon: interaction.guild!.iconURL({ format: "png" }),
pineafan813bdf42022-07-24 10:39:10 +0100221 interaction: interaction
pineafan63fc5e22022-08-04 22:04:10 +0100222 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100223 await interaction.editReply({
224 embeds: [
225 new EmojiEmbed()
226 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100227 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100228 .setStatus("Success")
229 .setEmoji("MEMBER.JOIN")
230 ],
231 components: [
TheCodedProf21c08592022-09-13 14:14:43 -0400232 new Discord.ActionRowBuilder().addComponents([
233 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100234 .setLabel("Verify")
TheCodedProf21c08592022-09-13 14:14:43 -0400235 .setStyle(ButtonStyle.Link)
Skyler Grey11236ba2022-08-08 21:13:33 +0100236 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100237 ])
238 ]
239 });
pineafan813bdf42022-07-24 10:39:10 +0100240}