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