|
1 | | -import { Message } from "../types/message" |
2 | | -import { getUserbyLid } from "../components/services/user"; |
| 1 | +import { Message } from "../types/message"; |
| 2 | +import { getUserbyLid, isAdmin } from "../components/services/user"; |
3 | 3 | import redis from "../components/redis"; |
4 | 4 | import { client } from "../components/client"; |
5 | 5 | import { MessageMedia } from "whatsapp-web.js"; |
@@ -50,42 +50,48 @@ export default async function (msg: Message): Promise<void> { |
50 | 50 | const jid = msg.author ?? msg.from; |
51 | 51 | const lid = jid.split("@")[0]; |
52 | 52 |
|
53 | | - const [user, isBlockPermanently, isBlockedTemporarily, userProfilePicture] = |
54 | | - await Promise.all([ |
55 | | - getUserbyLid(lid), |
56 | | - redis.get(`block:${lid}`), |
57 | | - redis.get(`rate:${lid}`), |
58 | | - (async () => { |
59 | | - try { |
60 | | - const tempDir = "./.temp"; |
61 | | - await fs.promises.mkdir(tempDir, { recursive: true }); |
62 | | - const savePath = path.join(tempDir, `profile_${lid}.png`); |
63 | | - |
64 | | - if (await fileExists(savePath)) { |
65 | | - return MessageMedia.fromFilePath(savePath); |
66 | | - } |
67 | | - |
68 | | - const avatarUrl = await (await client()).getProfilePicUrl(jid); |
69 | | - |
70 | | - if (!avatarUrl) return undefined; |
71 | | - |
72 | | - const res = await axios.get(avatarUrl, { |
73 | | - responseType: "arraybuffer", |
74 | | - }); |
75 | | - const buffer = Buffer.from(res.data, "binary"); |
76 | | - |
77 | | - await fs.promises.writeFile(savePath, buffer); |
78 | | - return new MessageMedia( |
79 | | - "image/jpeg", |
80 | | - buffer.toString("base64"), |
81 | | - "avatar.jpg", |
82 | | - ); |
83 | | - } catch (error) { |
84 | | - log.error("Me", "Unable to fetch user profile pic:", error); |
85 | | - return undefined; |
| 53 | + const [ |
| 54 | + user, |
| 55 | + isBlockPermanently, |
| 56 | + isBlockedTemporarily, |
| 57 | + isUserAdmin, |
| 58 | + userProfilePicture, |
| 59 | + ] = await Promise.all([ |
| 60 | + getUserbyLid(lid), |
| 61 | + redis.get(`block:${lid}`), |
| 62 | + redis.get(`rate:${lid}`), |
| 63 | + isAdmin(lid), |
| 64 | + (async () => { |
| 65 | + try { |
| 66 | + const tempDir = "./.temp"; |
| 67 | + await fs.promises.mkdir(tempDir, { recursive: true }); |
| 68 | + const savePath = path.join(tempDir, `profile_${lid}.png`); |
| 69 | + |
| 70 | + if (await fileExists(savePath)) { |
| 71 | + return MessageMedia.fromFilePath(savePath); |
86 | 72 | } |
87 | | - })(), |
88 | | - ]); |
| 73 | + |
| 74 | + const avatarUrl = await (await client()).getProfilePicUrl(jid); |
| 75 | + |
| 76 | + if (!avatarUrl) return undefined; |
| 77 | + |
| 78 | + const res = await axios.get(avatarUrl, { |
| 79 | + responseType: "arraybuffer", |
| 80 | + }); |
| 81 | + const buffer = Buffer.from(res.data, "binary"); |
| 82 | + |
| 83 | + await fs.promises.writeFile(savePath, buffer); |
| 84 | + return new MessageMedia( |
| 85 | + "image/jpeg", |
| 86 | + buffer.toString("base64"), |
| 87 | + "avatar.jpg", |
| 88 | + ); |
| 89 | + } catch (error) { |
| 90 | + log.error("Me", "Unable to fetch user profile pic:", error); |
| 91 | + return undefined; |
| 92 | + } |
| 93 | + })(), |
| 94 | + ]); |
89 | 95 |
|
90 | 96 | if (!user) { |
91 | 97 | await msg.reply( |
@@ -117,6 +123,7 @@ export default async function (msg: Message): Promise<void> { |
117 | 123 | Last Seen: ${user.updatedAt.toUTCString()} |
118 | 124 | Current Time: ${time.localTime} |
119 | 125 | Timezone: ${time.timezone.name} |
| 126 | + Is Admin: ${isUserAdmin ? "Yes" : "No"} |
120 | 127 | Is Block: ${isBlockPermanently ? "Yes" : "No"} |
121 | 128 | Is Bot: ${self.split("@")[0] == user.number ? "Yes" : "No"} |
122 | 129 | Is Muted: ${isBlockedTemporarily && ratelimit.penaltyCount > 0 ? "Yes" : "No"} |
|
0 commit comments