From 7380f6ecf3d61d72bafff8e845efc2b23872d5b9 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 8 May 2024 00:39:57 -0400 Subject: [PATCH] Add wikipedia images --- commands/search/wikipedia.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index d8c5bced..3743248a 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -34,7 +34,7 @@ module.exports = class WikipediaCommand extends Command { .get('https://en.wikipedia.org/w/api.php') .query({ action: 'query', - prop: 'extracts', + prop: 'extracts|pageimages', format: 'json', titles: query, exintro: '', @@ -44,11 +44,18 @@ module.exports = class WikipediaCommand extends Command { }); const data = body.query.pages[0]; if (data.missing) return msg.say('Could not find any results.'); + let thumbnail = data.thumbnail ? data.thumbnail.source : null; + if (!msg.channel.nsfw && thumbnail) { + const img = await request.get(data.thumbnail.source); + const nsfw = this.client.tensorflow.isImageNSFW(img.body); + if (nsfw) thumbnail = null; + } const embed = new EmbedBuilder() .setColor(0xE7E7E7) .setTitle(data.title) .setAuthor({ name: 'Wikipedia', iconURL: logos.wikipedia, url: 'https://www.wikipedia.org/' }) .setURL(`https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`) + .setThumbnail(thumbnail) .setDescription(shorten(data.extract.replaceAll('\n', '\n\n'))); return msg.embed(embed); }