Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pyrogram.enums import ChatMemberStatus
- is_admin = lambda x: x.status is ChatMemberStatus.ADMINISTRATOR
- @app.on_chat_member_updated()
- async def bot_promoted_demoted(c, m):
- if not m.new_chat_member: return
- if not m.new_chat_member.user.is_self: return
- if is_admin(m.new_chat_member) and (not m.old_chat_member or not is_admin(m.old_chat_member)):
- promoted = True
- elif m.new_chat_member.status is ChatMemberStatus.MEMBER and (m.old_chat_member or is_admin(m.old_chat_member)):
- promoted = False
- else: return
- with Session(engine) as s:
- group = s.query(Groups).filter_by(group_id=m.chat.id).first()
- group.is_admin = promoted
- s.commit()
- await app.send_message(m.chat.id, text='Admin' if promoted else 'Member')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement