Takes a ChatMemberUpdated instance and extracts whether the 'old_chat_member' was a member of the chat and whether the 'new_chat_member' is a member of the chat. Returns None, if the status didn't change.
(chat_member_update: ChatMemberUpdated)
| 37 | |
| 38 | |
| 39 | def extract_status_change(chat_member_update: ChatMemberUpdated) -> tuple[bool, bool] | None: |
| 40 | """Takes a ChatMemberUpdated instance and extracts whether the 'old_chat_member' was a member |
| 41 | of the chat and whether the 'new_chat_member' is a member of the chat. Returns None, if |
| 42 | the status didn't change. |
| 43 | """ |
| 44 | status_change = chat_member_update.difference().get("status") |
| 45 | old_is_member, new_is_member = chat_member_update.difference().get("is_member", (None, None)) |
| 46 | |
| 47 | if status_change is None: |
| 48 | return None |
| 49 | |
| 50 | old_status, new_status = status_change |
| 51 | was_member = old_status in [ |
| 52 | ChatMember.MEMBER, |
| 53 | ChatMember.OWNER, |
| 54 | ChatMember.ADMINISTRATOR, |
| 55 | ] or (old_status == ChatMember.RESTRICTED and old_is_member is True) |
| 56 | is_member = new_status in [ |
| 57 | ChatMember.MEMBER, |
| 58 | ChatMember.OWNER, |
| 59 | ChatMember.ADMINISTRATOR, |
| 60 | ] or (new_status == ChatMember.RESTRICTED and new_is_member is True) |
| 61 | |
| 62 | return was_member, is_member |
| 63 | |
| 64 | |
| 65 | async def track_chats(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
no test coverage detected
searching dependent graphs…