Skip to content

Commit 0ea6410

Browse files
committed
chore: simplify role checking
1 parent 3f49487 commit 0ea6410

1 file changed

Lines changed: 5 additions & 37 deletions

File tree

src/components/events/message.ts

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
deductUserPoints,
1414
findOrCreateUser,
1515
getBlockUser,
16+
isAdmin,
1617
} from "../services/user";
1718
import { client } from "../client";
1819
import Font from "../utils/font";
@@ -206,44 +207,11 @@ export default async function (msg: Message, type: string): Promise<void> {
206207
return;
207208
}
208209

209-
/*
210-
* Role based restrictions.
211-
* - super-admin: only the bot owner (msg.fromMe) can run these commands
212-
* - admin: allowed for bot owner OR group admins (when used inside groups)
213-
*/
214-
if (handler.role === "super-admin") {
215-
if (!msg.fromMe) return;
216-
} else if (handler.role === "admin") {
217-
if (!msg.fromMe) {
218-
// allow only if the sender is a group admin
219-
try {
220-
const chat = await msg.getChat();
221-
if (!chat.isGroup) return;
222-
223-
const participants: any = (chat as any).participants || [];
224-
const senderJid = msg.author || msg.from; // full serialized jid
225-
const participant = participants.find(
226-
(p: any) => p && p.id && p.id._serialized === senderJid,
227-
);
228-
229-
if (!participant || (!participant.isAdmin && !participant.isSuperAdmin))
230-
return;
231-
} catch (err) {
232-
// in doubt, deny
233-
return;
234-
}
235-
}
210+
if (handler.role === "super-admin" && !msg.fromMe) {
211+
return;
236212
} else if (handler.role === "admin") {
237-
if (!msg.fromMe) {
238-
// admin role now covers previously 'bot-admin' privileges (stored in redis)
239-
try {
240-
const { isAdmin } = await import("../services/user");
241-
const ok = await isAdmin(lid);
242-
if (!ok) return;
243-
} catch (err) {
244-
return;
245-
}
246-
}
213+
const ok = await isAdmin(lid);
214+
if (!ok) return;
247215
}
248216

249217
log.info("Message", lid, msg.body.slice(0, 150));

0 commit comments

Comments
 (0)