mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
const axios = require('axios');
|
|
const Discord = require('discord.js');
|
|
module.exports = {
|
|
name: 'wiki',
|
|
description: 'Recherche un mot clé sur Wikipedia et affiche le résumé dans un embed.',
|
|
utilisation: '+wiki <mot clé>',
|
|
category: 'info',
|
|
|
|
async execute(message, args, client) {
|
|
if (!args.length) {
|
|
return message.channel.send(`Veuillez fournir un mot clé pour la recherche.`);
|
|
}
|
|
|
|
const query = encodeURIComponent(args.join(' '));
|
|
const url = `https://fr.wikipedia.org/w/api.php?action=query&format=json&origin=*&prop=extracts&exintro=&explaintext=&titles=${query}`;
|
|
|
|
try {
|
|
const response = await axios.get(url);
|
|
const data = response.data;
|
|
const pages = data.query.pages;
|
|
const pageId = Object.keys(pages)[0];
|
|
const extract = pages[pageId].extract;
|
|
|
|
// Utiliser le premier résultat sans filtrer par le nombre de mots
|
|
const firstResult = pages[pageId];
|
|
const embed = new Discord.EmbedBuilder()
|
|
.setColor('#0099ff')
|
|
.setTitle(firstResult.title)
|
|
.setURL(`https://fr.wikipedia.org/wiki/${encodeURIComponent(firstResult.title)}`)
|
|
.setDescription(extract.substring(0, 200) + '...')
|
|
.addFields({ name: 'Lien', value: '[Lire plus](https://fr.wikipedia.org/wiki/${encodeURIComponent(firstResult.title)})', inline: true });
|
|
|
|
message.channel.send({ embeds: [embed] });
|
|
} catch (error) {
|
|
message.channel.send('Une erreur est survenue lors de la recherche.');
|
|
}
|
|
},
|
|
}; |