(sock, message, args, context)
| 10 | description: 'Convert an image to negative', |
| 11 | usage: 'Reply to an image with .invert', |
| 12 | async handler(sock, message, args, context) { |
| 13 | const chatId = context.chatId || message.key.remoteJid; |
| 14 | try { |
| 15 | const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 16 | if (!quoted?.imageMessage) { |
| 17 | return await sock.sendMessage(chatId, { text: '🤍 *Invert Image*\n\nReply to an image to convert it to negative\n\nUsage:\n.invert' }, { quoted: message }); |
| 18 | } |
| 19 | await sock.sendMessage(chatId, { react: { text: '🔄', key: message.key } }); |
| 20 | const stream = await downloadContentFromMessage(quoted.imageMessage, 'image'); |
| 21 | let buffer = Buffer.from([]); |
| 22 | for await (const chunk of stream) { |
| 23 | buffer = Buffer.concat([buffer, chunk]); |
| 24 | } |
| 25 | const tempFile = path.join(process.cwd(), `invert_${Date.now()}.jpg`); |
| 26 | fs.writeFileSync(tempFile, buffer); |
| 27 | const form = new FormData(); |
| 28 | form.append('apikey', 'guru'); |
| 29 | form.append('file', fs.createReadStream(tempFile)); |
| 30 | const res = await axios.post('https://discardapi.dpdns.org/api/image/invert', form, { headers: form.getHeaders(), responseType: 'arraybuffer', timeout: 60000 }); |
| 31 | fs.unlinkSync(tempFile); |
| 32 | if (!res?.data) |
| 33 | throw new Error('Negative conversion failed'); |
| 34 | const grayFile = path.join(process.cwd(), `invert_result_${Date.now()}.jpg`); |
| 35 | fs.writeFileSync(grayFile, res.data); |
| 36 | await sock.sendMessage(chatId, { |
| 37 | image: { url: grayFile }, |
| 38 | caption: `🤍 *Inverted Image*\n\nProcessed by: MEGA-MD` |
| 39 | }, { quoted: message }); |
| 40 | fs.unlinkSync(grayFile); |
| 41 | } |
| 42 | catch (err) { |
| 43 | console.error('Invert Plugin Error:', err); |
| 44 | await sock.sendMessage(chatId, { text: '❌ Failed to convert image to sepia. Make sure the image is clear and try again.' }, { quoted: message }); |
| 45 | } |
| 46 | } |
| 47 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected