blob: 489a10999a18767858f0a63cb82cb1da4881e0b8 [file] [log] [blame]
pineafan1dc15722022-03-14 21:27:34 +00001import Discord, { CommandInteraction, GuildMember } from "discord.js";
pineafan4f164f32022-02-26 22:07:12 +00002import { SlashCommandBuilder } from "@discordjs/builders";
3import { WrappedCheck } from "jshaiku";
pineafan1dc15722022-03-14 21:27:34 +00004import generateEmojiEmbed from "../utils/generateEmojiEmbed.js";
5import readConfig from "../utils/readConfig.js";
6import fetch from "node-fetch";
7import { TestString, NSFWCheck } from "../automations/unscan.js";
pineafan4f164f32022-02-26 22:07:12 +00008
9const command = new SlashCommandBuilder()
10 .setName("verify")
11 .setDescription("Get verified in the server")
12
pineafan1dc15722022-03-14 21:27:34 +000013const callback = async (interaction: CommandInteraction) => {
14 // @ts-ignore
15 let verify = interaction.client.verify
16 await interaction.reply({embeds: [new generateEmojiEmbed()
17 .setTitle("Loading")
18 .setStatus("Danger")
19 .setEmoji("NUCLEUS.LOADING")
20 ], ephemeral: true, fetchReply: true});
21 let config = await readConfig(interaction.guild.id);
22 if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) {
23 return await interaction.editReply({embeds: [new generateEmojiEmbed()
24 .setTitle("Verify")
25 .setDescription(`You already have the <@&${config.verify.role}> role`)
26 .setStatus("Danger")
27 .setEmoji("CONTROL.BLOCKCROSS")
28 ]});
29 } else if (interaction.channel.id != config.verify.channel) {
30 return await interaction.editReply({embeds: [new generateEmojiEmbed()
31 .setTitle("Verify")
32 .setDescription(`You can only use this command in <#${config.verify.channel}>`)
33 .setStatus("Danger")
34 .setEmoji("CONTROL.BLOCKCROSS")
35 ]});
36 }
37 await interaction.editReply({embeds: [new generateEmojiEmbed()
38 .setTitle("Verify")
39 .setDescription(`Checking our servers are up`)
40 .setStatus("Warning")
41 .setEmoji("NUCLEUS.LOADING")
42 ]});
43 try {
44 let status = await fetch(`https://clicksminuteper.net`).then(res => res.status);
45 if (status != 200) {
46 return await interaction.editReply({embeds: [new generateEmojiEmbed()
47 .setTitle("Verify")
48 .setDescription(`Our servers appear to be down, please try again later`)
49 .setStatus("Danger")
50 .setEmoji("CONTROL.BLOCKCROSS")
51 ]});
52 }
53 } catch {
54 return await interaction.editReply({embeds: [new generateEmojiEmbed()
55 .setTitle("Verify")
56 .setDescription(`Our servers appear to be down, please try again later`)
57 .setStatus("Danger")
58 .setEmoji("CONTROL.BLOCKCROSS")
59 ], components: [new Discord.MessageActionRow().addComponents([
60 new Discord.MessageButton()
61 .setLabel("Open webpage")
62 .setStyle("LINK")
63 .setURL("https://clicksminuteper.net/"),
64 new Discord.MessageButton()
65 .setLabel("Support")
66 .setStyle("LINK")
67 .setURL("https://discord.gg/bPaNnxe")
68 ])]});
69 }
70 if (config.filters.images.NSFW) {
71 await interaction.editReply({embeds: [new generateEmojiEmbed()
72 .setTitle("Verify")
73 .setDescription(`Checking your avatar is safe for work`)
74 .setStatus("Warning")
75 .setEmoji("NUCLEUS.LOADING")
76 ]});
77 if (await NSFWCheck((interaction.member as GuildMember).user.avatarURL({format: "png"}))) {
78 return await interaction.editReply({embeds: [new generateEmojiEmbed()
79 .setTitle("Verify")
80 .setDescription(`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`)
81 .setStatus("Danger")
82 .setEmoji("CONTROL.BLOCKCROSS")
83 ]});
84 }
85 }
86 if (config.filters.wordFilter) {
87 await interaction.editReply({embeds: [new generateEmojiEmbed()
88 .setTitle("Verify")
89 .setDescription(`Checking your name is allowed`)
90 .setStatus("Warning")
91 .setEmoji("NUCLEUS.LOADING")
92 ]});
93 if (TestString((interaction.member as Discord.GuildMember).displayName, config.filters.wordFilter.words.loose, config.filters.wordFilter.words.strict) != "none") {
94 return await interaction.editReply({embeds: [new generateEmojiEmbed()
95 .setTitle("Verify")
96 .setDescription(`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`)
97 .setStatus("Danger")
98 .setEmoji("CONTROL.BLOCKCROSS")
99 ]});
100 }
101 }
102 await interaction.editReply({embeds: [new generateEmojiEmbed()
103 .setTitle("Verify")
104 .setDescription(`One moment...`)
105 .setStatus("Warning")
106 .setEmoji("NUCLEUS.LOADING")
107 ]});
108 let code = ""
109 let length = 5
110 let itt = 0
111 const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
112 while (true) {
113 itt += 1
114 code = ""
115 for (let i = 0; i < length; i++) { code += chars.charAt(Math.floor(Math.random() * chars.length)); }
116 if (code in verify) continue;
117 if (itt > 1000) {
118 itt = 0
119 length += 1
120 continue
121 }
122 break;
123 }
124 verify[code] = {
125 uID: interaction.member.user.id,
126 gID: interaction.guild.id,
127 rName: (await interaction.guild.roles.fetch(config.verify.role)).name,
128 mCount: interaction.guild.memberCount,
129 gName: interaction.guild.name,
130 guildIcon: interaction.guild.iconURL({format: "png"})
131 }
132 await interaction.editReply({embeds: [new generateEmojiEmbed()
133 .setTitle("Verify")
134 .setDescription(`Looking good!\nClick the button below to get verified`)
135 .setStatus("Success")
136 .setEmoji("MEMBER.JOIN")
137 ], components: [new Discord.MessageActionRow().addComponents([new Discord.MessageButton()
138 .setLabel("Verify")
139 .setStyle("LINK")
140 .setURL(`https://clicksminuteper.net/nucleus/verify?code=${code}`)
141 ])]});
pineafan4f164f32022-02-26 22:07:12 +0000142}
143
144const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
145 return true;
146}
147
148export { command };
149export { callback };
pineafan1dc15722022-03-14 21:27:34 +0000150export { check };