(sock, chatId, message, args)
| 5 | const crypto = require('crypto'); |
| 6 | |
| 7 | async function takeCommand(sock, chatId, message, args) { |
| 8 | try { |
| 9 | // Check if message is a reply to a sticker |
| 10 | const quotedMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 11 | if (!quotedMessage?.stickerMessage) { |
| 12 | await sock.sendMessage(chatId, { text: '❌ Reply to a sticker with .take <packname>' }); |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | // Get the packname from args or use default |
| 17 | const packname = args.join(' ') || 'Knight Bot'; |
| 18 | |
| 19 | try { |
| 20 | // Download the sticker |
| 21 | const stickerBuffer = await downloadMediaMessage( |
| 22 | { |
| 23 | key: message.message.extendedTextMessage.contextInfo.stanzaId, |
| 24 | message: quotedMessage, |
| 25 | messageType: 'stickerMessage' |
| 26 | }, |
| 27 | 'buffer', |
| 28 | {}, |
| 29 | { |
| 30 | logger: console, |
| 31 | reuploadRequest: sock.updateMediaMessage |
| 32 | } |
| 33 | ); |
| 34 | |
| 35 | if (!stickerBuffer) { |
| 36 | await sock.sendMessage(chatId, { text: '❌ Failed to download sticker' }); |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | // Add metadata using webpmux |
| 41 | const img = new webp.Image(); |
| 42 | await img.load(stickerBuffer); |
| 43 | |
| 44 | // Create metadata |
| 45 | const json = { |
| 46 | 'sticker-pack-id': crypto.randomBytes(32).toString('hex'), |
| 47 | 'sticker-pack-name': packname, |
| 48 | 'emojis': ['🤖'] |
| 49 | }; |
| 50 | |
| 51 | // Create exif buffer |
| 52 | const exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]); |
| 53 | const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8'); |
| 54 | const exif = Buffer.concat([exifAttr, jsonBuffer]); |
| 55 | exif.writeUIntLE(jsonBuffer.length, 14, 4); |
| 56 | |
| 57 | // Set the exif data |
| 58 | img.exif = exif; |
| 59 | |
| 60 | // Get the final buffer with metadata |
| 61 | const finalBuffer = await img.save(null); |
| 62 | |
| 63 | // Send the sticker |
| 64 | await sock.sendMessage(chatId, { |
no test coverage detected