blob: 4977c64cb5db7e19b8eb5960d1672e676f8dea40 [file] [log] [blame]
PineaFan0d06edc2023-01-17 22:10:31 +00001import { LoadingEmbed, unknownServerIcon } from "../utils/defaults.js";
Skyler Greyf21323a2022-08-13 23:58:22 +01002import Discord, {
3 CommandInteraction,
4 GuildMember,
Skyler Greyf21323a2022-08-13 23:58:22 +01005 MessageComponentInteraction,
TheCodedProf21c08592022-09-13 14:14:43 -04006 Role,
PineaFan752af462022-12-31 21:59:38 +00007 ButtonStyle,
PineaFan538d3752023-01-12 21:48:23 +00008 PermissionsBitField,
9 ButtonInteraction
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;
PineaFan752af462022-12-31 21:59:38 +000025 interaction: Discord.MessageComponentInteraction;
Skyler Grey11236ba2022-08-08 21:13:33 +010026}
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
PineaFan538d3752023-01-12 21:48:23 +000032export default async function (interaction: CommandInteraction | ButtonInteraction) {
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({
PineaFan752af462022-12-31 21:59:38 +000047 text: (interaction.member!.permissions as PermissionsBitField).has("ManageGuild")
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: [
PineaFan752af462022-12-31 21:59:38 +000098 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040099 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(
PineaFan752af462022-12-31 21:59:38 +0000123 (interaction.member as GuildMember).user.displayAvatarURL({extension: "png", forceStatic: true})
Skyler Grey75ea9172022-08-06 10:22:23 +0100124 )
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 }
PineaFan752af462022-12-31 21:59:38 +0000140 if (config.filters.wordFilter.enabled) {
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 Grey11236ba2022-08-08 21:13:33 +0100183 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Skyler Greyf21323a2022-08-13 23:58:22 +0100184 do {
pineafan63fc5e22022-08-04 22:04:10 +0100185 itt += 1;
186 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100187 for (let i = 0; i < length; i++) {
188 code += chars.charAt(Math.floor(Math.random() * chars.length));
189 }
pineafan813bdf42022-07-24 10:39:10 +0100190 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100191 itt = 0;
192 length += 1;
pineafan813bdf42022-07-24 10:39:10 +0100193 }
Skyler Greyf21323a2022-08-13 23:58:22 +0100194 } while (code in verify);
pineafan3a02ea32022-08-11 21:35:04 +0100195 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
196 if (!role) {
197 await interaction.editReply({
198 embeds: [
199 new EmojiEmbed()
200 .setTitle("Verify")
201 .setDescription(
202 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
203 step(4)
204 )
205 .setStatus("Danger")
206 .setEmoji("CONTROL.BLOCKCROSS")
207 ]
208 });
209 return; // TODO: SEN
210 }
pineafan813bdf42022-07-24 10:39:10 +0100211 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100212 uID: interaction.member!.user.id,
213 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100214 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100215 rName: role.name,
216 uName: interaction.member!.user.username,
217 gName: interaction.guild!.name,
PineaFan0d06edc2023-01-17 22:10:31 +0000218 gIcon: interaction.guild!.iconURL({ extension: "png", size: 256 }) ?? unknownServerIcon,
PineaFan752af462022-12-31 21:59:38 +0000219 interaction: interaction as MessageComponentInteraction
pineafan63fc5e22022-08-04 22:04:10 +0100220 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100221 await interaction.editReply({
222 embeds: [
223 new EmojiEmbed()
224 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100225 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100226 .setStatus("Success")
227 .setEmoji("MEMBER.JOIN")
228 ],
229 components: [
PineaFan752af462022-12-31 21:59:38 +0000230 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400231 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100232 .setLabel("Verify")
TheCodedProf21c08592022-09-13 14:14:43 -0400233 .setStyle(ButtonStyle.Link)
Skyler Grey11236ba2022-08-08 21:13:33 +0100234 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100235 ])
236 ]
237 });
pineafan813bdf42022-07-24 10:39:10 +0100238}