diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index 6b149413..9368e68b 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -20,6 +20,7 @@ from .business_schedule import BusinessSchedule from .chat_action import ChatAction from .chat_event_action import ChatEventAction +from .chat_join_type import ChatJoinType from .chat_member_status import ChatMemberStatus from .chat_members_filter import ChatMembersFilter from .chat_type import ChatType @@ -45,6 +46,7 @@ 'BusinessSchedule', 'ChatAction', 'ChatEventAction', + 'ChatJoinType', 'ChatMemberStatus', 'ChatMembersFilter', 'ChatType', diff --git a/pyrogram/enums/chat_join_type.py b/pyrogram/enums/chat_join_type.py new file mode 100644 index 00000000..9773ff48 --- /dev/null +++ b/pyrogram/enums/chat_join_type.py @@ -0,0 +1,34 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from enum import auto + +from .auto_name import AutoName + + +class ChatJoinType(AutoName): + """How the service message :obj:`~pyrogram.enums.MessageServiceType.NEW_CHAT_MEMBERS` was used for the member to join the chat.""" + + BY_ADD = auto() + "A new member joined the chat via an invite link" + + BY_LINK = auto() + "A new member joined the chat via an invite link" + + BY_REQUEST = auto() + "A new member was accepted to the chat by an administrator" diff --git a/pyrogram/enums/message_service_type.py b/pyrogram/enums/message_service_type.py index 2ed3e564..5706ade4 100644 --- a/pyrogram/enums/message_service_type.py +++ b/pyrogram/enums/message_service_type.py @@ -28,9 +28,6 @@ class MessageServiceType(AutoName): NEW_CHAT_MEMBERS = auto() "New members join" - CHAT_JOINED_BY_REQUEST = auto() - "a member chat join request approved by admin." - LEFT_CHAT_MEMBERS = auto() "Left chat members" diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index ea281a63..310b0d21 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -422,6 +422,10 @@ class Message(Object, Update): from_scheduled (``bool``, *optional*): Message is a scheduled message and has been sent. + + chat_join_type (:obj:`~pyrogram.enums.ChatJoinType`, *optional*): + The message is a service message of the type :obj:`~pyrogram.enums.MessageServiceType.NEW_CHAT_MEMBERS`. + This field will contain the enumeration type of how the user had joined the chat. """ # TODO: Add game missing field, Also connected_website @@ -537,6 +541,7 @@ def __init__( "types.ForceReply" ] = None, reactions: List["types.Reaction"] = None, + chat_join_type: "enums.ChatJoinType" = None, raw: "raw.types.Message" = None ): super().__init__(client) @@ -643,6 +648,7 @@ def __init__( self.successful_payment = successful_payment self.payment_refunded = payment_refunded self.reactions = reactions + self.chat_join_type = chat_join_type self.raw = raw async def wait_for_click( @@ -752,6 +758,7 @@ async def _parse( boosts_applied = None service_type = None + chat_join_type = None from_user = types.User._parse(client, users.get(user_id, None)) sender_chat = types.Chat._parse(client, message, users, chats, is_chat=False) if not from_user else None @@ -759,12 +766,15 @@ async def _parse( if isinstance(action, raw.types.MessageActionChatAddUser): new_chat_members = [types.User._parse(client, users[i]) for i in action.users] service_type = enums.MessageServiceType.NEW_CHAT_MEMBERS + chat_join_type = enums.ChatJoinType.BY_ADD elif isinstance(action, raw.types.MessageActionChatJoinedByLink): new_chat_members = [types.User._parse(client, users[utils.get_raw_peer_id(message.from_id)])] service_type = enums.MessageServiceType.NEW_CHAT_MEMBERS + chat_join_type = enums.ChatJoinType.BY_LINK elif isinstance(action, raw.types.MessageActionChatJoinedByRequest): chat_joined_by_request = types.ChatJoinedByRequest() - service_type = enums.MessageServiceType.CHAT_JOINED_BY_REQUEST + service_type = enums.MessageServiceType.NEW_CHAT_MEMBERS + chat_join_type = enums.ChatJoinType.BY_REQUEST elif isinstance(action, raw.types.MessageActionChatDeleteUser): left_chat_member = types.User._parse(client, users[action.user_id]) service_type = enums.MessageServiceType.LEFT_CHAT_MEMBERS @@ -889,6 +899,7 @@ async def _parse( payment_refunded=payment_refunded, boosts_applied=boosts_applied, raw=message, + chat_join_type=chat_join_type, client=client # TODO: supergroup_chat_created )