Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3304,6 +3304,7 @@ def promote_chat_member(
can_promote_members: bool = None,
timeout: float = None,
api_kwargs: JSONDict = None,
is_anonymous: bool = None,
) -> bool:
"""
Use this method to promote or demote a user in a supergroup or a channel. The bot must be
Expand All @@ -3314,6 +3315,8 @@ def promote_chat_member(
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target supergroup (in the format @supergroupusername).
user_id (:obj:`int`): Unique identifier of the target user.
is_anonymous (:obj:`bool`, optional): Pass :obj:`True`, if the administrator's presence
in the chat is hidden.
can_change_info (:obj:`bool`, optional): Pass :obj:`True`, if the administrator can
change chat title, photo and other settings.
can_post_messages (:obj:`bool`, optional): Pass :obj:`True`, if the administrator can
Expand Down Expand Up @@ -3347,6 +3350,8 @@ def promote_chat_member(
"""
data: JSONDict = {'chat_id': chat_id, 'user_id': user_id}

if is_anonymous is not None:
data['is_anonymous'] = is_anonymous
if can_change_info is not None:
data['can_change_info'] = can_change_info
if can_post_messages is not None:
Expand Down
15 changes: 0 additions & 15 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,6 @@ def link(self) -> Optional[str]:
return "https://t.me/{}".format(self.username)
return None

@property
def is_anonymous_admin(self) -> bool:
""":obj:`bool`: Convenience property. Returns :obj:`True`, if this chat is with is the bot
representing anonymous admins. This behaviour is undocumented and might be changed
by Telegram."""

return self.id == constants.ANONYMOUS_ADMIN_ID

@property
def is_service_chat(self) -> bool:
""":obj:`bool`: Convenience property. Returns :obj:`True`, if this chat is the Telegram
service chat. This behaviour is undocumented and might be changed by Telegram."""

return self.id == constants.SERVICE_CHAT_ID

@classmethod
def de_json(cls, data: JSONDict, bot: 'Bot') -> Optional['Chat']:
data = cls.parse_data(data)
Expand Down
8 changes: 8 additions & 0 deletions telegram/chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ChatMember(TelegramObject):
user (:class:`telegram.User`): Information about the user.
status (:obj:`str`): The member's status in the chat.
custom_title (:obj:`str`): Optional. Custom title for owner and administrators.
is_anonymous (:obj:`bool`): Optional. :obj:`True`, if the user's presence in the chat is
hidden.
until_date (:class:`datetime.datetime`): Optional. Date when restrictions will be lifted
for this user.
can_be_edited (:obj:`bool`): Optional. If the bot is allowed to edit administrator
Expand Down Expand Up @@ -74,6 +76,8 @@ class ChatMember(TelegramObject):
'member', 'restricted', 'left' or 'kicked'.
custom_title (:obj:`str`, optional): Owner and administrators only.
Custom title for this user.
is_anonymous (:obj:`bool`, optional): Owner and administrators only. :obj:`True`, if the
user's presence in the chat is hidden.
until_date (:class:`datetime.datetime`, optional): Restricted and kicked only. Date when
restrictions will be lifted for this user.
can_be_edited (:obj:`bool`, optional): Administrators only. :obj:`True`, if the bot is
Expand Down Expand Up @@ -145,12 +149,16 @@ def __init__(
can_add_web_page_previews: bool = None,
is_member: bool = None,
custom_title: str = None,
is_anonymous: bool = None,
**_kwargs: Any,
):
# Required
self.user = user
self.status = status

# Optionals
self.custom_title = custom_title
self.is_anonymous = is_anonymous
self.until_date = until_date
self.can_be_edited = can_be_edited
self.can_change_info = can_change_info
Expand Down
21 changes: 16 additions & 5 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class Message(TelegramObject):
Attributes:
message_id (:obj:`int`): Unique message identifier inside this chat.
from_user (:class:`telegram.User`): Optional. Sender.
sender_chat (:class:`telegram.Chat`): Optional. Sender of the message, sent on behalf of a
chat. The channel itself for channel messages. The supergroup itself for messages from
anonymous group administrators. The linked channel for messages automatically forwarded
to the discussion group.
date (:class:`datetime.datetime`): Date the message was sent.
chat (:class:`telegram.Chat`): Conversation the message belongs to.
forward_from (:class:`telegram.User`): Optional. Sender of the original message.
Expand Down Expand Up @@ -134,8 +138,8 @@ class Message(TelegramObject):
forwarded from channels.
forward_sender_name (:obj:`str`): Optional. Sender's name for messages forwarded from users
who disallow adding a link to their account in forwarded messages.
author_signature (:obj:`str`): Optional. Signature of the post author for messages
in channels.
author_signature (:obj:`str`): Optional. Signature of the post author for messages in
channels, or the custom title of an anonymous group administrator.
passport_data (:class:`telegram.PassportData`): Optional. Telegram Passport data.
poll (:class:`telegram.Poll`): Optional. Message is a native poll,
information about the poll.
Expand All @@ -149,6 +153,10 @@ class Message(TelegramObject):
message_id (:obj:`int`): Unique message identifier inside this chat.
from_user (:class:`telegram.User`, optional): Sender, empty for messages sent
to channels.
sender_chat (:class:`telegram.Chat`, optional): Sender of the message, sent on behalf of a
chat. The channel itself for channel messages. The supergroup itself for messages from
anonymous group administrators. The linked channel for messages automatically forwarded
to the discussion group.
date (:class:`datetime.datetime`): Date the message was sent in Unix time. Converted to
:class:`datetime.datetime`.
chat (:class:`telegram.Chat`): Conversation the message belongs to.
Expand Down Expand Up @@ -242,8 +250,8 @@ class Message(TelegramObject):
has logged in.
forward_signature (:obj:`str`, optional): For messages forwarded from channels, signature
of the post author if present.
author_signature (:obj:`str`, optional): Signature of the post author for messages
in channels.
author_signature (:obj:`str`, optional): Signature of the post author for messages in
channels, or the custom title of an anonymous group administrator.
passport_data (:class:`telegram.PassportData`, optional): Telegram Passport data.
poll (:class:`telegram.Poll`, optional): Message is a native poll,
information about the poll.
Expand Down Expand Up @@ -344,14 +352,16 @@ def __init__(
bot: 'Bot' = None,
dice: Dice = None,
via_bot: User = None,
sender_chat: Chat = None,
**_kwargs: Any,
):
# Required
self.message_id = int(message_id)
# Optionals
self.from_user = from_user
self.sender_chat = sender_chat
self.date = date
self.chat = chat
# Optionals
self.forward_from = forward_from
self.forward_from_chat = forward_from_chat
self.forward_date = forward_date
Expand Down Expand Up @@ -427,6 +437,7 @@ def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> 'Message':
return None

data['from_user'] = User.de_json(data.get('from'), bot)
data['sender_chat'] = Chat.de_json(data.get('sender_chat'), bot)
data['date'] = from_timestamp(data['date'])
data['chat'] = Chat.de_json(data.get('chat'), bot)
data['entities'] = MessageEntity.de_list(data.get('entities'), bot)
Expand Down
16 changes: 1 addition & 15 deletions telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from typing import TYPE_CHECKING, Any, List, Optional

from telegram import TelegramObject, constants
from telegram import TelegramObject
from telegram.utils.helpers import mention_html as util_mention_html
from telegram.utils.helpers import mention_markdown as util_mention_markdown

Expand Down Expand Up @@ -122,20 +122,6 @@ def link(self) -> Optional[str]:
return "https://t.me/{}".format(self.username)
return None

@property
def is_anonymous_admin(self) -> bool:
""":obj:`bool`: Convenience property. Returns :obj:`True`, if this user is
an anonymous admin. This behaviour is undocumented and might be changed by Telegram."""

return self.id == constants.ANONYMOUS_ADMIN_ID

@property
def is_service_chat(self) -> bool:
""":obj:`bool`: Convenience property. Returns :obj:`True`, if this user is
the telegram service. This behaviour is undocumented and might be changed by Telegram."""

return self.id == constants.SERVICE_CHAT_ID

def get_profile_photos(self, *args: Any, **kwargs: Any) -> 'UserProfilePhotos':
"""
Shortcut for::
Expand Down
1 change: 1 addition & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@ def test_promote_chat_member(self, bot, channel_id):
assert bot.promote_chat_member(
channel_id,
95205500,
is_anonymous=True,
can_change_info=True,
can_post_messages=True,
can_edit_messages=True,
Expand Down
12 changes: 1 addition & 11 deletions tests/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest

from telegram import Chat, ChatAction, ChatPermissions, constants
from telegram import Chat, ChatAction, ChatPermissions
from telegram import User


Expand Down Expand Up @@ -95,16 +95,6 @@ def test_link(self, chat):
chat.username = None
assert chat.link is None

def test_anonymous_admin(self, chat):
assert chat.is_anonymous_admin is False
chat.id = constants.ANONYMOUS_ADMIN_ID
assert chat.is_anonymous_admin

def test_service_chat(self, chat):
assert chat.is_service_chat is False
chat.id = constants.SERVICE_CHAT_ID
assert chat.is_service_chat

def test_send_action(self, monkeypatch, chat):
def test(*args, **kwargs):
id_ = args[0] == chat.id
Expand Down
2 changes: 2 additions & 0 deletions tests/test_chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def test_de_json_all_args(self, bot, user):
'user': user.to_dict(),
'status': self.status,
'custom_title': custom_title,
'is_anonymous': True,
'until_date': to_timestamp(time),
'can_be_edited': False,
'can_change_info': True,
Expand All @@ -75,6 +76,7 @@ def test_de_json_all_args(self, bot, user):
assert chat_member.user == user
assert chat_member.status == self.status
assert chat_member.custom_title == custom_title
assert chat_member.is_anonymous is True
assert chat_member.can_be_edited is False
assert chat_member.can_change_info is True
assert chat_member.can_post_messages is False
Expand Down
2 changes: 2 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def message(bot):
{'quote': True},
{'dice': Dice(4, '🎲')},
{'via_bot': User(9, 'A_Bot', True)},
{'sender_chat': Chat(-123, 'discussion_channel')},
],
ids=[
'forwarded_user',
Expand Down Expand Up @@ -200,6 +201,7 @@ def message(bot):
'default_quote',
'dice',
'via_bot',
'sender_chat',
],
)
def message_params(bot, request):
Expand Down
12 changes: 1 addition & 11 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
import pytest

from telegram import Update, User, constants
from telegram import Update, User
from telegram.utils.helpers import escape_markdown


Expand Down Expand Up @@ -127,16 +127,6 @@ def test_link(self, user):
user.username = None
assert user.link is None

def test_anonymous_admin(self, user):
assert user.is_anonymous_admin is False
user.id = constants.ANONYMOUS_ADMIN_ID
assert user.is_anonymous_admin

def test_service_chat(self, user):
assert user.is_service_chat is False
user.id = constants.SERVICE_CHAT_ID
assert user.is_service_chat

def test_get_profile_photos(self, monkeypatch, user):
def test(*args, **kwargs):
return args[0] == user.id
Expand Down