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

Function handler

plugins/meme.js:7–41  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

5 description: 'Get a random cheems meme with buttons for another meme or joke',
6 usage: '.meme',
7 async handler(sock, message, args, context) {
8 const chatId = context.chatId || message.key.remoteJid;
9 try {
10 const res = await fetch('https://shizoapi.onrender.com/api/memes/cheems?apikey=shizo');
11 if (!res.ok)
12 throw new Error(`API request failed with status ${res.status}`);
13 const contentType = res.headers.get('content-type');
14 if (contentType && contentType.includes('image')) {
15 const imageBuffer = Buffer.from(await res.arrayBuffer());
16 const buttons = [
17 { buttonId: '.meme', buttonText: { displayText: '🎭 Another Meme' }, type: 1 },
18 { buttonId: '.joke', buttonText: { displayText: '😄 Joke' }, type: 1 }
19 ];
20 await sock.sendMessage(chatId, {
21 image: imageBuffer,
22 caption: "🐕 > Here's your cheems meme!",
23 buttons,
24 headerType: 1
25 }, { quoted: message });
26 }
27 else {
28 await sock.sendMessage(chatId, {
29 text: '❌ The API did not return a valid image.',
30 quoted: message
31 });
32 }
33 }
34 catch (error) {
35 console.error('Meme Command Error:', error);
36 await sock.sendMessage(chatId, {
37 text: '❌ Failed to fetch meme. Please try again later.',
38 quoted: message
39 });
40 }
41 }
42};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected