taslim19 commited on
Commit
3c55597
·
1 Parent(s): 13fb449

Refactor NSFW plugin: add is_admin helper for admin/owner check

Browse files
Files changed (1) hide show
  1. DragMusic/plugins/plugins/nsfw.py +11 -7
DragMusic/plugins/plugins/nsfw.py CHANGED
@@ -35,17 +35,21 @@ async def enable_nsfw(chat_id: int):
35
  async def disable_nsfw(chat_id: int):
36
  await nsfw_chats_collection.delete_one({"chat_id": chat_id})
37
 
 
 
 
 
 
 
 
 
38
  @app.on_message(filters.command("nsfw") & filters.group)
39
- async def toggle_nsfw_scan(_, message: Message):
40
  if len(message.command) != 2:
41
  return await message.reply("Usage: /nsfw enable or /nsfw disable")
42
 
43
- try:
44
- member = await app.get_chat_member(message.chat.id, message.from_user.id)
45
- if not (member.status in ["administrator", "owner"]):
46
- return await message.reply("Only group admins and the group owner can use this command.")
47
- except (PeerIdInvalid, UserNotParticipant):
48
- return await message.reply("You must be a group member to use this command.")
49
 
50
  arg = message.command[1].lower()
51
  if arg == "enable":
 
35
  async def disable_nsfw(chat_id: int):
36
  await nsfw_chats_collection.delete_one({"chat_id": chat_id})
37
 
38
+ # Helper to check if a user is admin or owner
39
+ async def is_admin(client, chat_id, user_id):
40
+ try:
41
+ member = await client.get_chat_member(chat_id, user_id)
42
+ return member.status in ["administrator", "owner"]
43
+ except:
44
+ return False
45
+
46
  @app.on_message(filters.command("nsfw") & filters.group)
47
+ async def toggle_nsfw_scan(client, message: Message):
48
  if len(message.command) != 2:
49
  return await message.reply("Usage: /nsfw enable or /nsfw disable")
50
 
51
+ if not await is_admin(client, message.chat.id, message.from_user.id):
52
+ return await message.reply("Only group admins and the group owner can use this command.")
 
 
 
 
53
 
54
  arg = message.command[1].lower()
55
  if arg == "enable":