pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import fetch from "node-fetch"; |
Skyler Grey | 3217998 | 2023-03-07 23:59:06 +0000 | [diff] [blame] | 2 | import { writeFileSync } from "fs"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 3 | import generateFileName from "../utils/temp/generateFileName.js"; |
| 4 | import Tesseract from "node-tesseract-ocr"; |
| 5 | import type Discord from "discord.js"; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 6 | import client from "../utils/client.js"; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 7 | import { createHash } from "crypto"; |
Skyler Grey | 3217998 | 2023-03-07 23:59:06 +0000 | [diff] [blame] | 8 | import * as nsfwjs from "nsfwjs"; |
Skyler Grey | 0a4846c | 2023-03-08 00:32:01 +0000 | [diff] [blame^] | 9 | import ClamScan from "clamscan"; |
Skyler Grey | 62da9bf | 2023-03-08 00:11:00 +0000 | [diff] [blame] | 10 | import * as tf from "@tensorflow/tfjs-node"; |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 11 | import EmojiEmbed from "../utils/generateEmojiEmbed.js"; |
| 12 | import getEmojiByName from "../utils/getEmojiByName.js"; |
| 13 | import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js"; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 14 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | interface NSFWSchema { |
| 16 | nsfw: boolean; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 17 | errored?: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 18 | } |
| 19 | interface MalwareSchema { |
| 20 | safe: boolean; |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 21 | errored?: boolean; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | } |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 23 | |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 24 | const nsfw_model = await nsfwjs.load(); |
Skyler Grey | 0a4846c | 2023-03-08 00:32:01 +0000 | [diff] [blame^] | 25 | const clamscanner = await new ClamScan().init({}); |
TheCodedProf | d8ef1f3 | 2023-03-06 19:15:18 -0500 | [diff] [blame] | 26 | |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 27 | export async function testNSFW(link: string): Promise<NSFWSchema> { |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 28 | const [fileStream, hash] = await streamAttachment(link); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 29 | const alreadyHaveCheck = await client.database.scanCache.read(hash); |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 30 | if (alreadyHaveCheck?.nsfw) return { nsfw: alreadyHaveCheck.nsfw }; |
TheCodedProf | d8ef1f3 | 2023-03-06 19:15:18 -0500 | [diff] [blame] | 31 | |
Skyler Grey | 3217998 | 2023-03-07 23:59:06 +0000 | [diff] [blame] | 32 | const image = tf.tensor3d(new Uint8Array(fileStream)); |
TheCodedProf | d8ef1f3 | 2023-03-06 19:15:18 -0500 | [diff] [blame] | 33 | |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 34 | const predictions = (await nsfw_model.classify(image, 1))[0]!; |
| 35 | image.dispose(); |
TheCodedProf | d8ef1f3 | 2023-03-06 19:15:18 -0500 | [diff] [blame] | 36 | |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 37 | return { nsfw: predictions.className === "Hentai" || predictions.className === "Porn" }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 38 | } |
| 39 | |
pineafan | 02ba023 | 2022-07-24 22:16:15 +0100 | [diff] [blame] | 40 | export async function testMalware(link: string): Promise<MalwareSchema> { |
Skyler Grey | 0a4846c | 2023-03-08 00:32:01 +0000 | [diff] [blame^] | 41 | const [fileName, hash] = await saveAttachment(link); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 42 | const alreadyHaveCheck = await client.database.scanCache.read(hash); |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 43 | if (alreadyHaveCheck?.malware) return { safe: alreadyHaveCheck.malware }; |
Skyler Grey | 0a4846c | 2023-03-08 00:32:01 +0000 | [diff] [blame^] | 44 | let safe; |
| 45 | try { |
| 46 | safe = !(await clamscanner.scanFile(fileName)).isInfected; |
| 47 | } catch (e) { |
| 48 | return { safe: true }; |
| 49 | } |
| 50 | client.database.scanCache.write(hash, "malware", safe); |
| 51 | return { safe }; |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | export async function testLink(link: string): Promise<{ safe: boolean; tags: string[] }> { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 55 | const alreadyHaveCheck = await client.database.scanCache.read(link); |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 56 | if (alreadyHaveCheck?.bad_link) return { safe: alreadyHaveCheck.bad_link, tags: alreadyHaveCheck.tags }; |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 57 | const scanned: { safe?: boolean; tags?: string[] } = await fetch("https://unscan.p.rapidapi.com/link", { |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 58 | method: "POST", |
| 59 | headers: { |
| 60 | "X-RapidAPI-Key": client.config.rapidApiKey, |
| 61 | "X-RapidAPI-Host": "unscan.p.rapidapi.com" |
| 62 | }, |
| 63 | body: `{"link":"${link}"}` |
| 64 | }) |
| 65 | .then((response) => response.json() as Promise<MalwareSchema>) |
| 66 | .catch((err) => { |
| 67 | console.error(err); |
| 68 | return { safe: true, tags: [] }; |
| 69 | }); |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 70 | client.database.scanCache.write(link, "bad_link", scanned.safe ?? true, scanned.tags ?? []); |
pineafan | 3a02ea3 | 2022-08-11 21:35:04 +0100 | [diff] [blame] | 71 | return { |
| 72 | safe: scanned.safe ?? true, |
| 73 | tags: scanned.tags ?? [] |
| 74 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 77 | export async function streamAttachment(link: string): Promise<[ArrayBuffer, string]> { |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 78 | const image = await (await fetch(link)).arrayBuffer(); |
Skyler Grey | 3217998 | 2023-03-07 23:59:06 +0000 | [diff] [blame] | 79 | const enc = new TextDecoder("utf-8"); |
| 80 | return [image, createHash("sha512").update(enc.decode(image), "base64").digest("base64")]; |
| 81 | } |
| 82 | |
| 83 | export async function saveAttachment(link: string): Promise<[string, string]> { |
| 84 | const image = await (await fetch(link)).arrayBuffer(); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 85 | const fileName = generateFileName(link.split("/").pop()!.split(".").pop()!); |
TheCodedProf | 5b53a8c | 2023-02-03 15:40:26 -0500 | [diff] [blame] | 86 | const enc = new TextDecoder("utf-8"); |
| 87 | writeFileSync(fileName, new DataView(image), "base64"); |
Skyler Grey | 3217998 | 2023-03-07 23:59:06 +0000 | [diff] [blame] | 88 | return [fileName, createHash("sha512").update(enc.decode(image), "base64").digest("base64")]; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 89 | } |
| 90 | |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 91 | const linkTypes = { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 92 | PHISHING: "Links designed to trick users into clicking on them.", |
| 93 | DATING: "Dating sites.", |
| 94 | TRACKERS: "Websites that store or track personal information.", |
| 95 | ADVERTISEMENTS: "Websites only for ads.", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 96 | FACEBOOK: "Facebook pages. (Facebook has a number of dangerous trackers. Read more on /privacy)", |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 97 | AMP: "AMP pages. (AMP is a technology that allows websites to be served by Google. Read more on /privacy)", |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 98 | "FACEBOOK TRACKERS": "Websites that include trackers from Facebook.", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 99 | "IP GRABBERS": "Websites that store your IP address, which shows your approximate location.", |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 100 | PORN: "Websites that include pornography.", |
| 101 | GAMBLING: "Gambling sites, often scams.", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 102 | MALWARE: "Websites which download files designed to break or slow down your device.", |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 103 | PIRACY: "Sites which include illegally downloaded material.", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 104 | RANSOMWARE: "Websites which download a program that can steal your data and make you pay to get it back.", |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 105 | REDIRECTS: "Sites like bit.ly which could redirect to a malicious site.", |
| 106 | SCAMS: "Sites which are designed to trick you into doing something.", |
| 107 | TORRENT: "Websites that download torrent files.", |
| 108 | HATE: "Websites that spread hate towards groups or individuals.", |
| 109 | JUNK: "Websites that are designed to make you waste time." |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 110 | }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 111 | export { linkTypes }; |
| 112 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 113 | export async function LinkCheck(message: Discord.Message): Promise<string[]> { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 114 | const links = |
| 115 | message.content.match( |
| 116 | /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi |
| 117 | ) ?? []; |
| 118 | const detections: { tags: string[]; safe: boolean }[] = []; |
| 119 | const promises: Promise<void>[] = links.map(async (element) => { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 120 | let returned; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 121 | try { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 122 | if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return; // Also matches discord.net, not enough of a bug |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 123 | returned = await testLink(element); |
| 124 | } catch { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 125 | detections.push({ tags: [], safe: true }); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 126 | return; |
| 127 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 128 | detections.push({ tags: returned.tags, safe: returned.safe }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 129 | }); |
| 130 | await Promise.all(promises); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 131 | const detectionsTypes = detections |
| 132 | .map((element) => { |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 133 | const type = Object.keys(linkTypes).find((type) => element.tags.includes(type)); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 134 | if (type) return type; |
| 135 | // if (!element.safe) return "UNSAFE" |
| 136 | return undefined; |
| 137 | }) |
| 138 | .filter((element) => element !== undefined); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 139 | return detectionsTypes as string[]; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 140 | } |
| 141 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 142 | export async function NSFWCheck(element: string): Promise<boolean> { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 143 | try { |
TheCodedProf | b5e9d55 | 2023-01-29 15:43:26 -0500 | [diff] [blame] | 144 | return (await testNSFW(element)).nsfw; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 145 | } catch { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 146 | return false; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 150 | export async function SizeCheck(element: { height: number | null; width: number | null }): Promise<boolean> { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 151 | if (element.height === null || element.width === null) return true; |
| 152 | if (element.height < 20 || element.width < 20) return false; |
| 153 | return true; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 154 | } |
| 155 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 156 | export async function MalwareCheck(element: string): Promise<boolean> { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 157 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 158 | return (await testMalware(element)).safe; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 159 | } catch { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 160 | return true; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 164 | export function TestString( |
| 165 | string: string, |
| 166 | soft: string[], |
| 167 | strict: string[], |
| 168 | enabled?: boolean |
| 169 | ): { word: string; type: string } | null { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 170 | if (!enabled) return null; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 171 | for (const word of strict) { |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 172 | if (string.toLowerCase().includes(word)) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 173 | return { word: word, type: "strict" }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 174 | } |
| 175 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 176 | for (const word of soft) { |
| 177 | for (const word2 of string.match(/[a-z]+/gi) ?? []) { |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 178 | if (word2 === word) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 179 | return { word: word, type: "soft" }; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 183 | return null; |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 184 | } |
| 185 | |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 186 | export async function TestImage(url: string): Promise<string | null> { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 187 | const text = await Tesseract.recognize(url, { |
| 188 | lang: "eng", |
| 189 | oem: 1, |
| 190 | psm: 3 |
| 191 | }); |
pineafan | 813bdf4 | 2022-07-24 10:39:10 +0100 | [diff] [blame] | 192 | return text; |
| 193 | } |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 194 | |
| 195 | export async function doMemberChecks(member: Discord.GuildMember, guild: Discord.Guild): Promise<void> { |
| 196 | if (member.user.bot) return; |
| 197 | const guildData = await client.database.guilds.read(guild.id); |
| 198 | if (!guildData.logging.staff.channel) return; |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 199 | const [loose, strict] = [guildData.filters.wordFilter.words.loose, guildData.filters.wordFilter.words.strict]; |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 200 | // Does the username contain filtered words |
| 201 | const usernameCheck = TestString(member.user.username, loose, strict, guildData.filters.wordFilter.enabled); |
| 202 | // Does the nickname contain filtered words |
| 203 | const nicknameCheck = TestString(member.nickname ?? "", loose, strict, guildData.filters.wordFilter.enabled); |
| 204 | // Does the profile picture contain filtered words |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 205 | const avatarTextCheck = TestString( |
| 206 | (await TestImage(member.user.displayAvatarURL({ forceStatic: true }))) ?? "", |
| 207 | loose, |
| 208 | strict, |
| 209 | guildData.filters.wordFilter.enabled |
| 210 | ); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 211 | // Is the profile picture NSFW |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 212 | const avatarCheck = |
| 213 | guildData.filters.images.NSFW && (await NSFWCheck(member.user.displayAvatarURL({ forceStatic: true }))); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 214 | // Does the username contain an invite |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 215 | const inviteCheck = guildData.filters.invite.enabled && /discord\.gg\/[a-zA-Z0-9]+/gi.test(member.user.username); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 216 | // Does the nickname contain an invite |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 217 | const nicknameInviteCheck = |
Skyler Grey | 1443271 | 2023-03-07 23:40:50 +0000 | [diff] [blame] | 218 | guildData.filters.invite.enabled && /discord\.gg\/[a-zA-Z0-9]+/gi.test(member.nickname ?? ""); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 219 | |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 220 | if ( |
| 221 | usernameCheck !== null || |
| 222 | nicknameCheck !== null || |
| 223 | avatarCheck || |
| 224 | inviteCheck || |
| 225 | nicknameInviteCheck || |
| 226 | avatarTextCheck !== null |
| 227 | ) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 228 | const infractions = []; |
| 229 | if (usernameCheck !== null) { |
| 230 | infractions.push(`Username contains a ${usernameCheck.type}ly filtered word (${usernameCheck.word})`); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 231 | } |
| 232 | if (nicknameCheck !== null) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 233 | infractions.push(`Nickname contains a ${nicknameCheck.type}ly filtered word (${nicknameCheck.word})`); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 234 | } |
| 235 | if (avatarCheck) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 236 | infractions.push("Profile picture is NSFW"); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 237 | } |
| 238 | if (inviteCheck) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 239 | infractions.push("Username contains an invite"); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 240 | } |
| 241 | if (nicknameInviteCheck) { |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 242 | infractions.push("Nickname contains an invite"); |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 243 | } |
| 244 | if (avatarTextCheck !== null) { |
| 245 | infractions.push( |
| 246 | `Profile picture contains a ${avatarTextCheck.type}ly filtered word: ${avatarTextCheck.word}` |
| 247 | ); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 248 | } |
| 249 | if (infractions.length === 0) return; |
| 250 | // This is bad - Warn in the staff notifications channel |
| 251 | const filter = getEmojiByName("ICONS.FILTER"); |
| 252 | const channel = guild.channels.cache.get(guildData.logging.staff.channel) as Discord.TextChannel; |
| 253 | const embed = new EmojiEmbed() |
| 254 | .setTitle("Member Flagged") |
| 255 | .setEmoji("ICONS.FLAGS.RED") |
| 256 | .setStatus("Danger") |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 257 | .setDescription( |
| 258 | `**Member:** ${member.user.username} (<@${member.user.id}>)\n\n` + |
| 259 | infractions.map((element) => `${filter} ${element}`).join("\n") |
| 260 | ); |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 261 | await channel.send({ |
| 262 | embeds: [embed], |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 263 | components: [ |
| 264 | new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 265 | ...[ |
| 266 | new ButtonBuilder() |
| 267 | .setCustomId(`mod:warn:${member.user.id}`) |
| 268 | .setLabel("Warn") |
| 269 | .setStyle(ButtonStyle.Primary), |
| 270 | new ButtonBuilder() |
| 271 | .setCustomId(`mod:mute:${member.user.id}`) |
| 272 | .setLabel("Mute") |
| 273 | .setStyle(ButtonStyle.Primary), |
| 274 | new ButtonBuilder() |
| 275 | .setCustomId(`mod:kick:${member.user.id}`) |
| 276 | .setLabel("Kick") |
| 277 | .setStyle(ButtonStyle.Danger), |
| 278 | new ButtonBuilder() |
| 279 | .setCustomId(`mod:ban:${member.user.id}`) |
| 280 | .setLabel("Ban") |
| 281 | .setStyle(ButtonStyle.Danger) |
| 282 | ].concat( |
| 283 | usernameCheck !== null || nicknameCheck !== null || avatarTextCheck !== null |
| 284 | ? [ |
| 285 | new ButtonBuilder() |
| 286 | .setCustomId(`mod:nickname:${member.user.id}`) |
| 287 | .setLabel("Change Name") |
| 288 | .setStyle(ButtonStyle.Primary) |
| 289 | ] |
| 290 | : [] |
| 291 | ) |
| 292 | ) |
| 293 | ] |
pineafan | 6de4da5 | 2023-03-07 20:43:44 +0000 | [diff] [blame] | 294 | }); |
| 295 | } |
pineafan | 1e462ab | 2023-03-07 21:34:06 +0000 | [diff] [blame] | 296 | } |