1919"""This module contains an object that represents a Telegram ChatMember."""
2020
2121from telegram import User , TelegramObject
22+ from telegram .utils .helpers import to_timestamp , from_timestamp
2223
2324
2425class ChatMember (TelegramObject ):
@@ -28,10 +29,39 @@ class ChatMember(TelegramObject):
2829 user (:class:`telegram.User`): Information about the user.
2930 status (str): The member's status in the chat. Can be 'creator', 'administrator', 'member',
3031 'left' or 'kicked'.
32+ until_date (Optional[:class:`datetime.datetime`]): Restricted and kicked only. Date when
33+ restrictions will be lifted for this user.
34+ can_be_edited (Optional[boolean]): Administrators only. True, if the bot is allowed to
35+ edit administrator privileges of that user
36+ can_change_info (Optional[boolean]): Administrators only. True, if the administrator can
37+ change the chat title, photo and other settings
38+ can_post_messages (Optional[boolean]): Administrators only. True, if the administrator can
39+ post in the channel, channels only
40+ can_edit_messages (Optional[boolean]): Administrators only. True, if the administrator can
41+ edit messages of other users, channels only
42+ can_delete_messages (Optional[boolean]): Administrators only. True, if the administrator
43+ can delete messages of other user
44+ can_invite_users (Optional[boolean]): Administrators only. True, if the administrator can
45+ invite new users to the chat
46+ can_restrict_members (Optional[boolean]): Administrators only. True, if the administrator
47+ can restrict, ban or unban chat members
48+ can_pin_messages (Optional[boolean]): Administrators only. True, if the administrator can
49+ pin messages, supergroups only
50+ can_promote_members (Optional[boolean]): Administrators only. True, if the administrator
51+ can add new administrators with a subset of his own privileges or demote administrators
52+ that he has promoted, directly or indirectly (promoted by administrators that were
53+ appointed by the user)
54+ can_send_messages (Optional[boolean]): Restricted only. True, if the user can send text
55+ messages, contacts, locations and venues
56+ can_send_media_messages (Optional[boolean]): Restricted only. True, if the user can send
57+ audios, documents, photos, videos, video notes and voice notes,
58+ implies can_send_messages
59+ can_send_other_messages (Optional[boolean]): Restricted only. True, if the user can send
60+ animations, games, stickers and use inline bots, implies can_send_media_messages
61+ can_add_web_page_previews (Optional[boolean]): Restricted only. True, if user may add
62+ web page previews to his messages, implies can_send_media_messages
3163
3264 Args:
33- user (:class:`telegram.User`):
34- status (str):
3565 **kwargs (dict): Arbitrary keyword arguments.
3666
3767 """
@@ -41,10 +71,30 @@ class ChatMember(TelegramObject):
4171 LEFT = 'left'
4272 KICKED = 'kicked'
4373
44- def __init__ (self , user , status , ** kwargs ):
74+ def __init__ (self , user , status , until_date = None , can_be_edited = None ,
75+ can_change_info = None , can_post_messages = None , can_edit_messages = None ,
76+ can_delete_messages = None , can_invite_users = None ,
77+ can_restrict_members = None , can_pin_messages = None ,
78+ can_promote_members = None , can_send_messages = None ,
79+ can_send_media_messages = None , can_send_other_messages = None ,
80+ can_add_web_page_previews = None , ** kwargs ):
4581 # Required
4682 self .user = user
4783 self .status = status
84+ self .until_date = until_date
85+ self .can_be_edited = can_be_edited
86+ self .can_change_info = can_change_info
87+ self .can_post_messages = can_post_messages
88+ self .can_edit_messages = can_edit_messages
89+ self .can_delete_messages = can_delete_messages
90+ self .can_invite_users = can_invite_users
91+ self .can_restrict_members = can_restrict_members
92+ self .can_pin_messages = can_pin_messages
93+ self .can_promote_members = can_promote_members
94+ self .can_send_messages = can_send_messages
95+ self .can_send_media_messages = can_send_media_messages
96+ self .can_send_other_messages = can_send_other_messages
97+ self .can_add_web_page_previews = can_add_web_page_previews
4898
4999 self ._id_attrs = (self .user , self .status )
50100
@@ -64,5 +114,17 @@ def de_json(data, bot):
64114 data = super (ChatMember , ChatMember ).de_json (data , bot )
65115
66116 data ['user' ] = User .de_json (data .get ('user' ), bot )
117+ data ['until_date' ] = from_timestamp (data .get ('until_date' , None ))
67118
68119 return ChatMember (** data )
120+
121+ def to_dict (self ):
122+ """
123+ Returns:
124+ dict:
125+ """
126+ data = super (ChatMember , self ).to_dict ()
127+
128+ data ['until_date' ] = to_timestamp (self .until_date )
129+
130+ return data
0 commit comments