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 { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 8 | if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 9 | console.log(1.1) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 10 | element = await scan.testLink(element) |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 11 | console.log(1.2) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 12 | } catch {} |
| 13 | detections.push({tags: element.tags || [], safe: element.safe}) |
| 14 | }); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 15 | console.log(1) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 16 | await Promise.all(promises); |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 17 | console.log(2) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 18 | 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 |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 27 | // if (!element.safe) return "UNSAFE" |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 28 | return undefined |
| 29 | }).filter(element => element !== undefined) |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 30 | console.log(detectionsTypes) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 31 | return detectionsTypes.length > 0 |
| 32 | } |
| 33 | |
| 34 | export async function NSFWCheck(element): Promise<boolean> { |
| 35 | try { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 36 | let test = (await scan.testNSFW(element)) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 37 | //@ts-ignore |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 38 | return test.nsfw |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 39 | } catch { |
| 40 | return false |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 47 | return true |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | export async function MalwareCheck(element): Promise<boolean> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 51 | try { |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 52 | //@ts-ignore |
| 53 | return (await scan.testMalware(element)).safe |
| 54 | } catch { |
| 55 | return true |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | export 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" |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | export async function TestImage(element): Promise<string> { |
| 76 | return ""; |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 77 | } |