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