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 | }); |
| 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 |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame] | 25 | // if (!element.safe) return "UNSAFE" |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 26 | return undefined |
| 27 | }).filter(element => element !== undefined) |
| 28 | return detectionsTypes.length > 0 |
| 29 | } |
| 30 | |
| 31 | export async function NSFWCheck(element): Promise<boolean> { |
| 32 | try { |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 33 | let test = (await scan.testNSFW(element)) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 34 | //@ts-ignore |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 35 | return test.nsfw |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 36 | } catch { |
| 37 | return false |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | export 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 |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 44 | return true |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | export async function MalwareCheck(element): Promise<boolean> { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 48 | try { |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 49 | //@ts-ignore |
| 50 | return (await scan.testMalware(element)).safe |
| 51 | } catch { |
| 52 | return true |
| 53 | } |
| 54 | } |
| 55 | |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 56 | export function TestString(string, soft, strict): object | null { |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 57 | for(let word of strict || []) { |
| 58 | if (string.toLowerCase().includes(word)) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 59 | return {word: word, type: "strict"} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | for(let word of soft) { |
| 63 | for(let word2 of string.match(/[a-z]+/gi) || []) { |
| 64 | if (word2 == word) { |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 65 | return {word: word, type: "strict"} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 69 | return null |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame] | 70 | } |
| 71 | |
pineafan | da6e534 | 2022-07-03 10:03:16 +0100 | [diff] [blame^] | 72 | export async function TestImage(element): Promise<string | null> { |
| 73 | return null; |
pineafan | 34369e6 | 2022-05-18 16:52:37 +0100 | [diff] [blame] | 74 | } |