Skip to content

Commit 6456055

Browse files
committed
fix(message): update message
1 parent 82d31ff commit 6456055

1 file changed

Lines changed: 42 additions & 25 deletions

File tree

src/components/events/message.ts

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,26 @@ export default async function (msg: Message, type: string) {
5959

6060
/*
6161
* Block users from running commands.
62+
* will always return false if its admin
6263
*/
63-
const [isRateLimit, isBlockedUser] = await Promise.all([
64-
rateLimiter(lid),
65-
isBlocked(lid),
64+
const [rateLimitResult, isBlockedUser] = await Promise.all([
65+
(async () => {
66+
if (msg.fromMe) {
67+
return {
68+
status: false,
69+
value: { timestamps: [], penaltyCount: 0, penaltyUntil: 0 },
70+
};
71+
}
72+
73+
return rateLimiter(lid);
74+
})(),
75+
(async () => {
76+
if (msg.fromMe) {
77+
return false;
78+
}
79+
80+
return isBlocked(lid);
81+
})(),
6682
]);
6783

6884
if (isBlockedUser) return;
@@ -95,7 +111,7 @@ export default async function (msg: Message, type: string) {
95111

96112
Promise.resolve().then(async () => {
97113
const extractUrls = msg.body.match(/(https?:\/\/[^\s]+)/g);
98-
if (!extractUrls || isRateLimit.status) return;
114+
if (!extractUrls || rateLimitResult.status) return;
99115

100116
const url = extractUrls[Math.floor(Math.random() * extractUrls.length)];
101117
const message = msg;
@@ -116,7 +132,7 @@ export default async function (msg: Message, type: string) {
116132
if (msg.hasQuotedMsg) {
117133
Promise.resolve().then(async () => {
118134
const quoted = await msg.getQuotedMessage();
119-
if (!quoted.body || isRateLimit.status) return;
135+
if (!quoted.body || rateLimitResult.status) return;
120136

121137
await Promise.all([quiz(msg, quoted), riddle(msg, quoted)]);
122138
});
@@ -155,23 +171,23 @@ export default async function (msg: Message, type: string) {
155171
*/
156172
if (isMustautoReact && isMustautoReact == "on") {
157173
Promise.resolve().then(async () => {
158-
if (!msg.fromMe) {
159-
const emojis = [
160-
...new Set([...msg.body.matchAll(regex)].map((m) => m[0])),
161-
];
162-
if (emojis.length > 0) {
163-
const react = emojis[Math.floor(Math.random() * emojis.length)];
164-
165-
await msg.react(react);
166-
} else if (containsAny(msg.body, funD)) {
167-
await msg.react("🤣");
168-
} else if (containsAny(msg.body, happyEE)) {
169-
await msg.reply(funD[Math.floor(Math.random() * funD.length)]);
170-
} else if (containsAny(msg.body, sadEE)) {
171-
await msg.react("😭");
172-
} else if (containsAny(msg.body, loveEE)) {
173-
await msg.react("❤️");
174-
}
174+
if (msg.fromMe || rateLimitResult.status) return;
175+
176+
const emojis = [
177+
...new Set([...msg.body.matchAll(regex)].map((m) => m[0])),
178+
];
179+
if (emojis.length > 0) {
180+
const react = emojis[Math.floor(Math.random() * emojis.length)];
181+
182+
await msg.react(react);
183+
} else if (containsAny(msg.body, funD)) {
184+
await msg.react("🤣");
185+
} else if (containsAny(msg.body, happyEE)) {
186+
await msg.reply(funD[Math.floor(Math.random() * funD.length)]);
187+
} else if (containsAny(msg.body, sadEE)) {
188+
await msg.react("😭");
189+
} else if (containsAny(msg.body, loveEE)) {
190+
await msg.react("❤️");
175191
}
176192
});
177193
}
@@ -193,16 +209,17 @@ export default async function (msg: Message, type: string) {
193209
if (
194210
msg.mentionedIds &&
195211
msg.mentionedIds.length > 0 &&
196-
msg.mentionedIds.includes((await client()).info.wid._serialized)
212+
msg.mentionedIds.includes((await client()).info.wid._serialized) &&
213+
!rateLimitResult.status
197214
)
198215
await msg.reply(
199216
mentionResponses[Math.floor(Math.random() * mentionResponses.length)],
200217
);
201218
return;
202219
}
203220

204-
if (isRateLimit.status) {
205-
penalizeUser(lid, isRateLimit.value);
221+
if (rateLimitResult.status) {
222+
penalizeUser(lid, rateLimitResult.value);
206223
return;
207224
}
208225

0 commit comments

Comments
 (0)