PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 1 | import { LoadingEmbed, unknownServerIcon } from "../utils/defaults.js"; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 2 | import Discord, { |
| 3 | CommandInteraction, |
| 4 | GuildMember, |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 5 | MessageComponentInteraction, |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 6 | Role, |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 7 | ButtonStyle, |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 8 | PermissionsBitField, |
| 9 | ButtonInteraction |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 10 | } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 11 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 12 | import fetch from "node-fetch"; |
| 13 | import { TestString, NSFWCheck } from "./scanners.js"; |
| 14 | import createPageIndicator from "../utils/createPageIndicator.js"; |
| 15 | import client from "../utils/client.js"; |
| 16 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 17 | export interface VerifySchema { |
| 18 | uID: string; |
| 19 | gID: string; |
| 20 | rID: string; |
| 21 | rName: string; |
| 22 | uName: string; |
| 23 | gName: string; |
| 24 | gIcon: string; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 25 | interaction: Discord.MessageComponentInteraction; |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 26 | } |
| 27 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 28 | function step(i: number) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 29 | return "\n\n" + createPageIndicator(5, i); |
| 30 | } |
| 31 | |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 32 | export default async function (interaction: CommandInteraction | ButtonInteraction) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 33 | const verify = client.verify; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | await interaction.reply({ |
| 35 | embeds: LoadingEmbed, |
| 36 | ephemeral: true, |
| 37 | fetchReply: true |
| 38 | }); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 39 | const config = await client.database.guilds.read(interaction.guild!.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 40 | if (!config.verify.enabled || !config.verify.role) |
| 41 | return interaction.editReply({ |
| 42 | embeds: [ |
| 43 | new EmojiEmbed() |
| 44 | .setTitle("Verify") |
| 45 | .setDescription("Verify is not enabled on this server") |
| 46 | .setFooter({ |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 47 | text: (interaction.member!.permissions as PermissionsBitField).has("ManageGuild") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 48 | ? "You can enable it by running /settings verify" |
| 49 | : "" |
| 50 | }) |
| 51 | .setStatus("Danger") |
| 52 | .setEmoji("CONTROL.BLOCKCROSS") |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 53 | ] |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 54 | }); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 55 | if ((interaction.member as GuildMember).roles.cache.has(config.verify.role)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 56 | return await interaction.editReply({ |
| 57 | embeds: [ |
| 58 | new EmojiEmbed() |
| 59 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 60 | .setDescription(`You already have the <@&${config.verify.role}> role` + step(0)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 61 | .setStatus("Danger") |
| 62 | .setEmoji("CONTROL.BLOCKCROSS") |
| 63 | ] |
| 64 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 65 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 66 | await interaction.editReply({ |
| 67 | embeds: [ |
| 68 | new EmojiEmbed() |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 69 | .setTitle("Verify") |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 70 | .setDescription("Checking our servers are up" + step(0)) |
| 71 | .setStatus("Warning") |
| 72 | .setEmoji("NUCLEUS.LOADING") |
| 73 | ] |
| 74 | }); |
| 75 | try { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 76 | const status = await fetch(client.config.baseUrl).then((res) => res.status); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 77 | if (status !== 200) { |
| 78 | return await interaction.editReply({ |
| 79 | embeds: [ |
| 80 | new EmojiEmbed() |
| 81 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 82 | .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] | 83 | .setStatus("Danger") |
| 84 | .setEmoji("CONTROL.BLOCKCROSS") |
| 85 | ] |
| 86 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 87 | } |
| 88 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 89 | return await interaction.editReply({ |
| 90 | embeds: [ |
| 91 | new EmojiEmbed() |
| 92 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 93 | .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] | 94 | .setStatus("Danger") |
| 95 | .setEmoji("CONTROL.BLOCKCROSS") |
| 96 | ], |
| 97 | components: [ |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 98 | new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 99 | new Discord.ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | .setLabel("Check webpage") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 101 | .setStyle(ButtonStyle.Link) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 102 | .setURL(client.config.baseUrl), |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 103 | new Discord.ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 104 | .setLabel("Support") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 105 | .setStyle(ButtonStyle.Link) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 106 | .setURL("https://discord.gg/bPaNnxe") |
| 107 | ]) |
| 108 | ] |
| 109 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 110 | } |
| 111 | if (config.filters.images.NSFW) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 112 | await interaction.editReply({ |
| 113 | embeds: [ |
| 114 | new EmojiEmbed() |
| 115 | .setTitle("Verify") |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 116 | .setDescription("Checking your avatar is safe for work" + step(1)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 117 | .setStatus("Warning") |
| 118 | .setEmoji("NUCLEUS.LOADING") |
| 119 | ] |
| 120 | }); |
| 121 | if ( |
| 122 | await NSFWCheck( |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 123 | (interaction.member as GuildMember).user.displayAvatarURL({extension: "png", forceStatic: true}) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 124 | ) |
| 125 | ) { |
| 126 | return await interaction.editReply({ |
| 127 | embeds: [ |
| 128 | new EmojiEmbed() |
| 129 | .setTitle("Verify") |
| 130 | .setDescription( |
PineaFan | c4d6c3f | 2023-01-19 12:17:25 +0000 | [diff] [blame] | 131 | "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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 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 | } |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 140 | if (config.filters.wordFilter.enabled) { |
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 | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 183 | const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 184 | do { |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame^] | 185 | itt ++; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 186 | code = ""; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 187 | for (let i = 0; i < length; i++) { |
| 188 | code += chars.charAt(Math.floor(Math.random() * chars.length)); |
| 189 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 190 | if (itt > 1000) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 191 | itt = 0; |
TheCodedProf | 4a6d571 | 2023-01-19 15:54:40 -0500 | [diff] [blame^] | 192 | length ++; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 193 | } |
Skyler Grey | f21323a | 2022-08-13 23:58:22 +0100 | [diff] [blame] | 194 | } while (code in verify); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 195 | const role: Role | null = await interaction.guild!.roles.fetch(config.verify.role); |
| 196 | if (!role) { |
| 197 | await interaction.editReply({ |
| 198 | embeds: [ |
| 199 | new EmojiEmbed() |
| 200 | .setTitle("Verify") |
| 201 | .setDescription( |
| 202 | "The server's verify role was deleted, or could not be found. Please contact a staff member to fix this issue." + |
| 203 | step(4) |
| 204 | ) |
| 205 | .setStatus("Danger") |
| 206 | .setEmoji("CONTROL.BLOCKCROSS") |
| 207 | ] |
| 208 | }); |
| 209 | return; // TODO: SEN |
| 210 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 211 | verify[code] = { |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 212 | uID: interaction.member!.user.id, |
| 213 | gID: interaction.guild!.id, |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 214 | rID: config.verify.role, |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 215 | rName: role.name, |
| 216 | uName: interaction.member!.user.username, |
| 217 | gName: interaction.guild!.name, |
PineaFan | 0d06edc | 2023-01-17 22:10:31 +0000 | [diff] [blame] | 218 | gIcon: interaction.guild!.iconURL({ extension: "png", size: 256 }) ?? unknownServerIcon, |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 219 | interaction: interaction as MessageComponentInteraction |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 220 | }; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 221 | await interaction.editReply({ |
| 222 | embeds: [ |
| 223 | new EmojiEmbed() |
| 224 | .setTitle("Verify") |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 225 | .setDescription("Looking good!\nClick the button below to get verified." + step(4)) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 226 | .setStatus("Success") |
| 227 | .setEmoji("MEMBER.JOIN") |
| 228 | ], |
| 229 | components: [ |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 230 | new Discord.ActionRowBuilder<Discord.ButtonBuilder>().addComponents([ |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 231 | new Discord.ButtonBuilder() |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 232 | .setLabel("Verify") |
TheCodedProf | 21c0859 | 2022-09-13 14:14:43 -0400 | [diff] [blame] | 233 | .setStyle(ButtonStyle.Link) |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 234 | .setURL(`${client.config.baseUrl}nucleus/verify?code=${code}`) |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 235 | ]) |
| 236 | ] |
| 237 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 238 | } |