blob: 940a1feefefa447884f8ea82fea5ce408f84a0d1 [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 });
pineafan4edb7762022-06-26 19:21:04 +010015 console.log(1)
pineafan32767212022-03-14 21:27:39 +000016 await Promise.all(promises);
pineafan4edb7762022-06-26 19:21:04 +010017 console.log(2)
pineafan32767212022-03-14 21:27:39 +000018 let types = [
19 "PHISHING", "DATING", "TRACKERS", "ADVERTISEMENTS", "FACEBOOK",
20 "AMP", "FACEBOOK TRACKERS", "IP GRABBERS", "PORN",
21 "GAMBLING", "MALWARE", "PIRACY", "RANSOMWARE",
22 "REDIRECTS", "SCAMS", "TORRENT", "HATE", "JUNK"
23 ]
24 let detectionsTypes = detections.map(element => {
25 let type = types.find(type => element.tags.includes(type))
26 if (type) return type
pineafan4edb7762022-06-26 19:21:04 +010027 // if (!element.safe) return "UNSAFE"
pineafan32767212022-03-14 21:27:39 +000028 return undefined
29 }).filter(element => element !== undefined)
pineafan4edb7762022-06-26 19:21:04 +010030 console.log(detectionsTypes)
pineafan32767212022-03-14 21:27:39 +000031 return detectionsTypes.length > 0
32}
33
34export async function NSFWCheck(element): Promise<boolean> {
35 try {
pineafan377794f2022-04-18 19:01:01 +010036 let test = (await scan.testNSFW(element))
pineafan32767212022-03-14 21:27:39 +000037 //@ts-ignore
pineafan377794f2022-04-18 19:01:01 +010038 return test.nsfw
pineafan32767212022-03-14 21:27:39 +000039 } catch {
40 return false
41 }
42}
43
44export async function SizeCheck(element): Promise<boolean> {
45 if (element.height == undefined || element.width == undefined) return true
46 if (element.height < 20 || element.width < 20) return false
pineafane625d782022-05-09 18:04:32 +010047 return true
pineafan32767212022-03-14 21:27:39 +000048}
49
50export async function MalwareCheck(element): Promise<boolean> {
pineafane625d782022-05-09 18:04:32 +010051 try {
pineafan32767212022-03-14 21:27:39 +000052 //@ts-ignore
53 return (await scan.testMalware(element)).safe
54 } catch {
55 return true
56 }
57}
58
59export function TestString(string, soft, strict): string {
60 for(let word of strict || []) {
61 if (string.toLowerCase().includes(word)) {
62 return "strict"
63 }
64 }
65 for(let word of soft) {
66 for(let word2 of string.match(/[a-z]+/gi) || []) {
67 if (word2 == word) {
68 return "loose"
69 }
70 }
71 }
72 return "none"
pineafan377794f2022-04-18 19:01:01 +010073}
74
75export async function TestImage(element): Promise<string> {
76 return "";
pineafan34369e62022-05-18 16:52:37 +010077}