|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-2021 Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Dict, Union |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw |
| 23 | +from pyrogram import types |
| 24 | +from ..object import Object |
| 25 | +from ..update import Update |
| 26 | + |
| 27 | + |
| 28 | +class ChatMemberUpdated(Object, Update): |
| 29 | + """Represents changes in the status of a chat member. |
| 30 | +
|
| 31 | + Parameters: |
| 32 | + chat (:obj:`~pyrogram.types.Chat`): |
| 33 | + Chat the user belongs to. |
| 34 | +
|
| 35 | + from_user (:obj:`~pyrogram.types.User`): |
| 36 | + Performer of the action, which resulted in the change. |
| 37 | +
|
| 38 | + date (``int``): |
| 39 | + Date the change was done in Unix time. |
| 40 | +
|
| 41 | + old_chat_member (:obj:`~pyrogram.types.ChatMember`): |
| 42 | + Previous information about the chat member. |
| 43 | +
|
| 44 | + new_chat_member (:obj:`~pyrogram.types.ChatMember`): |
| 45 | + New information about the chat member. |
| 46 | +
|
| 47 | + invite_link (:obj:`~pyrogram.types.ChatInviteLink`, *optional*): |
| 48 | + Chat invite link, which was used by the user to join the chat; for joining by invite link events only. |
| 49 | + """ |
| 50 | + |
| 51 | + def __init__( |
| 52 | + self, |
| 53 | + *, |
| 54 | + client: "pyrogram.Client" = None, |
| 55 | + chat: "types.Chat", |
| 56 | + from_user: "types.User", |
| 57 | + date: int, |
| 58 | + old_chat_member: "types.ChatMember", |
| 59 | + new_chat_member: "types.ChatMember", |
| 60 | + invite_link: "types.ChatInviteLink" = None, |
| 61 | + ): |
| 62 | + super().__init__(client) |
| 63 | + |
| 64 | + self.chat = chat |
| 65 | + self.from_user = from_user |
| 66 | + self.date = date |
| 67 | + self.old_chat_member = old_chat_member |
| 68 | + self.new_chat_member = new_chat_member |
| 69 | + self.invite_link = invite_link |
| 70 | + |
| 71 | + @staticmethod |
| 72 | + def _parse( |
| 73 | + client: "pyrogram.Client", |
| 74 | + update: Union["raw.types.UpdateChatParticipant", "raw.types.UpdateChannelParticipant"], |
| 75 | + users: Dict[int, "raw.types.User"], |
| 76 | + chats: Dict[int, "raw.types.Chat"] |
| 77 | + ) -> "ChatMemberUpdated": |
| 78 | + chat_id = getattr(update, "chat_id", None) or getattr(update, "channel_id") |
| 79 | + invite_link = types.ChatInviteLink._parse(client, update.invite, users) if update.invite else None |
| 80 | + |
| 81 | + return ChatMemberUpdated( |
| 82 | + chat=types.Chat._parse_chat(client, chats[chat_id]), |
| 83 | + from_user=types.User._parse(client, users[update.actor_id]), |
| 84 | + date=update.date, |
| 85 | + old_chat_member=types.ChatMember._parse(client, update.prev_participant, users), |
| 86 | + new_chat_member=types.ChatMember._parse(client, update.new_participant, users), |
| 87 | + invite_link=invite_link, |
| 88 | + client=client |
| 89 | + ) |
0 commit comments