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