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
15 changes: 15 additions & 0 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ 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
5 changes: 5 additions & 0 deletions telegram/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
Attributes:
MAX_MESSAGE_ENTITIES (:obj:`int`): 100 (Beyond this cap telegram will simply ignore further
formatting styles)
ANONYMOUS_ADMIN_ID (:obj:`int`): ``1087968824`` (User id in groups for anonymous admin)
SERVICE_CHAT_ID (:obj:`int`): ``777000`` (Telegram service chat, that also acts as sender of
channel posts forwarded to discussion groups)

The following constants are related to specific classes and are also available
as attributes of those classes:
Expand Down Expand Up @@ -128,6 +131,8 @@

MAX_MESSAGE_LENGTH: int = 4096
MAX_CAPTION_LENGTH: int = 1024
ANONYMOUS_ADMIN_ID: int = 1087968824
SERVICE_CHAT_ID: int = 777000

# constants above this line are tested

Expand Down
16 changes: 15 additions & 1 deletion telegram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram User."""

from telegram import TelegramObject
from telegram import TelegramObject, constants
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,6 +122,20 @@ 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
12 changes: 11 additions & 1 deletion 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
from telegram import Chat, ChatAction, ChatPermissions, constants
from telegram import User


Expand Down Expand Up @@ -95,6 +95,16 @@ 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
12 changes: 11 additions & 1 deletion 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
from telegram import Update, User, constants
from telegram.utils.helpers import escape_markdown


Expand Down Expand Up @@ -127,6 +127,16 @@ 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