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

Function handler

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

Source from the content-addressed store, hash-verified

24 description: 'Convert a sticker to an image',
25 usage: '.s2img (reply to a sticker)',
26 async handler(sock, message, args, context) {
27 const chatId = context.chatId || message.key.remoteJid;
28 try {
29 const quotedMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
30 if (!quotedMessage?.stickerMessage) {
31 await sock.sendMessage(chatId, { text: '⚠️ Reply to a sticker with .simage to convert it.' }, { quoted: message });
32 return;
33 }
34 const stickerFilePath = path.join(tempDir, `sticker_${Date.now()}.webp`);
35 const outputImagePath = path.join(tempDir, `converted_image_${Date.now()}.png`);
36 const stream = await downloadContentFromMessage(quotedMessage.stickerMessage, 'sticker');
37 let buffer = Buffer.from([]);
38 for await (const chunk of stream)
39 buffer = Buffer.concat([buffer, chunk]);
40 await fsPromises.writeFile(stickerFilePath, buffer);
41 await sharp(stickerFilePath).toFormat('png').toFile(outputImagePath);
42 const imageBuffer = await fsPromises.readFile(outputImagePath);
43 await sock.sendMessage(chatId, { image: imageBuffer, caption: '✨ Here is the converted image!' }, { quoted: message });
44 scheduleFileDeletion(stickerFilePath);
45 scheduleFileDeletion(outputImagePath);
46 }
47 catch (error) {
48 console.error('SImage Command Error:', error);
49 await sock.sendMessage(chatId, { text: '❌ An error occurred while converting the sticker.' }, { quoted: message });
50 }
51 }
52};

Callers

nothing calls this directly

Calls 1

scheduleFileDeletionFunction · 0.85

Tested by

no test coverage detected