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