More accurate nsfw domain check

This commit is contained in:
Dragon Fire
2021-04-03 19:50:05 -04:00
parent 07db7d5325
commit b6bf3e4bfa
4 changed files with 33 additions and 18 deletions
+3 -13
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { URL } = require('url');
const { isImageNSFW } = require('../../util/Util');
const { isImageNSFW, isUrlNSFW } = require('../../util/Util');
module.exports = class ScreenshotCommand extends Command {
constructor(client) {
@@ -36,18 +36,8 @@ module.exports = class ScreenshotCommand extends Command {
async run(msg, { url }) {
try {
if (!msg.channel.nsfw) {
let nsfw;
if (this.client.adultSiteList.includes(url.host)) {
nsfw = true;
} else {
try {
const { url: newURL } = await request.get(url);
const parsedNewURL = new URL(newURL);
if (this.client.adultSiteList.includes(parsedNewURL.host)) nsfw = true;
} catch {
return msg.reply('This site did not respond, or sent an error.');
}
}
const nsfw = await isUrlNSFW(url.href);
if (nsfw === null) return msg.reply('This site did not respond, or sent an error.');
if (nsfw) return msg.reply('This site is NSFW.');
}
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${url.href}`);