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