mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Add wikipedia images
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user