pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import * as scan from '../utils/scanners.js' |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame^] | 2 | import process from 'tesseract.js' |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 3 | |
| 4 | export 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 { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 9 | if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | 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 | |
| 30 | export async function NSFWCheck(element): Promise<boolean> { |
| 31 | try { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 32 | let test = (await scan.testNSFW(element)) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 33 | //@ts-ignore |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 34 | return test.nsfw |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 35 | } catch { |
| 36 | return false |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | export 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 43 | return true |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | export async function MalwareCheck(element): Promise<boolean> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 47 | try { |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 48 | //@ts-ignore |
| 49 | return (await scan.testMalware(element)).safe |
| 50 | } catch { |
| 51 | return true |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export 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" |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | export async function TestImage(element): Promise<string> { |
| 72 | return ""; |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame^] | 73 | } |