pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import { LoadingEmbed } from "./../utils/defaultEmbeds.js"; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | GuildMember, |
| 5 | Interaction, |
| 6 | MessageComponentInteraction, |
| 7 | Permissions, |
| 8 | Role |
| 9 | } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 10 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 11 | import fetch from "node-fetch"; |
| 12 | import { TestString, NSFWCheck } from "./scanners.js"; |
| 13 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 14 | import client from "../utils/client.js"; |
| 15 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 16 | export interface VerifySchema { |
| 17 | uID: string; |
| 18 | gID: string; |
| 19 | rID: string; |
| 20 | rName: string; |
| 21 | uName: string; |
| 22 | gName: string; |
| 23 | gIcon: string; |
| 24 | interaction: Interaction; |
| 25 | } |
| 26 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 27 | function step(i: number) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 28 | return "\n\n" + createPageIndicator(5, i); |
| 29 | } |
| 30 | |
pineafan | 0f5cc78 | 2022-08-12 21:55:42 +0100 | [diff] [blame] | 31 | export default async function (interaction: CommandInteraction | MessageComponentInteraction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | const verify = client.verify; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 33 | await interaction.reply({ |
| 34 | embeds: LoadingEmbed, |
| 35 | ephemeral: true, |
| 36 | fetchReply: true |
| 37 | }); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 38 | const config = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 39 | 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({ |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 46 | text: (interaction.member!.permissions as Permissions).has("MANAGE_GUILD") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 47 | ? "You can enable it by running /settings verify" |
| 48 | : "" |
| 49 | }) |
| 50 | .setStatus("Danger") |
| 51 | .setEmoji("CONTROL.BLOCKCROSS") |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 52 | ] |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 53 | }); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 54 | if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 55 | return await interaction.editReply({ |
| 56 | embeds: [ |
| 57 | new EmojiEmbed() |
| 58 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 59 | .setDescription(`You already have the <@&${config.verify.role}> role` + step(0)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 60 | .setStatus("Danger") |
| 61 | .setEmoji("CONTROL.BLOCKCROSS") |
| 62 | ] |
| 63 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 64 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 65 | await interaction.editReply({ |
| 66 | embeds: [ |
| 67 | new EmojiEmbed() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 68 | .setTitle("Verify") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 69 | .setDescription("Checking our servers are up" + step(0)) |
| 70 | .setStatus("Warning") |
| 71 | .setEmoji("NUCLEUS.LOADING") |
| 72 | ] |
| 73 | }); |
| 74 | try { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 75 | const status = await fetch(client.config.baseUrl).then((res) => res.status); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 76 | if (status !== 200) { |
| 77 | return await interaction.editReply({ |
| 78 | embeds: [ |
| 79 | new EmojiEmbed() |
| 80 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 81 | .setDescription("Our servers appear to be down, please try again later" + step(0)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 82 | .setStatus("Danger") |
| 83 | .setEmoji("CONTROL.BLOCKCROSS") |
| 84 | ] |
| 85 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 86 | } |
| 87 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 88 | return await interaction.editReply({ |
| 89 | embeds: [ |
| 90 | new EmojiEmbed() |
| 91 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 92 | .setDescription("Our servers appear to be down, please try again later" + step(0)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 93 | .setStatus("Danger") |
| 94 | .setEmoji("CONTROL.BLOCKCROSS") |
| 95 | ], |
| 96 | components: [ |
| 97 | new Discord.MessageActionRow().addComponents([ |
| 98 | new Discord.MessageButton() |
| 99 | .setLabel("Check webpage") |
| 100 | .setStyle("LINK") |
| 101 | .setURL(client.config.baseUrl), |
| 102 | new Discord.MessageButton() |
| 103 | .setLabel("Support") |
| 104 | .setStyle("LINK") |
| 105 | .setURL("https://discord.gg/bPaNnxe") |
| 106 | ]) |
| 107 | ] |
| 108 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 109 | } |
| 110 | if (config.filters.images.NSFW) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 111 | await interaction.editReply({ |
| 112 | embeds: [ |
| 113 | new EmojiEmbed() |
| 114 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 115 | .setDescription("Checking your avatar is safe for work" + step(1)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 116 | .setStatus("Warning") |
| 117 | .setEmoji("NUCLEUS.LOADING") |
| 118 | ] |
| 119 | }); |
| 120 | if ( |
| 121 | await NSFWCheck( |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 122 | (interaction.member as GuildMember).user.displayAvatarURL({ |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 123 | format: "png" |
| 124 | }) |
| 125 | ) |
| 126 | ) { |
| 127 | return await interaction.editReply({ |
| 128 | embeds: [ |
| 129 | new EmojiEmbed() |
| 130 | .setTitle("Verify") |
| 131 | .setDescription( |
| 132 | "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" + |
| 133 | step(1) |
| 134 | ) |
| 135 | .setStatus("Danger") |
| 136 | .setEmoji("CONTROL.BLOCKCROSS") |
| 137 | ] |
| 138 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | if (config.filters.wordFilter) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 142 | await interaction.editReply({ |
| 143 | embeds: [ |
| 144 | new EmojiEmbed() |
| 145 | .setTitle("Verify") |
| 146 | .setDescription("Checking your name is allowed" + step(2)) |
| 147 | .setStatus("Warning") |
| 148 | .setEmoji("NUCLEUS.LOADING") |
| 149 | ] |
| 150 | }); |
| 151 | if ( |
| 152 | TestString( |
| 153 | (interaction.member as Discord.GuildMember).displayName, |
| 154 | config.filters.wordFilter.words.loose, |
| 155 | config.filters.wordFilter.words.strict |
| 156 | ) !== null |
| 157 | ) { |
| 158 | return await interaction.editReply({ |
| 159 | embeds: [ |
| 160 | new EmojiEmbed() |
| 161 | .setTitle("Verify") |
| 162 | .setDescription( |
| 163 | "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" + |
| 164 | step(2) |
| 165 | ) |
| 166 | .setStatus("Danger") |
| 167 | .setEmoji("CONTROL.BLOCKCROSS") |
| 168 | ] |
| 169 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 170 | } |
| 171 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 172 | await interaction.editReply({ |
| 173 | embeds: [ |
| 174 | new EmojiEmbed() |
| 175 | .setTitle("Verify") |
| 176 | .setDescription("One moment..." + step(3)) |
| 177 | .setStatus("Warning") |
| 178 | .setEmoji("NUCLEUS.LOADING") |
| 179 | ] |
| 180 | }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 181 | let code = ""; |
| 182 | let length = 5; |
| 183 | let itt = 0; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 184 | const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 185 | do { |
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 (itt > 1000) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 192 | itt = 0; |
| 193 | length += 1; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 194 | } |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 195 | } while (code in verify); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 196 | const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role); |
| 197 | if (!role) { |
| 198 | await interaction.editReply({ |
| 199 | embeds: [ |
| 200 | new EmojiEmbed() |
| 201 | .setTitle("Verify") |
| 202 | .setDescription( |
| 203 | "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." + |
| 204 | step(4) |
| 205 | ) |
| 206 | .setStatus("Danger") |
| 207 | .setEmoji("CONTROL.BLOCKCROSS") |
| 208 | ] |
| 209 | }); |
| 210 | return; // TODO: SEN |
| 211 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 212 | verify[code] = { |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 213 | uID: interaction.member!.user.id, |
| 214 | gID: interaction.guild!.id, |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 215 | rID: config.verify.role, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 216 | rName: role.name, |
| 217 | uName: interaction.member!.user.username, |
| 218 | gName: interaction.guild!.name, |
| 219 | gIcon: interaction.guild!.iconURL({ format: "png" }), |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 220 | interaction: interaction |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 221 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 222 | await interaction.editReply({ |
| 223 | embeds: [ |
| 224 | new EmojiEmbed() |
| 225 | .setTitle("Verify") |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 226 | .setDescription("Looking good!\nClick the button below to get verified." + step(4)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 227 | .setStatus("Success") |
| 228 | .setEmoji("MEMBER.JOIN") |
| 229 | ], |
| 230 | components: [ |
| 231 | new Discord.MessageActionRow().addComponents([ |
| 232 | new Discord.MessageButton() |
| 233 | .setLabel("Verify") |
| 234 | .setStyle("LINK") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 235 | .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 236 | ]) |
| 237 | ] |
| 238 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 239 | } |