pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame^] | 1 | import * as scan from '../utils/scanners.js' |
| 2 | |
| 3 | export 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 { |
| 8 | element = await scan.testLink(element) |
| 9 | } catch {} |
| 10 | detections.push({tags: element.tags || [], safe: element.safe}) |
| 11 | }); |
| 12 | await Promise.all(promises); |
| 13 | let types = [ |
| 14 | "PHISHING", "DATING", "TRACKERS", "ADVERTISEMENTS", "FACEBOOK", |
| 15 | "AMP", "FACEBOOK TRACKERS", "IP GRABBERS", "PORN", |
| 16 | "GAMBLING", "MALWARE", "PIRACY", "RANSOMWARE", |
| 17 | "REDIRECTS", "SCAMS", "TORRENT", "HATE", "JUNK" |
| 18 | ] |
| 19 | let detectionsTypes = detections.map(element => { |
| 20 | let type = types.find(type => element.tags.includes(type)) |
| 21 | if (type) return type |
| 22 | if (!element.safe) return "UNSAFE" |
| 23 | return undefined |
| 24 | }).filter(element => element !== undefined) |
| 25 | return detectionsTypes.length > 0 |
| 26 | } |
| 27 | |
| 28 | export async function NSFWCheck(element): Promise<boolean> { |
| 29 | try { |
| 30 | //@ts-ignore |
| 31 | let test = (await scan.testNSFW(element)).nsfw |
| 32 | return test |
| 33 | } catch { |
| 34 | return false |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | export async function SizeCheck(element): Promise<boolean> { |
| 39 | if (element.height == undefined || element.width == undefined) return true |
| 40 | if (element.height < 20 || element.width < 20) return false |
| 41 | return true |
| 42 | } |
| 43 | |
| 44 | export async function MalwareCheck(element): Promise<boolean> { |
| 45 | try { |
| 46 | //@ts-ignore |
| 47 | return (await scan.testMalware(element)).safe |
| 48 | } catch { |
| 49 | return true |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | export function TestString(string, soft, strict): string { |
| 54 | for(let word of strict || []) { |
| 55 | if (string.toLowerCase().includes(word)) { |
| 56 | return "strict" |
| 57 | } |
| 58 | } |
| 59 | for(let word of soft) { |
| 60 | for(let word2 of string.match(/[a-z]+/gi) || []) { |
| 61 | if (word2 == word) { |
| 62 | return "loose" |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | return "none" |
| 67 | } |