MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / extract_status_change

Function extract_status_change

examples/chatmemberbot.py:39–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

37
38
39def 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
65async def track_chats(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:

Callers 2

track_chatsFunction · 0.85
greet_chat_membersFunction · 0.85

Calls 1

differenceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…