Use NSFW AI in flickr

This commit is contained in:
Dragon Fire
2021-03-22 19:51:57 -04:00
parent 4b99cd3142
commit f2b4b5b7cd
+9 -3
View File
@@ -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!`);
}