Add wikipedia images

This commit is contained in:
Dragon Fire
2024-05-08 00:39:57 -04:00
parent 31d5ba3779
commit 7380f6ecf3
+8 -1
View File
@@ -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);
}