mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +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')
|
.get('https://en.wikipedia.org/w/api.php')
|
||||||
.query({
|
.query({
|
||||||
action: 'query',
|
action: 'query',
|
||||||
prop: 'extracts',
|
prop: 'extracts|pageimages',
|
||||||
format: 'json',
|
format: 'json',
|
||||||
titles: query,
|
titles: query,
|
||||||
exintro: '',
|
exintro: '',
|
||||||
@@ -44,11 +44,18 @@ module.exports = class WikipediaCommand extends Command {
|
|||||||
});
|
});
|
||||||
const data = body.query.pages[0];
|
const data = body.query.pages[0];
|
||||||
if (data.missing) return msg.say('Could not find any results.');
|
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()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(0xE7E7E7)
|
.setColor(0xE7E7E7)
|
||||||
.setTitle(data.title)
|
.setTitle(data.title)
|
||||||
.setAuthor({ name: 'Wikipedia', iconURL: logos.wikipedia, url: 'https://www.wikipedia.org/' })
|
.setAuthor({ name: 'Wikipedia', iconURL: logos.wikipedia, url: 'https://www.wikipedia.org/' })
|
||||||
.setURL(`https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`)
|
.setURL(`https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`)
|
||||||
|
.setThumbnail(thumbnail)
|
||||||
.setDescription(shorten(data.extract.replaceAll('\n', '\n\n')));
|
.setDescription(shorten(data.extract.replaceAll('\n', '\n\n')));
|
||||||
return msg.embed(embed);
|
return msg.embed(embed);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user