MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/wikipedia.js:9–47  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

7 description: 'Search Wikipedia for a topic!',
8 usage: '.wiki <query>',
9 async handler(sock, message, args, context) {
10 const chatId = context.chatId || message.key.remoteJid;
11 const query = args.join(' ').trim();
12 if (!query) {
13 return await sock.sendMessage(chatId, {
14 text: "*Enter what you want to search for on Wikipedia.*\nExample: .wiki Pakistan",
15 ...channelInfo
16 }, { quoted: message });
17 }
18 const formattedQuery = query.replace(/ /g, "_");
19 try {
20 const res = await axios.get(`https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(formattedQuery)}`, {
21 headers: {
22 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) MEGA-BOT/1.0',
23 'Accept-Language': 'en'
24 }
25 });
26 const data = res.data;
27 if (data.extract) {
28 await sock.sendMessage(chatId, {
29 text: `▢ *Wikipedia*\n\n‣ Search: ${data.title}\n\n${data.extract}\n\nRead more: ${data.content_urls.desktop.page}`,
30 ...channelInfo
31 }, { quoted: message });
32 }
33 else {
34 await sock.sendMessage(chatId, {
35 text: "⚠️ No results found.",
36 ...channelInfo
37 }, { quoted: message });
38 }
39 }
40 catch (e) {
41 console.error('Wikipedia plugin error:', e.message || e);
42 await sock.sendMessage(chatId, {
43 text: "⚠️ No results found or Wikipedia blocked the request.",
44 ...channelInfo
45 }, { quoted: message });
46 }
47 }
48};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected