Advertisement
disk6969

pyrogram demote promote update

Dec 1st, 2023 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from pyrogram.enums import ChatMemberStatus
  2. is_admin = lambda x: x.status is ChatMemberStatus.ADMINISTRATOR
  3.  
  4. @app.on_chat_member_updated()
  5. async def bot_promoted_demoted(c, m):
  6.     if not m.new_chat_member: return
  7.     if not m.new_chat_member.user.is_self: return
  8.     if is_admin(m.new_chat_member) and (not m.old_chat_member or not is_admin(m.old_chat_member)):
  9.         promoted = True
  10.     elif m.new_chat_member.status is ChatMemberStatus.MEMBER and (m.old_chat_member or is_admin(m.old_chat_member)):
  11.         promoted = False
  12.     else: return
  13.  
  14.     with Session(engine) as s:
  15.         group = s.query(Groups).filter_by(group_id=m.chat.id).first()
  16.         group.is_admin = promoted
  17.         s.commit()
  18.     await app.send_message(m.chat.id, text='Admin' if promoted else 'Member')
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement