-
-
Save weskerty/9ace4ec5d9911e7e267e53ef0ea5af05 to your computer and use it in GitHub Desktop.
Wikipedia Fork Plugin pero en Español (cambiar https://es.wikipedia.org)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { bot } = require("../lib/"); | |
| const axios = require("axios"); | |
| bot( | |
| { | |
| pattern: "wiki ?(.*)", | |
| desc: "Search Wikipedia for a topic", | |
| type: "info", | |
| }, | |
| async (message, match) => { | |
| try { | |
| if (!match) return await message.send("Please provide a search query\nExample: .wiki Albert Einstein"); | |
| const response = await axios.get( | |
| `https://es.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(match)}` | |
| ); | |
| const data = response.data; | |
| const summary = data.extract || "No summary available."; | |
| const title = data.title; | |
| const wikiMessage = ` | |
| 📖 ${title} | |
| 📝 ${summary} | |
| 🔗 ${data.content_urls.desktop.page} | |
| `; | |
| await message.send(wikiMessage); | |
| } catch (error) { | |
| console.error("Wiki Error:", error); | |
| let errorMsg = "⚠️ Failed to fetch Wikipedia information"; | |
| if (error.response?.status === 404) { | |
| errorMsg = "⚠️ Article not found. Try another query."; | |
| } | |
| await message.send(errorMsg); | |
| } | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment