blob: 8f68c0e7da5883569ad09b756b56f95b913752c3 [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";
TheCodedProf1f675042023-02-16 17:01:29 -050016import singleNotify from "../utils/singleNotify.js";
17import { getCommandMentionByName } from "../utils/getCommandDataByName.js";
pineafan813bdf42022-07-24 10:39:10 +010018
Skyler Grey11236ba2022-08-08 21:13:33 +010019export interface VerifySchema {
20 uID: string;
21 gID: string;
22 rID: string;
23 rName: string;
24 uName: string;
25 gName: string;
26 gIcon: string;
PineaFan752af462022-12-31 21:59:38 +000027 interaction: Discord.MessageComponentInteraction;
Skyler Grey11236ba2022-08-08 21:13:33 +010028}
29
Skyler Grey75ea9172022-08-06 10:22:23 +010030function step(i: number) {
pineafan813bdf42022-07-24 10:39:10 +010031 return "\n\n" + createPageIndicator(5, i);
32}
33
PineaFan538d3752023-01-12 21:48:23 +000034export default async function (interaction: CommandInteraction | ButtonInteraction) {
pineafan63fc5e22022-08-04 22:04:10 +010035 const verify = client.verify;
Skyler Grey75ea9172022-08-06 10:22:23 +010036 await interaction.reply({
37 embeds: LoadingEmbed,
38 ephemeral: true,
39 fetchReply: true
40 });
pineafan3a02ea32022-08-11 21:35:04 +010041 const config = await client.database.guilds.read(interaction.guild!.id);
Skyler Grey75ea9172022-08-06 10:22:23 +010042 if (!config.verify.enabled || !config.verify.role)
43 return interaction.editReply({
44 embeds: [
45 new EmojiEmbed()
46 .setTitle("Verify")
47 .setDescription("Verify is not enabled on this server")
48 .setFooter({
PineaFan752af462022-12-31 21:59:38 +000049 text: (interaction.member!.permissions as PermissionsBitField).has("ManageGuild")
Skyler Grey75ea9172022-08-06 10:22:23 +010050 ? "You can enable it by running /settings verify"
51 : ""
52 })
53 .setStatus("Danger")
54 .setEmoji("CONTROL.BLOCKCROSS")
pineafan3a02ea32022-08-11 21:35:04 +010055 ]
Skyler Grey75ea9172022-08-06 10:22:23 +010056 });
Skyler Grey11236ba2022-08-08 21:13:33 +010057 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
Skyler Grey75ea9172022-08-06 10:22:23 +010058 return await interaction.editReply({
59 embeds: [
60 new EmojiEmbed()
61 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010062 .setDescription(`You already have the <@&${config.verify.role}> role` + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010063 .setStatus("Danger")
64 .setEmoji("CONTROL.BLOCKCROSS")
65 ]
66 });
pineafan813bdf42022-07-24 10:39:10 +010067 }
Skyler Grey75ea9172022-08-06 10:22:23 +010068 await interaction.editReply({
69 embeds: [
70 new EmojiEmbed()
pineafan813bdf42022-07-24 10:39:10 +010071 .setTitle("Verify")
Skyler Grey75ea9172022-08-06 10:22:23 +010072 .setDescription("Checking our servers are up" + step(0))
73 .setStatus("Warning")
74 .setEmoji("NUCLEUS.LOADING")
75 ]
76 });
77 try {
Skyler Grey11236ba2022-08-08 21:13:33 +010078 const status = await fetch(client.config.baseUrl).then((res) => res.status);
Skyler Grey75ea9172022-08-06 10:22:23 +010079 if (status !== 200) {
80 return await interaction.editReply({
81 embeds: [
82 new EmojiEmbed()
83 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010084 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010085 .setStatus("Danger")
86 .setEmoji("CONTROL.BLOCKCROSS")
87 ]
88 });
pineafan813bdf42022-07-24 10:39:10 +010089 }
90 } catch {
Skyler Grey75ea9172022-08-06 10:22:23 +010091 return await interaction.editReply({
92 embeds: [
93 new EmojiEmbed()
94 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +010095 .setDescription("Our servers appear to be down, please try again later" + step(0))
Skyler Grey75ea9172022-08-06 10:22:23 +010096 .setStatus("Danger")
97 .setEmoji("CONTROL.BLOCKCROSS")
98 ],
99 components: [
PineaFan752af462022-12-31 21:59:38 +0000100 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400101 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100102 .setLabel("Check webpage")
TheCodedProf21c08592022-09-13 14:14:43 -0400103 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100104 .setURL(client.config.baseUrl),
TheCodedProf21c08592022-09-13 14:14:43 -0400105 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100106 .setLabel("Support")
TheCodedProf21c08592022-09-13 14:14:43 -0400107 .setStyle(ButtonStyle.Link)
Skyler Grey75ea9172022-08-06 10:22:23 +0100108 .setURL("https://discord.gg/bPaNnxe")
109 ])
110 ]
111 });
pineafan813bdf42022-07-24 10:39:10 +0100112 }
113 if (config.filters.images.NSFW) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100114 await interaction.editReply({
115 embeds: [
116 new EmojiEmbed()
117 .setTitle("Verify")
Skyler Grey11236ba2022-08-08 21:13:33 +0100118 .setDescription("Checking your avatar is safe for work" + step(1))
Skyler Grey75ea9172022-08-06 10:22:23 +0100119 .setStatus("Warning")
120 .setEmoji("NUCLEUS.LOADING")
121 ]
122 });
123 if (
Skyler Grey8034b942023-03-09 00:34:46 +0000124 await NSFWCheck({
125 url: (interaction.member as GuildMember).user.displayAvatarURL({ extension: "png", forceStatic: true }),
126 height: 1024,
127 width: 1024,
128 })
Skyler Grey75ea9172022-08-06 10:22:23 +0100129 ) {
130 return await interaction.editReply({
131 embeds: [
132 new EmojiEmbed()
133 .setTitle("Verify")
134 .setDescription(
PineaFanc4d6c3f2023-01-19 12:17:25 +0000135 "Your avatar was detected as NSFW, which we do not allow in this server.\nPlease contact a staff members if you believe this is a mistake" +
Skyler Grey75ea9172022-08-06 10:22:23 +0100136 step(1)
137 )
138 .setStatus("Danger")
139 .setEmoji("CONTROL.BLOCKCROSS")
140 ]
141 });
pineafan813bdf42022-07-24 10:39:10 +0100142 }
143 }
PineaFan752af462022-12-31 21:59:38 +0000144 if (config.filters.wordFilter.enabled) {
Skyler Grey75ea9172022-08-06 10:22:23 +0100145 await interaction.editReply({
146 embeds: [
147 new EmojiEmbed()
148 .setTitle("Verify")
149 .setDescription("Checking your name is allowed" + step(2))
150 .setStatus("Warning")
151 .setEmoji("NUCLEUS.LOADING")
152 ]
153 });
154 if (
155 TestString(
156 (interaction.member as Discord.GuildMember).displayName,
157 config.filters.wordFilter.words.loose,
158 config.filters.wordFilter.words.strict
159 ) !== null
160 ) {
161 return await interaction.editReply({
162 embeds: [
163 new EmojiEmbed()
164 .setTitle("Verify")
165 .setDescription(
166 "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" +
167 step(2)
168 )
169 .setStatus("Danger")
170 .setEmoji("CONTROL.BLOCKCROSS")
171 ]
172 });
pineafan813bdf42022-07-24 10:39:10 +0100173 }
174 }
Skyler Grey75ea9172022-08-06 10:22:23 +0100175 await interaction.editReply({
176 embeds: [
177 new EmojiEmbed()
178 .setTitle("Verify")
179 .setDescription("One moment..." + step(3))
180 .setStatus("Warning")
181 .setEmoji("NUCLEUS.LOADING")
182 ]
183 });
pineafan63fc5e22022-08-04 22:04:10 +0100184 let code = "";
185 let length = 5;
186 let itt = 0;
Skyler Grey11236ba2022-08-08 21:13:33 +0100187 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Skyler Greyf21323a2022-08-13 23:58:22 +0100188 do {
Skyler Greyda16adf2023-03-05 10:22:12 +0000189 itt++;
pineafan63fc5e22022-08-04 22:04:10 +0100190 code = "";
Skyler Grey75ea9172022-08-06 10:22:23 +0100191 for (let i = 0; i < length; i++) {
192 code += chars.charAt(Math.floor(Math.random() * chars.length));
193 }
pineafan813bdf42022-07-24 10:39:10 +0100194 if (itt > 1000) {
pineafan63fc5e22022-08-04 22:04:10 +0100195 itt = 0;
Skyler Greyda16adf2023-03-05 10:22:12 +0000196 length++;
pineafan813bdf42022-07-24 10:39:10 +0100197 }
Skyler Greyf21323a2022-08-13 23:58:22 +0100198 } while (code in verify);
pineafan3a02ea32022-08-11 21:35:04 +0100199 const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role);
200 if (!role) {
201 await interaction.editReply({
202 embeds: [
203 new EmojiEmbed()
204 .setTitle("Verify")
205 .setDescription(
206 "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." +
207 step(4)
208 )
209 .setStatus("Danger")
210 .setEmoji("CONTROL.BLOCKCROSS")
211 ]
212 });
Skyler Greyf4f21c42023-03-08 14:36:29 +0000213 await singleNotify(
Skyler Greyda16adf2023-03-05 10:22:12 +0000214 "verifyRoleDeleted",
215 interaction.guild!.id,
216 `The role given when a member is verified has been deleted. Use ${getCommandMentionByName(
217 "settings/verify"
218 )} to set a new one`,
219 "Critical"
220 );
TheCodedProf1f675042023-02-16 17:01:29 -0500221 return;
pineafan3a02ea32022-08-11 21:35:04 +0100222 }
pineafan813bdf42022-07-24 10:39:10 +0100223 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100224 uID: interaction.member!.user.id,
225 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100226 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100227 rName: role.name,
228 uName: interaction.member!.user.username,
229 gName: interaction.guild!.name,
PineaFan0d06edc2023-01-17 22:10:31 +0000230 gIcon: interaction.guild!.iconURL({ extension: "png", size: 256 }) ?? unknownServerIcon,
PineaFan752af462022-12-31 21:59:38 +0000231 interaction: interaction as MessageComponentInteraction
pineafan63fc5e22022-08-04 22:04:10 +0100232 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100233 await interaction.editReply({
234 embeds: [
235 new EmojiEmbed()
236 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100237 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100238 .setStatus("Success")
239 .setEmoji("MEMBER.JOIN")
240 ],
241 components: [
PineaFan752af462022-12-31 21:59:38 +0000242 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400243 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100244 .setLabel("Verify")
TheCodedProf21c08592022-09-13 14:14:43 -0400245 .setStyle(ButtonStyle.Link)
Skyler Grey11236ba2022-08-08 21:13:33 +0100246 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100247 ])
248 ]
249 });
pineafan813bdf42022-07-24 10:39:10 +0100250}