blob: d1fa7d41cfe53dc7e234f22d8a84f778aae10070 [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001import * as scan from '../utils/scanners.js'
2
3export async function LinkCheck(message): Promise<boolean> {
4 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) ?? []
5 let detections = []
6 const promises = links.map(async element => {
7 try {
pineafan377794f2022-04-18 19:01:01 +01008 if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug
pineafan4edb7762022-06-26 19:21:04 +01009 console.log(1.1)
pineafan32767212022-03-14 21:27:39 +000010 element = await scan.testLink(element)
pineafan4edb7762022-06-26 19:21:04 +010011 console.log(1.2)
pineafan32767212022-03-14 21:27:39 +000012 } catch {}
13 detections.push({tags: element.tags || [], safe: element.safe})
14 });
15 await Promise.all(promises);
16 let types = [
17 "PHISHING", "DATING", "TRACKERS", "ADVERTISEMENTS", "FACEBOOK",
18 "AMP", "FACEBOOK TRACKERS", "IP GRABBERS", "PORN",
19 "GAMBLING", "MALWARE", "PIRACY", "RANSOMWARE",
20 "REDIRECTS", "SCAMS", "TORRENT", "HATE", "JUNK"
21 ]
22 let detectionsTypes = detections.map(element => {
23 let type = types.find(type => element.tags.includes(type))
24 if (type) return type
pineafan4edb7762022-06-26 19:21:04 +010025 // if (!element.safe) return "UNSAFE"
pineafan32767212022-03-14 21:27:39 +000026 return undefined
27 }).filter(element => element !== undefined)
28 return detectionsTypes.length > 0
29}
30
31export async function NSFWCheck(element): Promise<boolean> {
32 try {
pineafan377794f2022-04-18 19:01:01 +010033 let test = (await scan.testNSFW(element))
pineafan32767212022-03-14 21:27:39 +000034 //@ts-ignore
pineafan377794f2022-04-18 19:01:01 +010035 return test.nsfw
pineafan32767212022-03-14 21:27:39 +000036 } catch {
37 return false
38 }
39}
40
41export async function SizeCheck(element): Promise<boolean> {
42 if (element.height == undefined || element.width == undefined) return true
43 if (element.height < 20 || element.width < 20) return false
pineafane625d782022-05-09 18:04:32 +010044 return true
pineafan32767212022-03-14 21:27:39 +000045}
46
47export async function MalwareCheck(element): Promise<boolean> {
pineafane625d782022-05-09 18:04:32 +010048 try {
pineafan32767212022-03-14 21:27:39 +000049 //@ts-ignore
50 return (await scan.testMalware(element)).safe
51 } catch {
52 return true
53 }
54}
55
pineafanda6e5342022-07-03 10:03:16 +010056export function TestString(string, soft, strict): object | null {
pineafan32767212022-03-14 21:27:39 +000057 for(let word of strict || []) {
58 if (string.toLowerCase().includes(word)) {
pineafanda6e5342022-07-03 10:03:16 +010059 return {word: word, type: "strict"}
pineafan32767212022-03-14 21:27:39 +000060 }
61 }
62 for(let word of soft) {
63 for(let word2 of string.match(/[a-z]+/gi) || []) {
64 if (word2 == word) {
pineafanda6e5342022-07-03 10:03:16 +010065 return {word: word, type: "strict"}
pineafan32767212022-03-14 21:27:39 +000066 }
67 }
68 }
pineafanda6e5342022-07-03 10:03:16 +010069 return null
pineafan377794f2022-04-18 19:01:01 +010070}
71
pineafanda6e5342022-07-03 10:03:16 +010072export async function TestImage(element): Promise<string | null> {
73 return null;
pineafan34369e62022-05-18 16:52:37 +010074}