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

Function handler

plugins/resize.ts:19–66  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

uploadImageFunction · 0.85
downloadMediaFunction · 0.70

Tested by

no test coverage detected