blob: 940a1feefefa447884f8ea82fea5ce408f84a0d1 [file] [log] [blame]
import * as scan from '../utils/scanners.js'
export async function LinkCheck(message): Promise<boolean> {
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) ?? []
let detections = []
const promises = links.map(async element => {
try {
if (element.match(/https?:\/\/[a-zA-Z]+\.?discord(app)?\.(com|net)\/?/)) return // Also matches discord.net, not enough of a bug
console.log(1.1)
element = await scan.testLink(element)
console.log(1.2)
} catch {}
detections.push({tags: element.tags || [], safe: element.safe})
});
console.log(1)
await Promise.all(promises);
console.log(2)
let types = [
"PHISHING", "DATING", "TRACKERS", "ADVERTISEMENTS", "FACEBOOK",
"AMP", "FACEBOOK TRACKERS", "IP GRABBERS", "PORN",
"GAMBLING", "MALWARE", "PIRACY", "RANSOMWARE",
"REDIRECTS", "SCAMS", "TORRENT", "HATE", "JUNK"
]
let detectionsTypes = detections.map(element => {
let type = types.find(type => element.tags.includes(type))
if (type) return type
// if (!element.safe) return "UNSAFE"
return undefined
}).filter(element => element !== undefined)
console.log(detectionsTypes)
return detectionsTypes.length > 0
}
export async function NSFWCheck(element): Promise<boolean> {
try {
let test = (await scan.testNSFW(element))
//@ts-ignore
return test.nsfw
} catch {
return false
}
}
export async function SizeCheck(element): Promise<boolean> {
if (element.height == undefined || element.width == undefined) return true
if (element.height < 20 || element.width < 20) return false
return true
}
export async function MalwareCheck(element): Promise<boolean> {
try {
//@ts-ignore
return (await scan.testMalware(element)).safe
} catch {
return true
}
}
export function TestString(string, soft, strict): string {
for(let word of strict || []) {
if (string.toLowerCase().includes(word)) {
return "strict"
}
}
for(let word of soft) {
for(let word2 of string.match(/[a-z]+/gi) || []) {
if (word2 == word) {
return "loose"
}
}
}
return "none"
}
export async function TestImage(element): Promise<string> {
return "";
}