(sock, message, args, context)
| 9 | description: 'Set or update the bot profile picture (owner only)', |
| 10 | usage: '.setpp (reply to an image)', |
| 11 | async handler(sock, message, args, context) { |
| 12 | const chatId = context.chatId || message.key.remoteJid; |
| 13 | try { |
| 14 | const senderId = message.key.participant || message.key.remoteJid; |
| 15 | const isOwner = await isOwnerOrSudo(senderId, sock, chatId); |
| 16 | if (!message.key.fromMe && !isOwner) { |
| 17 | await sock.sendMessage(chatId, { |
| 18 | text: '*This command is only available for the owner!*' |
| 19 | }, { quoted: message }); |
| 20 | return; |
| 21 | } |
| 22 | const quotedMessage = message.message?.extendedTextMessage?.contextInfo?.quotedMessage; |
| 23 | if (!quotedMessage) { |
| 24 | await sock.sendMessage(chatId, { |
| 25 | text: '⚠️ Please reply to an image with the .setpp command!' |
| 26 | }, { quoted: message }); |
| 27 | return; |
| 28 | } |
| 29 | const imageMessage = quotedMessage.imageMessage || quotedMessage.stickerMessage; |
| 30 | if (!imageMessage) { |
| 31 | await sock.sendMessage(chatId, { |
| 32 | text: '*The replied message must contain an image!*' |
| 33 | }, { quoted: message }); |
| 34 | return; |
| 35 | } |
| 36 | const tmpDir = path.join(process.cwd(), 'tmp'); |
| 37 | if (!fs.existsSync(tmpDir)) |
| 38 | fs.mkdirSync(tmpDir, { recursive: true }); |
| 39 | const stream = await downloadContentFromMessage(imageMessage, 'image'); |
| 40 | let buffer = Buffer.from([]); |
| 41 | for await (const chunk of stream) |
| 42 | buffer = Buffer.concat([buffer, chunk]); |
| 43 | const imagePath = path.join(tmpDir, `profile_${Date.now()}.jpg`); |
| 44 | fs.writeFileSync(imagePath, buffer); |
| 45 | await sock.updateProfilePicture(sock.user.id, { url: imagePath }); |
| 46 | fs.unlinkSync(imagePath); |
| 47 | await sock.sendMessage(chatId, { |
| 48 | text: '✅ Successfully updated bot profile picture!' |
| 49 | }, { quoted: message }); |
| 50 | } |
| 51 | catch (error) { |
| 52 | console.error('SetPP Command Error:', error); |
| 53 | await sock.sendMessage(chatId, { |
| 54 | text: '❌ Failed to update profile picture!' |
| 55 | }, { quoted: message }); |
| 56 | } |
| 57 | } |
| 58 | }; |
nothing calls this directly
no test coverage detected