From 3285d6f68e4cce6f5d7850393711c559f714b9d0 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Wed, 8 May 2024 01:15:52 -0400 Subject: [PATCH] Add Disambiguation check to wikipedia --- commands/search/wikipedia.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index cc09b137..baf5cd6e 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -33,11 +33,12 @@ module.exports = class WikipediaCommand extends Command { .get('https://en.wikipedia.org/w/api.php') .query({ action: 'query', - prop: 'extracts|pageimages', + prop: 'extracts|pageimages|categories|links', format: 'json', titles: query, exintro: '', explaintext: '', + pllimit: 20, piprop: 'original', redirects: '', formatversion: 2 @@ -56,14 +57,22 @@ module.exports = class WikipediaCommand extends Command { fact = `${facts[0]}.`; if (fact.length < 200 && facts.length > 1) fact += `${facts[1]}.`; } + const isDisambig = data.categories.some(category => category.title === 'Category:Disambiguation pages'); + if (isDisambig) { + fact += data.links.map(link => link.title).join('\n'); + fact += '\n'; + } else { + fact += ' '; + } const url = `https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`; + fact += `[Read more...](${url})`; const embed = new EmbedBuilder() .setColor(0xE7E7E7) .setTitle(data.title) .setAuthor({ name: 'Wikipedia', iconURL: logos.wikipedia, url: 'https://www.wikipedia.org/' }) .setURL(url) .setThumbnail(thumbnail) - .setDescription(`${fact} [Read more...](${url})`); + .setDescription(fact); return msg.embed(embed); } };