Skip to content

Commit 35b18ec

Browse files
committed
chore(deps): bump @neoxr/wb from 6.0.0-rc.9 to 6.0.0-rc.10
feat: added error handling when get profile picture
1 parent 596ce70 commit 35b18ec

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

lib/baileys.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Utils } from '@neoxr/wb'
2+
import fs from 'node:fs'
23

34
export default client => {
45
/**
@@ -21,4 +22,24 @@ export default client => {
2122
client.getAdmin = participants => participants
2223
?.filter(i => i.admin === 'admin' || i.admin === 'superadmin')
2324
?.map(i => i.id) || []
25+
26+
/**
27+
* Fetches the profile picture of a given WhatsApp JID.
28+
*
29+
* If the user has no profile picture or if an error occurs while fetching it,
30+
* the function will return a default image instead.
31+
*
32+
* @param {string} jid - The WhatsApp JID (user identifier) whose profile picture is requested.
33+
* @returns {Promise<string|Buffer>} - A URL of the profile picture if available,
34+
* otherwise the default image as a Buffer.
35+
*/
36+
client.profilePicture = async jid => {
37+
const defaults = fs.readFileSync('./media/image/default.jpg')
38+
try {
39+
const picture = await client.profilePictureUrl(jid, 'image')
40+
return picture ?? defaults
41+
} catch (e) {
42+
return defaults
43+
}
44+
}
2445
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/neoxr/neoxr-bot#readme",
2727
"dependencies": {
2828
"@adiwajshing/keyed-db": "^0.2.4",
29-
"@neoxr/wb": "^6.0.0-rc.9",
29+
"@neoxr/wb": "^6.0.0-rc.10",
3030
"audio-decode": "^2.1.3",
3131
"baileys": "^7.0.0-rc.3",
3232
"cfonts": "3.1.1",
@@ -43,4 +43,4 @@
4343
"resolutions": {
4444
"jimp": "~0.22.12"
4545
}
46-
}
46+
}

plugins/convert/qc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const run = {
1616
if (!text) return client.reply(m.chat, Utils.example(isPrefix, command, 'Hi!'), m)
1717
if (text.length > 30) return client.reply(m.chat, Utils.texted('bold', `🚩 Max 30 character.`), m)
1818
client.sendReact(m.chat, '🕒', m.key)
19-
let pic = await client.profilePictureUrl(m.quoted ? m.quoted.sender : m.sender, 'image')
20-
if (!pic) {
21-
pic = 'https://i.ibb.co/nsDv3ZJ/image.jpg'
19+
let avatar = await client.profilePicture(m.quoted ? m.quoted.sender : m.sender)
20+
if (Buffer.isBuffer(avatar)) {
21+
avatar = 'https://qu.ax/mnUAl.jpg'
2222
}
2323
const json = {
2424
"type": "quote",
@@ -34,7 +34,7 @@ export const run = {
3434
"id": 1,
3535
"name": m.quoted ? global.db.users.find(v => v.jid == m.quoted.sender).name : m.pushName,
3636
"photo": {
37-
"url": pic
37+
"url": avatar
3838
}
3939
},
4040
"text": text,

plugins/group/groupinfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const run = {
1515
const creator = (meta?.owner?.endsWith('lid') ? meta?.ownerJid : meta.owner)?.replace(/@.+/, '')
1616
const admin = client.getAdmin(meta.participants)
1717
const member = participants.map(u => u.id)
18-
let pic = await client.profilePictureUrl(m.chat, 'image')
18+
const picture = await client.profilePicture(m.chat)
1919
let caption = `乂 *G R O U P - I N F O*\n\n`
2020
caption += ` ◦ *Name* : ${meta.subject}\n`
2121
caption += ` ◦ *Member* : ${member.length}\n`
@@ -40,7 +40,7 @@ export const run = {
4040
caption += global.footer
4141
client.sendMessageModify(m.chat, caption, m, {
4242
largeThumb: true,
43-
thumbnail: pic ? await Utils.fetchAsBuffer(pic) : await Utils.fetchAsBuffer('./media/image/default.jpg')
43+
thumbnail: picture
4444
})
4545
} catch (e) {
4646
client.reply(m.chat, Utils.jsonFormat(e), m)

plugins/owner/gc.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ export const run = {
2727
const option = useOpt ? (args[1]).toLowerCase() : false
2828
const time = group.stay ? 'FOREVER' : (group.expired == 0 ? 'NOT SET' : Utils.timeReverse(group.expired - new Date() * 1))
2929
const member = groupMetadata.participants.map(u => u.id).length
30-
let pic = await Utils.fetchAsBuffer('./media/image/default.jpg')
31-
try {
32-
pic = await client.profilePictureUrl(jid, 'image') || await Utils.fetchAsBuffer('./media/image/default.jpg')
33-
} catch {
34-
pic = await Utils.fetchAsBuffer('./media/image/default.jpg')
35-
}
30+
const picture = await client.profilePicture(jid)
3631
let data = {
3732
name: groupName,
3833
member,
@@ -42,7 +37,7 @@ export const run = {
4237
}
4338
if (!useOpt) return client.sendMessageModify(m.chat, steal(Utils, data) + '\n\n' + global.footer, m, {
4439
largeThumb: true,
45-
thumbnail: await Utils.fetchAsBuffer(pic)
40+
thumbnail: picture
4641
})
4742
if (option == 'open') {
4843
if (!admin) return client.reply(m.chat, Utils.texted('bold', `🚩 Can't open ${groupName} group link because the bot is not an admin.`), m)

plugins/userinfo/me.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const run = {
99
}) => {
1010
let user = global.db.users.find(v => v.jid == m.sender)
1111
let _own = [...new Set([Config.owner, ...global.db.setting.owners])]
12-
var pic = await client.profilePictureUrl(m.sender, 'image')
12+
const avatar = await client.profilePicture(m.sender)
1313
let blocked = blockList.includes(m.sender) ? true : false
1414
let now = new Date() * 1
1515
let lastseen = (user.lastseen == 0) ? 'Never' : Utils.toDate(now - user.lastseen)
@@ -28,7 +28,7 @@ export const run = {
2828
caption += global.footer
2929
client.sendMessageModify(m.chat, caption, m, {
3030
largeThumb: true,
31-
thumbnail: pic ? await Utils.fetchAsBuffer(pic) : await Utils.fetchAsBuffer('./media/image/default.jpg')
31+
thumbnail: avatar
3232
})
3333
},
3434
error: false

plugins/userinfo/profile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const run = {
2424
} catch (e) { } finally {
2525
let target = global.db.users.find(v => v.jid == user)
2626
if (typeof target == 'undefined') return client.reply(m.chat, Utils.texted('bold', `🚩 Can't find user data.`), m)
27-
var pic = await client.profilePictureUrl(user, 'image')
27+
const avatar = await client.profilePicture(user)
2828
let blocked = blockList.includes(user) ? true : false
2929
let caption = `乂 *U S E R - P R O F I L E*\n\n`
3030
caption += ` ◦ *Name* : ${target.name}\n`
@@ -40,7 +40,7 @@ export const run = {
4040
caption += global.footer
4141
client.sendMessageModify(m.chat, caption, m, {
4242
largeThumb: true,
43-
thumbnail: pic ? await Utils.fetchAsBuffer(pic) : await Utils.fetchAsBuffer('./media/image/default.jpg')
43+
thumbnail: avatar
4444
})
4545
}
4646
},

0 commit comments

Comments
 (0)