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