mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
add wiki , and antieveryone sysem ( command + event)
This commit is contained in:
+29
-19
@@ -1,28 +1,38 @@
|
||||
const axios = require('axios');
|
||||
const Discord = require('discord.js');
|
||||
const wiki = require('wikipedia');
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: "wiki",
|
||||
aliases: ["wikipedia"],
|
||||
description: "Permet de faire une recherche wikipédia depuis votre serveur ",
|
||||
category: "utils" ,
|
||||
emote:"🌍",
|
||||
utilisation: "wiki <mot-clé>",
|
||||
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) {
|
||||
let query = args.join(" ");
|
||||
if(!query) return;
|
||||
|
||||
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 searchResults = await wiki.summary(query.toLocaleLowerCase());
|
||||
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('#00FFFF')
|
||||
.setTitle(`${searchResults.title}`)
|
||||
.setDescription(`${searchResults.extract}`);
|
||||
message.reply({ embeds: [embed] });
|
||||
.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) {
|
||||
console.error(error);
|
||||
message.reply('Je n\'ai pas pu trouver cette page sur Wikipedia. Veuillez vérifier le mot-clé et réessayer.');
|
||||
message.channel.send('Une erreur est survenue lors de la recherche.');
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user