(sock: any, message: any, args: any, context: BotContext)
| 11 | usage: '.take <packname> (reply to sticker)', |
| 12 | |
| 13 | async handler(sock: any, message: any, args: any, context: BotContext) { |
| 14 | const { chatId, channelInfo } = context; |
| 15 | |
| 16 | try { |
| 17 | const quotedMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 18 | |
| 19 | if (!quotedMessage?.stickerMessage) { |
| 20 | await sock.sendMessage(chatId, { |
| 21 | text: '❌ Reply to a sticker with .take <packname>', |
| 22 | ...channelInfo |
| 23 | }, { quoted: message }); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | const packname = args.join(' ') || 'MEGA AI'; |
| 28 | |
| 29 | try { |
| 30 | const stickerBuffer = await downloadMediaMessage( |
| 31 | { |
| 32 | key: message.message.extendedTextMessage.contextInfo.stanzaId, |
| 33 | message: quotedMessage, |
| 34 | // messageType: 'stickerMessage' |
| 35 | }, |
| 36 | 'buffer', |
| 37 | {}, |
| 38 | { |
| 39 | logger: (console as any), |
| 40 | reuploadRequest: sock.updateMediaMessage |
| 41 | } |
| 42 | ); |
| 43 | |
| 44 | if (!stickerBuffer) { |
| 45 | await sock.sendMessage(chatId, { |
| 46 | text: '❌ Failed to download sticker', |
| 47 | ...channelInfo |
| 48 | }, { quoted: message }); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | const img = new webp.Image(); |
| 53 | await img.load(stickerBuffer); |
| 54 | |
| 55 | const json = { |
| 56 | 'sticker-pack-id': crypto.randomBytes(32).toString('hex'), |
| 57 | 'sticker-pack-name': packname, |
| 58 | 'emojis': ['🤖'] |
| 59 | }; |
| 60 | |
| 61 | 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]); |
| 62 | const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8'); |
| 63 | const exif = Buffer.concat([exifAttr, jsonBuffer]); |
| 64 | exif.writeUIntLE(jsonBuffer.length, 14, 4); |
| 65 | |
| 66 | img.exif = exif; |
| 67 | |
| 68 | const finalBuffer = await img.save(null); |
| 69 | |
| 70 | await sock.sendMessage(chatId, { |
nothing calls this directly
no test coverage detected