is_admin.py 737 B

1234567891011121314151617181920212223242526272829303132
  1. from pyrogram.types import Message
  2. async def is_admin(message: Message) -> bool:
  3. if not message.from_user:
  4. return False
  5. if message.chat.type not in ["supergroup", "channel"]:
  6. return False
  7. if message.from_user.id in [
  8. 777000, # Telegram Service Notifications
  9. 1087968824 # GroupAnonymousBot
  10. ]:
  11. return True
  12. client = message._client
  13. chat_id = message.chat.id
  14. user_id = message.from_user.id
  15. check_status = await client.get_chat_member(
  16. chat_id=chat_id,
  17. user_id=user_id
  18. )
  19. admin_strings = [
  20. "creator",
  21. "administrator"
  22. ]
  23. if check_status.status not in admin_strings:
  24. return False
  25. else:
  26. return True