buscador-wikipedia.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import axios from 'axios';
  2. import fetch from 'node-fetch';
  3. import cheerio from 'cheerio';
  4. async function wikipedia(querry) {
  5. try {
  6. const link = await axios.get(`https://es.wikipedia.org/wiki/${querry}`);
  7. const $ = cheerio.load(link.data);
  8. const judul = $('#firstHeading').text().trim();
  9. const thumb = $('#mw-content-text').find('div.mw-parser-output > div:nth-child(1) > table > tbody > tr:nth-child(2) > td > a > img').attr('src') || `//i.ibb.co/nzqPBpC/http-error-404-not-found.png`;
  10. const isi = [];
  11. $('#mw-content-text > div.mw-parser-output').each(function(rayy, Ra) {
  12. const penjelasan = $(Ra).find('p').text().trim();
  13. isi.push(penjelasan)});
  14. for (const i of isi) {
  15. const data = {status: link.status,
  16. result: {judul: judul,
  17. thumb: 'https:' + thumb,
  18. isi: i}};
  19. return data;
  20. }} catch (err) {
  21. const notFond = {status: link.status,
  22. Pesan: eror};
  23. return notFond;
  24. }}
  25. const handler = async (m, {conn, text, usedPrefix, command}) => {
  26. if (!text) throw `*⚠️ ᴇsᴛᴀs ᴜsᴀɴᴅᴏ ᴍᴀʟ ᴇʟ ᴄᴏᴍᴀɴᴅᴏ!!*\n*ᴜsᴏ ᴄᴏʀʀᴇᴄᴛᴏ:*\n*${usedPrefix + command} 𝙿𝚊𝚕𝚊𝚋𝚛𝚊 𝚌𝚕𝚊𝚟𝚎 𝚊 𝚋𝚞𝚜𝚌𝚊𝚛*\n\n*• ᴇᴊᴇᴍᴘʟᴏ:*\n*${usedPrefix + command} Estrellas*`;
  27. wikipedia(`${text}`).then((res) => {
  28. m.reply(`*ᴀǫᴜɪ ᴛɪᴇɴᴇs ʟᴀ ɪɴғᴏʀᴍᴀᴄɪᴏ́ɴ ᴇɴᴄᴏɴᴛʀᴀᴅᴀ:*\n\n` + res.result.isi)}).catch(() => {
  29. m.reply('*⚠️ ɴᴏ sᴇ ᴇɴᴄᴏɴᴛʀᴏ ɴɪɴɢᴜɴᴀ ɪɴғᴏʀᴍᴀᴄɪᴏ́ɴ, ᴘʀᴜᴇʙᴀ ǫᴜᴇ ʜᴀʏᴀs ᴇsᴄʀɪᴛᴏ ᴜɴᴀ sᴏʟᴀ ᴘᴀʟᴀʙʀᴀ ʏ ʟᴏ ʜᴀʏᴀs ᴇsᴄʀɪᴛᴏ ᴄᴏʀʀᴇᴄᴛᴀᴍᴇɴᴛᴇ*');
  30. });
  31. };
  32. handler.help = ['wikipedia'].map((v) => v + ' <apa>');
  33. handler.tags = ['buscadores'];
  34. handler.command = /^(wiki|wikipedia)$/i;
  35. handler.register = true
  36. handler.limit = 1
  37. export default handler;