(sock, message, args, context)
| 10 | groupOnly: true, |
| 11 | adminOnly: true, |
| 12 | async handler(sock, message, args, context) { |
| 13 | const chatId = context.chatId || message.key.remoteJid; |
| 14 | const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 15 | const imageMessage = quoted?.imageMessage || quoted?.stickerMessage; |
| 16 | if (!imageMessage) { |
| 17 | await sock.sendMessage(chatId, { |
| 18 | text: '❌ *Please reply to an image or sticker*\n\nUsage: Reply to an image with `.setgpp`' |
| 19 | }, { quoted: message }); |
| 20 | return; |
| 21 | } |
| 22 | try { |
| 23 | const tmpDir = path.join(process.cwd(), 'tmp'); |
| 24 | if (!fs.existsSync(tmpDir)) { |
| 25 | fs.mkdirSync(tmpDir, { recursive: true }); |
| 26 | } |
| 27 | const stream = await downloadContentFromMessage(imageMessage, 'image'); |
| 28 | let buffer = Buffer.from([]); |
| 29 | for await (const chunk of stream) { |
| 30 | buffer = Buffer.concat([buffer, chunk]); |
| 31 | } |
| 32 | const imgPath = path.join(tmpDir, `gpp_${Date.now()}.jpg`); |
| 33 | fs.writeFileSync(imgPath, buffer); |
| 34 | await sock.updateProfilePicture(chatId, { url: imgPath }); |
| 35 | try { |
| 36 | fs.unlinkSync(imgPath); |
| 37 | } |
| 38 | catch (e) { } |
| 39 | await sock.sendMessage(chatId, { |
| 40 | text: '✅ *Group profile picture updated successfully!*' |
| 41 | }, { quoted: message }); |
| 42 | } |
| 43 | catch (error) { |
| 44 | console.error('Error updating group photo:', error); |
| 45 | await sock.sendMessage(chatId, { |
| 46 | text: '❌ *Failed to update group profile picture*\n\nMake sure the bot is an admin and the image is valid.' |
| 47 | }, { quoted: message }); |
| 48 | } |
| 49 | } |
| 50 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected