blob: d3a2a18744564f083fcc6c38644557674fa2ebfb [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import * as scan from '../utils/scanners.js'
pineafan34369e62022-05-18 16:52:37 +01002import process from 'tesseract.js'
pineafan32767212022-03-14 21:27:39 +00003
4export async function LinkCheck(message): Promise<boolean> {
5 let links = message.content.match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi) ?? []
6 let detections = []
7 const promises = links.map(async element => {
8 try {
pineafan377794f2022-04-18 19:01:01 +01009 if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug
pineafan32767212022-03-14 21:27:39 +000010 element = await scan.testLink(element)
11 } catch {}
12 detections.push({tags: element.tags || [], safe: element.safe})
13 });
14 await Promise.all(promises);
15 let types = [
16 "PHISHING", "DATING", "TRACKERS", "ADVERTISEMENTS", "FACEBOOK",
17 "AMP", "FACEBOOK TRACKERS", "IP GRABBERS", "PORN",
18 "GAMBLING", "MALWARE", "PIRACY", "RANSOMWARE",
19 "REDIRECTS", "SCAMS", "TORRENT", "HATE", "JUNK"
20 ]
21 let detectionsTypes = detections.map(element => {
22 let type = types.find(type => element.tags.includes(type))
23 if (type) return type
24 if (!element.safe) return "UNSAFE"
25 return undefined
26 }).filter(element => element !== undefined)
27 return detectionsTypes.length > 0
28}
29
30export async function NSFWCheck(element): Promise<boolean> {
31 try {
pineafan377794f2022-04-18 19:01:01 +010032 let test = (await scan.testNSFW(element))
pineafan32767212022-03-14 21:27:39 +000033 //@ts-ignore
pineafan377794f2022-04-18 19:01:01 +010034 return test.nsfw
pineafan32767212022-03-14 21:27:39 +000035 } catch {
36 return false
37 }
38}
39
40export async function SizeCheck(element): Promise<boolean> {
41 if (element.height == undefined || element.width == undefined) return true
42 if (element.height < 20 || element.width < 20) return false
pineafane625d782022-05-09 18:04:32 +010043 return true
pineafan32767212022-03-14 21:27:39 +000044}
45
46export async function MalwareCheck(element): Promise<boolean> {
pineafane625d782022-05-09 18:04:32 +010047 try {
pineafan32767212022-03-14 21:27:39 +000048 //@ts-ignore
49 return (await scan.testMalware(element)).safe
50 } catch {
51 return true
52 }
53}
54
55export function TestString(string, soft, strict): string {
56 for(let word of strict || []) {
57 if (string.toLowerCase().includes(word)) {
58 return "strict"
59 }
60 }
61 for(let word of soft) {
62 for(let word2 of string.match(/[a-z]+/gi) || []) {
63 if (word2 == word) {
64 return "loose"
65 }
66 }
67 }
68 return "none"
pineafan377794f2022-04-18 19:01:01 +010069}
70
71export async function TestImage(element): Promise<string> {
72 return "";
pineafan34369e62022-05-18 16:52:37 +010073}