Skip to content

Commit b060913

Browse files
committed
chore: extra bandit
1 parent 121e13c commit b060913

2 files changed

Lines changed: 45 additions & 38 deletions

File tree

src/commands/me.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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";
33
import redis from "../components/redis";
44
import { client } from "../components/client";
55
import { MessageMedia } from "whatsapp-web.js";
@@ -50,42 +50,48 @@ export default async function (msg: Message): Promise<void> {
5050
const jid = msg.author ?? msg.from;
5151
const lid = jid.split("@")[0];
5252

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);
8672
}
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+
]);
8995

9096
if (!user) {
9197
await msg.reply(
@@ -117,6 +123,7 @@ export default async function (msg: Message): Promise<void> {
117123
Last Seen: ${user.updatedAt.toUTCString()}
118124
Current Time: ${time.localTime}
119125
Timezone: ${time.timezone.name}
126+
Is Admin: ${isUserAdmin ? "Yes" : "No"}
120127
Is Block: ${isBlockPermanently ? "Yes" : "No"}
121128
Is Bot: ${self.split("@")[0] == user.number ? "Yes" : "No"}
122129
Is Muted: ${isBlockedTemporarily && ratelimit.penaltyCount > 0 ? "Yes" : "No"}

src/commands/stalk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default async function (msg: Message): Promise<void> {
6262
const lid = jid.split("@")[0];
6363
const isUserAdmin = await isAdmin(lid);
6464

65-
if (lid === botId.split("@")[0] || isUserAdmin) {
65+
if (!msg.fromMe && (lid === botId.split("@")[0] || isUserAdmin)) {
6666
await msg.reply("You cannot do that, please mention someone else.");
6767
return;
6868
}

0 commit comments

Comments
 (0)