pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 2 | import Discord, { CommandInteraction, GuildMember } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 3 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 4 | import fetch from "node-fetch"; |
| 5 | import { TestString, NSFWCheck } from "./scanners.js"; |
| 6 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 7 | import client from "../utils/client.js"; |
| 8 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 9 | function step(i: number) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 10 | return "\n\n" + createPageIndicator(5, i); |
| 11 | } |
| 12 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 13 | export default async function (interaction: CommandInteraction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const verify = client.verify; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | await interaction.reply({ |
| 16 | embeds: LoadingEmbed, |
| 17 | ephemeral: true, |
| 18 | fetchReply: true |
| 19 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | const config = await client.database.guilds.read(interaction.guild.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 21 | if (!config.verify.enabled || !config.verify.role) |
| 22 | return interaction.editReply({ |
| 23 | embeds: [ |
| 24 | new EmojiEmbed() |
| 25 | .setTitle("Verify") |
| 26 | .setDescription("Verify is not enabled on this server") |
| 27 | .setFooter({ |
| 28 | text: interaction.member.permissions.has("MANAGE_GUILD") |
| 29 | ? "You can enable it by running /settings verify" |
| 30 | : "" |
| 31 | }) |
| 32 | .setStatus("Danger") |
| 33 | .setEmoji("CONTROL.BLOCKCROSS") |
| 34 | ], |
| 35 | ephemeral: true, |
| 36 | fetchReply: true |
| 37 | }); |
| 38 | if ( |
| 39 | (interaction.member as GuildMember).roles.cache.has(config.verify.role) |
| 40 | ) { |
| 41 | return await interaction.editReply({ |
| 42 | embeds: [ |
| 43 | new EmojiEmbed() |
| 44 | .setTitle("Verify") |
| 45 | .setDescription( |
| 46 | `You already have the <@&${config.verify.role}> role` + |
| 47 | step(0) |
| 48 | ) |
| 49 | .setStatus("Danger") |
| 50 | .setEmoji("CONTROL.BLOCKCROSS") |
| 51 | ] |
| 52 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 53 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | await interaction.editReply({ |
| 55 | embeds: [ |
| 56 | new EmojiEmbed() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 57 | .setTitle("Verify") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 58 | .setDescription("Checking our servers are up" + step(0)) |
| 59 | .setStatus("Warning") |
| 60 | .setEmoji("NUCLEUS.LOADING") |
| 61 | ] |
| 62 | }); |
| 63 | try { |
| 64 | const status = await fetch(client.config.baseUrl).then( |
| 65 | (res) => res.status |
| 66 | ); |
| 67 | if (status !== 200) { |
| 68 | return await interaction.editReply({ |
| 69 | embeds: [ |
| 70 | new EmojiEmbed() |
| 71 | .setTitle("Verify") |
| 72 | .setDescription( |
| 73 | "Our servers appear to be down, please try again later" + |
| 74 | step(0) |
| 75 | ) |
| 76 | .setStatus("Danger") |
| 77 | .setEmoji("CONTROL.BLOCKCROSS") |
| 78 | ] |
| 79 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 80 | } |
| 81 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | return await interaction.editReply({ |
| 83 | embeds: [ |
| 84 | new EmojiEmbed() |
| 85 | .setTitle("Verify") |
| 86 | .setDescription( |
| 87 | "Our servers appear to be down, please try again later" + |
| 88 | step(0) |
| 89 | ) |
| 90 | .setStatus("Danger") |
| 91 | .setEmoji("CONTROL.BLOCKCROSS") |
| 92 | ], |
| 93 | components: [ |
| 94 | new Discord.MessageActionRow().addComponents([ |
| 95 | new Discord.MessageButton() |
| 96 | .setLabel("Check webpage") |
| 97 | .setStyle("LINK") |
| 98 | .setURL(client.config.baseUrl), |
| 99 | new Discord.MessageButton() |
| 100 | .setLabel("Support") |
| 101 | .setStyle("LINK") |
| 102 | .setURL("https://discord.gg/bPaNnxe") |
| 103 | ]) |
| 104 | ] |
| 105 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 106 | } |
| 107 | if (config.filters.images.NSFW) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 108 | await interaction.editReply({ |
| 109 | embeds: [ |
| 110 | new EmojiEmbed() |
| 111 | .setTitle("Verify") |
| 112 | .setDescription( |
| 113 | "Checking your avatar is safe for work" + step(1) |
| 114 | ) |
| 115 | .setStatus("Warning") |
| 116 | .setEmoji("NUCLEUS.LOADING") |
| 117 | ] |
| 118 | }); |
| 119 | if ( |
| 120 | await NSFWCheck( |
| 121 | (interaction.member as GuildMember).user.avatarURL({ |
| 122 | format: "png" |
| 123 | }) |
| 124 | ) |
| 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 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | if (config.filters.wordFilter) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 141 | 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 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 169 | } |
| 170 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 171 | 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 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 180 | let code = ""; |
| 181 | let length = 5; |
| 182 | let itt = 0; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 183 | const chars = |
| 184 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 185 | while (true) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 186 | itt += 1; |
| 187 | code = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 188 | for (let i = 0; i < length; i++) { |
| 189 | code += chars.charAt(Math.floor(Math.random() * chars.length)); |
| 190 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 191 | if (code in verify) continue; |
| 192 | if (itt > 1000) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 193 | itt = 0; |
| 194 | length += 1; |
| 195 | continue; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 196 | } |
| 197 | break; |
| 198 | } |
| 199 | verify[code] = { |
| 200 | uID: interaction.member.user.id, |
| 201 | gID: interaction.guild.id, |
| 202 | rID: config.verify.role, |
| 203 | rName: (await interaction.guild.roles.fetch(config.verify.role)).name, |
| 204 | uName: interaction.member.user.username, |
| 205 | gName: interaction.guild.name, |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 206 | gIcon: interaction.guild.iconURL({ format: "png" }), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 207 | interaction: interaction |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 208 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 209 | await interaction.editReply({ |
| 210 | embeds: [ |
| 211 | new EmojiEmbed() |
| 212 | .setTitle("Verify") |
| 213 | .setDescription( |
| 214 | "Looking good!\nClick the button below to get verified" + |
| 215 | step(4) |
| 216 | ) |
| 217 | .setStatus("Success") |
| 218 | .setEmoji("MEMBER.JOIN") |
| 219 | ], |
| 220 | components: [ |
| 221 | new Discord.MessageActionRow().addComponents([ |
| 222 | new Discord.MessageButton() |
| 223 | .setLabel("Verify") |
| 224 | .setStyle("LINK") |
| 225 | .setURL( |
| 226 | `${client.config.baseUrl}nucleus/verify?code=${code}` |
| 227 | ) |
| 228 | ]) |
| 229 | ] |
| 230 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 231 | } |