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