(sock, message, args, context)
| 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 | }; |
nothing calls this directly
no test coverage detected