From 40f34e571e44fecbe6afc6cb2fdcbc40a1e90f3a Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 21 Jun 2020 17:34:41 -0400 Subject: [PATCH] Screenshot NSFW Filter --- README.md | 2 ++ commands/other/screenshot.js | 19 +++++++++++++++++++ package.json | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9bae1875..d05ce199 100644 --- a/README.md +++ b/README.md @@ -886,6 +886,8 @@ here. * skyrim-skill ([Image, Original "The Elder Scrolls V: Skyrim" Game](https://elderscrolls.bethesda.net/en/skyrim)) - [Bitly](https://bitly.com/) * shorten-url ([API](https://dev.bitly.com/v4_documentation.html)) +- [Block List Project](https://blocklist.site/) + * screenshot ([NSFW Site List](https://raw.githubusercontent.com/blocklistproject/Lists/master/porn.txt)) - [Bob Ross](https://www.bobross.com/) * bob-ross (Himself) - [Bowserinator](https://github.com/Bowserinator/) diff --git a/commands/other/screenshot.js b/commands/other/screenshot.js index 85d81270..f5d3d539 100644 --- a/commands/other/screenshot.js +++ b/commands/other/screenshot.js @@ -20,6 +20,12 @@ module.exports = class ScreenshotCommand extends Command { name: 'AzuraApple', url: 'https://github.com/AzuraApple', reason: 'Concept' + }, + { + name: 'Block List Project', + url: 'https://blocklist.site/', + reason: 'NSFW Site List', + reasonURL: 'https://raw.githubusercontent.com/blocklistproject/Lists/master/porn.txt' } ], args: [ @@ -30,10 +36,16 @@ module.exports = class ScreenshotCommand extends Command { } ] }); + + this.pornList = null; } async run(msg, { url }) { try { + if (!this.pornList) await this.fetchPornList(); + if (this.pornList.some(pornURL => url.includes(pornURL)) && !msg.channel.nsfw) { + return msg.reply('This site is NSFW.'); + } const { body } = await request.get(`https://image.thum.io/get/width/1920/crop/675/noanimate/${url}`); return msg.say({ files: [{ attachment: body, name: 'screenshot.png' }] }); } catch (err) { @@ -41,4 +53,11 @@ module.exports = class ScreenshotCommand extends Command { return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); } } + + async fetchPornList(force = false) { + if (!force && this.pornList) return this.pornList; + const { text } = await request.get('https://raw.githubusercontent.com/blocklistproject/Lists/master/porn.txt'); + this.pornList = text.split('\n').filter(url => !url.startsWith('#')).map(url => url.replace(/^(0.0.0.0 )/, '')); + return this.postList; + } }; diff --git a/package.json b/package.json index cdd79dfd..b8d096c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "116.37.0", + "version": "116.37.1", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {