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

Function handler

plugins/joke2.js:8–26  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

6 description: 'Get a random general joke',
7 usage: '.joke2',
8 async handler(sock, message, args, context) {
9 const chatId = context.chatId || message.key.remoteJid;
10 try {
11 const res = await axios.get('https://raw.githubusercontent.com/GlobalTechInfo/Database/main/text/random_jokes.txt');
12 if (!res.data) {
13 return await sock.sendMessage(chatId, { text: '❌ Failed to fetch joke.' }, { quoted: message });
14 }
15 const jokes = res.data.split('\n').filter((line) => line.trim() !== '');
16 if (jokes.length === 0) {
17 return await sock.sendMessage(chatId, { text: '❌ No jokes available.' }, { quoted: message });
18 }
19 const randomJoke = jokes[Math.floor(Math.random() * jokes.length)];
20 await sock.sendMessage(chatId, { text: `😂 *Joke*\n\n${randomJoke}` }, { quoted: message });
21 }
22 catch (err) {
23 console.error('Joke plugin error:', err);
24 await sock.sendMessage(chatId, { text: '❌ Error while fetching joke.' }, { quoted: message });
25 }
26 }
27};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected