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

Function handler

plugins/u-catbox.js:11–57  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

9 description: 'Upload to Catbox.moe (200MB, permanent)',
10 usage: '.catbox (reply to media)',
11 async handler(sock, message, args, context) {
12 const chatId = context.chatId || message.key.remoteJid;
13 try {
14 const quotedMsg = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
15 if (!quotedMsg) {
16 await sock.sendMessage(chatId, { text: '⚠️ Please reply to media!' }, { quoted: message });
17 return;
18 }
19 const type = Object.keys(quotedMsg)[0];
20 const supportedTypes = ['imageMessage', 'videoMessage', 'stickerMessage', 'documentMessage'];
21 if (!supportedTypes.includes(type)) {
22 await sock.sendMessage(chatId, { text: '⚠️ Unsupported type!' }, { quoted: message });
23 return;
24 }
25 await sock.sendMessage(chatId, { text: 'Uploading to Catbox...' }, { quoted: message });
26 const mediaType = type === 'stickerMessage' ? 'sticker' : type.replace('Message', '');
27 const stream = await downloadContentFromMessage(quotedMsg[type], mediaType);
28 let buffer = Buffer.from([]);
29 for await (const chunk of stream) {
30 buffer = Buffer.concat([buffer, chunk]);
31 }
32 let ext = 'bin';
33 if (type === 'imageMessage')
34 ext = 'jpg';
35 else if (type === 'videoMessage')
36 ext = 'mp4';
37 else if (type === 'stickerMessage')
38 ext = 'webp';
39 else if (quotedMsg[type].fileName) {
40 ext = quotedMsg[type].fileName.split('.').pop() || 'bin';
41 }
42 const tempDir = path.join('./temp');
43 if (!fs.existsSync(tempDir))
44 fs.mkdirSync(tempDir, { recursive: true });
45 const tempPath = path.join(tempDir, `catbox_${Date.now()}.${ext}`);
46 fs.writeFileSync(tempPath, buffer);
47 const result = await uploadToCatbox(tempPath);
48 await sock.sendMessage(chatId, {
49 text: `✅ *Catbox Upload Success!*\n\n🔗 ${result.url}`
50 }, { quoted: message });
51 fs.unlinkSync(tempPath);
52 }
53 catch (error) {
54 console.error('Catbox Error:', error);
55 await sock.sendMessage(chatId, { text: `❌ Error: ${error.message}` }, { quoted: message });
56 }
57 }
58};

Callers

nothing calls this directly

Calls 1

uploadToCatboxFunction · 0.90

Tested by

no test coverage detected