blob: 6458439a442c5459110233826e4fd3a4a5dc9376 [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,
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,
8 PermissionsBitField
Skyler Greyf21323a2022-08-13 23:58:22 +01009} 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;
PineaFan752af462022-12-31 21:59:38 +000024 interaction: Discord.MessageComponentInteraction;
Skyler Grey11236ba2022-08-08 21:13:33 +010025}
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({
PineaFan752af462022-12-31 21:59:38 +000046 text: (interaction.member!.permissions as PermissionsBitField).has("ManageGuild")
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: [
PineaFan752af462022-12-31 21:59:38 +000097 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -040098 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +010099 .setLabel("Check webpage")
TheCodedProf21c08592022-09-13 14:14:43 -0400100 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100101 .setURL(client.config.baseUrl),
TheCodedProf21c08592022-09-13 14:14:43 -0400102 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100103 .setLabel("Support")
TheCodedProf21c08592022-09-13 14:14:43 -0400104 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100105 .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(
PineaFan752af462022-12-31 21:59:38 +0000122 (interaction.member as GuildMember).user.displayAvatarURL({extension: "png", forceStatic: true})
Skyler Grey75ea9172022-08-06 10:22:23 +0100123 )
124 ) {
125 return await interaction.editReply({
126 embeds: [
127 new EmojiEmbed()
128 .setTitle("Verify")
129 .setDescription(
130 "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" +
131 step(1)
132 )
133 .setStatus("Danger")
134 .setEmoji("CONTROL.BLOCKCROSS")
135 ]
136 });
pineafan813bdf42022-07-24 10:39:10 +0100137 }
138 }
PineaFan752af462022-12-31 21:59:38 +0000139 if (config.filters.wordFilter.enabled) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100140 await interaction.editReply({
141 embeds: [
142 new EmojiEmbed()
143 .setTitle("Verify")
144 .setDescription("Checking your name is allowed" + step(2))
145 .setStatus("Warning")
146 .setEmoji("NUCLEUS.LOADING")
147 ]
148 });
149 if (
150 TestString(
151 (interaction.member as Discord.GuildMember).displayName,
152 config.filters.wordFilter.words.loose,
153 config.filters.wordFilter.words.strict
154 ) !== null
155 ) {
156 return await interaction.editReply({
157 embeds: [
158 new EmojiEmbed()
159 .setTitle("Verify")
160 .setDescription(
161 "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" +
162 step(2)
163 )
164 .setStatus("Danger")
165 .setEmoji("CONTROL.BLOCKCROSS")
166 ]
167 });
pineafan813bdf42022-07-24 10:39:10 +0100168 }
169 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100170 await interaction.editReply({
171 embeds: [
172 new EmojiEmbed()
173 .setTitle("Verify")
174 .setDescription("One moment..." + step(3))
175 .setStatus("Warning")
176 .setEmoji("NUCLEUS.LOADING")
177 ]
178 });
pineafan63fc5e22022-08-04 22:04:10 +0100179 let code = "";
180 let length = 5;
181 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100182 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Skyler Greyf21323a2022-08-13 23:58:22 +0100183 do {
pineafan63fc5e22022-08-04 22:04:10 +0100184 itt += 1;
185 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100186 for (let i = 0; i < length; i++) {
187 code += chars.charAt(Math.floor(Math.random() * chars.length));
188 }
pineafan813bdf42022-07-24 10:39:10 +0100189 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100190 itt = 0;
191 length += 1;
pineafan813bdf42022-07-24 10:39:10 +0100192 }
Skyler Greyf21323a2022-08-13 23:58:22 +0100193 } while (code in verify);
pineafan3a02ea32022-08-11 21:35:04 +0100194 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
195 if (!role) {
196 await interaction.editReply({
197 embeds: [
198 new EmojiEmbed()
199 .setTitle("Verify")
200 .setDescription(
201 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
202 step(4)
203 )
204 .setStatus("Danger")
205 .setEmoji("CONTROL.BLOCKCROSS")
206 ]
207 });
208 return; // TODO: SEN
209 }
pineafan813bdf42022-07-24 10:39:10 +0100210 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100211 uID: interaction.member!.user.id,
212 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100213 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100214 rName: role.name,
215 uName: interaction.member!.user.username,
216 gName: interaction.guild!.name,
PineaFan752af462022-12-31 21:59:38 +0000217 gIcon: interaction.guild!.iconURL({ extension: "png", size: 256 }) ?? "https://assets-global.website-files.com/6257adef93867e50d84d30e2/636e0a6a49cf127bf92de1e2_icon_clyde_blurple_RGB.png",
218 interaction: interaction as MessageComponentInteraction
pineafan63fc5e22022-08-04 22:04:10 +0100219 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100220 await interaction.editReply({
221 embeds: [
222 new EmojiEmbed()
223 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100224 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100225 .setStatus("Success")
226 .setEmoji("MEMBER.JOIN")
227 ],
228 components: [
PineaFan752af462022-12-31 21:59:38 +0000229 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400230 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100231 .setLabel("Verify")
TheCodedProf21c08592022-09-13 14:14:43 -0400232 .setStyle(ButtonStyle.Link)
Skyler Grey11236ba2022-08-08 21:13:33 +0100233 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100234 ])
235 ]
236 });
pineafan813bdf42022-07-24 10:39:10 +0100237}