Fix nsfw site filter matching in screenshot

This commit is contained in:
Dragon Fire
2020-06-21 20:58:33 -04:00
parent efd54a6e35
commit f6e7f0698a
2 changed files with 9 additions and 6 deletions
+8 -5
View File
@@ -1,5 +1,6 @@
const Command = require('../../structures/Command'); const Command = require('../../structures/Command');
const request = require('node-superfetch'); const request = require('node-superfetch');
const url = require('url');
module.exports = class ScreenshotCommand extends Command { module.exports = class ScreenshotCommand extends Command {
constructor(client) { constructor(client) {
@@ -30,9 +31,10 @@ module.exports = class ScreenshotCommand extends Command {
], ],
args: [ args: [
{ {
key: 'url', key: 'site',
prompt: 'What webpage do you want to take a screenshot of?', prompt: 'What webpage do you want to take a screenshot of?',
type: 'string' type: 'string',
parse: site => /^(https?:\/\/)/i.test(site) ? site : `http://${site}`
} }
] ]
}); });
@@ -40,13 +42,14 @@ module.exports = class ScreenshotCommand extends Command {
this.pornList = null; this.pornList = null;
} }
async run(msg, { url }) { async run(msg, { site }) {
try { try {
if (!this.pornList) await this.fetchPornList(); if (!this.pornList) await this.fetchPornList();
if (this.pornList.some(pornURL => url.includes(pornURL)) && !msg.channel.nsfw) { const parsed = url.parse(site);
if (this.pornList.some(pornURL => parsed.host === pornURL) && !msg.channel.nsfw) {
return msg.reply('This site is NSFW.'); return msg.reply('This site is NSFW.');
} }
const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${url}`); const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${site}`);
return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] }); return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] });
} catch (err) { } catch (err) {
if (err.status === 404) return msg.say('Could not find any results. Invalid URL?'); if (err.status === 404) return msg.say('Could not find any results. Invalid URL?');
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "xiao", "name": "xiao",
"version": "116.37.1", "version": "116.37.2",
"description": "Your personal server companion.", "description": "Your personal server companion.",
"main": "Xiao.js", "main": "Xiao.js",
"scripts": { "scripts": {