blob: 540fb4d3f8419778fd21ab0feedf65c291b2854c [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 (
124 await NSFWCheck(
Skyler Greyda16adf2023-03-05 10:22:12 +0000125 (interaction.member as GuildMember).user.displayAvatarURL({ extension: "png", forceStatic: true })
Skyler Grey75ea9172022-08-06 10:22:23 +0100126 )
127 ) {
128 return await interaction.editReply({
129 embeds: [
130 new EmojiEmbed()
131 .setTitle("Verify")
132 .setDescription(
PineaFanc4d6c3f2023-01-19 12:17:25 +0000133 "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 +0100134 step(1)
135 )
136 .setStatus("Danger")
137 .setEmoji("CONTROL.BLOCKCROSS")
138 ]
139 });
pineafan813bdf42022-07-24 10:39:10 +0100140 }
141 }
PineaFan752af462022-12-31 21:59:38 +0000142 if (config.filters.wordFilter.enabled) {
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 {
Skyler Greyda16adf2023-03-05 10:22:12 +0000187 itt++;
pineafan63fc5e22022-08-04 22:04:10 +0100188 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;
Skyler Greyda16adf2023-03-05 10:22:12 +0000194 length++;
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 });
Skyler Greyf4f21c42023-03-08 14:36:29 +0000211 await singleNotify(
Skyler Greyda16adf2023-03-05 10:22:12 +0000212 "verifyRoleDeleted",
213 interaction.guild!.id,
214 `The role given when a member is verified has been deleted. Use ${getCommandMentionByName(
215 "settings/verify"
216 )} to set a new one`,
217 "Critical"
218 );
TheCodedProf1f675042023-02-16 17:01:29 -0500219 return;
pineafan3a02ea32022-08-11 21:35:04 +0100220 }
pineafan813bdf42022-07-24 10:39:10 +0100221 verify[code] = {
pineafan3a02ea32022-08-11 21:35:04 +0100222 uID: interaction.member!.user.id,
223 gID: interaction.guild!.id,
pineafan813bdf42022-07-24 10:39:10 +0100224 rID: config.verify.role,
pineafan3a02ea32022-08-11 21:35:04 +0100225 rName: role.name,
226 uName: interaction.member!.user.username,
227 gName: interaction.guild!.name,
PineaFan0d06edc2023-01-17 22:10:31 +0000228 gIcon: interaction.guild!.iconURL({ extension: "png", size: 256 }) ?? unknownServerIcon,
PineaFan752af462022-12-31 21:59:38 +0000229 interaction: interaction as MessageComponentInteraction
pineafan63fc5e22022-08-04 22:04:10 +0100230 };
Skyler Grey75ea9172022-08-06 10:22:23 +0100231 await interaction.editReply({
232 embeds: [
233 new EmojiEmbed()
234 .setTitle("Verify")
pineafan3a02ea32022-08-11 21:35:04 +0100235 .setDescription("Looking good!\nClick the button below to get verified." + step(4))
Skyler Grey75ea9172022-08-06 10:22:23 +0100236 .setStatus("Success")
237 .setEmoji("MEMBER.JOIN")
238 ],
239 components: [
PineaFan752af462022-12-31 21:59:38 +0000240 new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([
TheCodedProf21c08592022-09-13 14:14:43 -0400241 new Discord.ButtonBuilder()
Skyler Grey75ea9172022-08-06 10:22:23 +0100242 .setLabel("Verify")
TheCodedProf21c08592022-09-13 14:14:43 -0400243 .setStyle(ButtonStyle.Link)
Skyler Grey11236ba2022-08-08 21:13:33 +0100244 .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`)
Skyler Grey75ea9172022-08-06 10:22:23 +0100245 ])
246 ]
247 });
pineafan813bdf42022-07-24 10:39:10 +0100248}