diff --git a/commands/search/flickr.js b/commands/search/flickr.js index ee8bffef..e23b981a 100644 --- a/commands/search/flickr.js +++ b/commands/search/flickr.js @@ -1,5 +1,6 @@ const Command = require('../../structures/Command'); const request = require('node-superfetch'); +const { isImageNSFW } = require('../../util/Util'); const { FLICKR_KEY } = process.env; module.exports = class FlickrCommand extends Command { @@ -8,8 +9,7 @@ module.exports = class FlickrCommand extends Command { name: 'flickr', group: 'search', memberName: 'flickr', - description: 'Searches Flickr for your query... Maybe.', - nsfw: true, + description: 'Searches Flickr for your query.', credit: [ { name: 'Flickr', @@ -41,7 +41,13 @@ module.exports = class FlickrCommand extends Command { }); if (!body.photos.photo.length) return msg.say('Could not find any results.'); const data = body.photos.photo[Math.floor(Math.random() * body.photos.photo.length)]; - return msg.say(`https://farm${data.farm}.staticflickr.com/${data.server}/${data.id}_${data.secret}.jpg`); + const url = `https://farm${data.farm}.staticflickr.com/${data.server}/${data.id}_${data.secret}.jpg`; + if (!msg.channel.nsfw) { + const { body: imageBody } = await request.get(url); + const aiDetect = await isImageNSFW(this.client.nsfwModel, imageBody); + if (aiDetect) return msg.reply('Found an NSFW image. Sorry, please try again.'); + } + return msg.say(url); } catch (err) { return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); }