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

Function handler

plugins/resize.js:16–58  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

14 description: 'Send an image or video with a custom file length',
15 usage: '.length <size> (reply to media)',
16 async handler(sock, message, args, context) {
17 const chatId = context.chatId || message.key.remoteJid;
18 const text = args?.join(' ')?.trim();
19 try {
20 let mediaMsg, mediaType;
21 const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
22 if (quoted) {
23 if (quoted.imageMessage) {
24 mediaMsg = quoted.imageMessage;
25 mediaType = 'image';
26 }
27 else if (quoted.videoMessage) {
28 mediaMsg = quoted.videoMessage;
29 mediaType = 'video';
30 }
31 }
32 if (!mediaMsg) {
33 if (message.message?.imageMessage) {
34 mediaMsg = message.message.imageMessage;
35 mediaType = 'image';
36 }
37 else if (message.message?.videoMessage) {
38 mediaMsg = message.message.videoMessage;
39 mediaType = 'video';
40 }
41 }
42 if (!mediaMsg) {
43 return await sock.sendMessage(chatId, { text: '*⚠️ Reply to an image or video.*' }, { quoted: message });
44 }
45 if (!text || isNaN(text)) {
46 return await sock.sendMessage(chatId, { text: '*🔢 Provide numeric file size.*\nExample: .length 999999' }, { quoted: message });
47 }
48 const buffer = await downloadMedia(mediaMsg, mediaType);
49 const url = await uploadImage(buffer);
50 await sock.sendMessage(chatId, mediaType === 'image'
51 ? { image: { url }, caption: 'Here you go', fileLength: text }
52 : { video: { url }, caption: 'Here you go', fileLength: text }, { quoted: message });
53 }
54 catch (err) {
55 console.error('FileLength plugin error:', err);
56 await sock.sendMessage(chatId, { text: '❌ Failed to process media.' }, { quoted: message });
57 }
58 }
59};

Callers

nothing calls this directly

Calls 2

uploadImageFunction · 0.90
downloadMediaFunction · 0.70

Tested by

no test coverage detected