Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0c4fae6
temporarily test PRs to api-5.0-master
Bibo-Joshi Nov 5, 2020
be4dfbb
Merge branch 'master' into api-5.0-master
Bibo-Joshi Nov 5, 2020
0b0460c
Api 5.0 WP 4 (Working with Files) (#2186)
Bibo-Joshi Nov 7, 2020
e159d24
Update typehints/docs of send_media_group, fix redering error in set_…
Bibo-Joshi Nov 7, 2020
57580bc
Api 5.0 WP 10 (Dice) (#2190)
Bibo-Joshi Nov 7, 2020
9b988fc
Merge branch 'master' into api-5.0-master
Poolitzer Nov 7, 2020
c364e57
Anonymous Admins (#2189)
Bibo-Joshi Nov 7, 2020
d580707
API 5.0 WP 1+2 (API Servers & Webhooks) (#2183)
Bibo-Joshi Nov 10, 2020
6025bca
Update some docs
Bibo-Joshi Nov 10, 2020
c4acb71
Merge remote-tracking branch 'origin/api-5.0-master' into api-5.0-master
Bibo-Joshi Nov 10, 2020
e84cf01
API 5.0 WP5 - Pinned messages (#2184)
harshil21 Nov 13, 2020
6768fef
Api 5.0 WP 7 (Live Locations) (#2188)
Bibo-Joshi Nov 14, 2020
1a1b8b7
API 5.0 WP 3 (Working with Groups) (#2185)
Bibo-Joshi Nov 15, 2020
9408ef5
allow_sending_without_reply parameter & corresponding Default (#2192)
Bibo-Joshi Nov 18, 2020
042f933
Api 5.0 WP 13 (New Filters) (#2205)
Bibo-Joshi Nov 18, 2020
b8ebcac
Api 5.0 WP 9.1 (#2196)
Poolitzer Nov 20, 2020
cdf9cce
Actually add ChatLocation & ProximitiAlertTriggered to docs
Bibo-Joshi Nov 25, 2020
9426204
Api 5.0 WP 9.2+9.3 (caption_entities for InputMedia* and InlineQueryR…
Bibo-Joshi Nov 29, 2020
da8223f
Google Place thingies (#2193)
Bibo-Joshi Nov 29, 2020
4359007
API 5.0 WP4.3: Handling of files in local mode (#2223)
Bibo-Joshi Nov 29, 2020
889e2a9
Merge branch 'master' into api-5.0-master
Bibo-Joshi Nov 29, 2020
eeb3b6d
Revert "temporarily test PRs to api-5.0-master"
Bibo-Joshi Nov 29, 2020
a9fc470
Fix test_official
Bibo-Joshi Nov 29, 2020
3109533
Increase coverage
Bibo-Joshi Nov 29, 2020
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
6 changes: 6 additions & 0 deletions docs/source/telegram.chatlocation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ChatLocation
=====================

.. autoclass:: telegram.ChatLocation
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.messageid.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.MessageId
==================

.. autoclass:: telegram.MessageId
:members:
:show-inheritance:
6 changes: 6 additions & 0 deletions docs/source/telegram.proximityalerttriggered.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ProximityAlertTriggered
================================

.. autoclass:: telegram.ProximityAlertTriggered
:members:
:show-inheritance:
3 changes: 3 additions & 0 deletions docs/source/telegram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ telegram package
telegram.callbackquery
telegram.chat
telegram.chataction
telegram.chatlocation
telegram.chatmember
telegram.chatpermissions
telegram.chatphoto
Expand All @@ -37,12 +38,14 @@ telegram package
telegram.location
telegram.loginurl
telegram.message
telegram.messageid
telegram.messageentity
telegram.parsemode
telegram.photosize
telegram.poll
telegram.pollanswer
telegram.polloption
telegram.proximityalerttriggered
telegram.replykeyboardremove
telegram.replykeyboardmarkup
telegram.replymarkup
Expand Down
6 changes: 6 additions & 0 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .user import User
from .files.chatphoto import ChatPhoto
from .chat import Chat
from .chatlocation import ChatLocation
from .chatmember import ChatMember
from .chatpermissions import ChatPermissions
from .files.photosize import PhotoSize
Expand Down Expand Up @@ -50,9 +51,11 @@
from .files.file import File
from .parsemode import ParseMode
from .messageentity import MessageEntity
from .messageid import MessageId
from .games.game import Game
from .poll import Poll, PollOption, PollAnswer
from .loginurl import LoginUrl
from .proximityalerttriggered import ProximityAlertTriggered
from .games.callbackgame import CallbackGame
from .payment.shippingaddress import ShippingAddress
from .payment.orderinfo import OrderInfo
Expand Down Expand Up @@ -189,6 +192,8 @@
'InputTextMessageContent',
'InputVenueMessageContent',
'Location',
'ChatLocation',
'ProximityAlertTriggered',
'EncryptedCredentials',
'PassportFile',
'EncryptedPassportElement',
Expand Down Expand Up @@ -268,4 +273,5 @@
'KeyboardButtonPollType',
'Dice',
'BotCommand',
'MessageId',
]
739 changes: 538 additions & 201 deletions telegram/bot.py

Large diffs are not rendered by default.

46 changes: 45 additions & 1 deletion telegram/callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from telegram.utils.types import JSONDict

if TYPE_CHECKING:
from telegram import Bot, GameHighScore, InlineKeyboardMarkup
from telegram import Bot, GameHighScore, InlineKeyboardMarkup, MessageId


class CallbackQuery(TelegramObject):
Expand Down Expand Up @@ -325,3 +325,47 @@ def delete_message(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:

"""
return self.message.delete(*args, **kwargs)

def pin_message(self, *args: Any, **kwargs: Any) -> bool:
"""Shortcut for::

bot.pin_chat_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.message.pin(*args, **kwargs)

def unpin_message(self, *args: Any, **kwargs: Any) -> bool:
"""Shortcut for::

bot.unpin_chat_message(chat_id=message.chat_id,
message_id=message.message_id,
*args,
**kwargs)

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.message.unpin(*args, **kwargs)

def copy_message(self, chat_id: int, *args: Any, **kwargs: Any) -> 'MessageId':
"""Shortcut for::

update.callback_query.message.copy(
chat_id,
from_chat_id=update.message.chat_id,
message_id=update.message.message_id,
*args,
**kwargs)

Returns:
:class:`telegram.MessageId`: On success, returns the MessageId of the sent message.

"""
return self.message.copy(chat_id, *args, **kwargs)
108 changes: 88 additions & 20 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
from telegram.utils.types import JSONDict

from .chatpermissions import ChatPermissions
from .chatlocation import ChatLocation

if TYPE_CHECKING:
from telegram import Bot, ChatMember, Message
from telegram import Bot, ChatMember, Message, MessageId


class Chat(TelegramObject):
Expand All @@ -44,10 +45,12 @@ class Chat(TelegramObject):
first_name (:obj:`str`): Optional. First name of the other party in a private chat.
last_name (:obj:`str`): Optional. Last name of the other party in a private chat.
photo (:class:`telegram.ChatPhoto`): Optional. Chat photo.
bio (:obj:`str`): Optional. Bio of the other party in a private chat. Returned only in
:meth:`telegram.Bot.get_chat`.
description (:obj:`str`): Optional. Description, for groups, supergroups and channel chats.
invite_link (:obj:`str`): Optional. Chat invite link, for supergroups and channel chats.
pinned_message (:class:`telegram.Message`): Optional. Pinned message, for supergroups.
Returned only in :meth:`telegram.Bot.get_chat`.
pinned_message (:class:`telegram.Message`): Optional. The most recent pinned message
(by sending date). Returned only in :meth:`telegram.Bot.get_chat`.
permissions (:class:`telegram.ChatPermissions`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in :meth:`telegram.Bot.get_chat`.
slow_mode_delay (:obj:`int`): Optional. For supergroups, the minimum allowed delay between
Expand All @@ -56,6 +59,11 @@ class Chat(TelegramObject):
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
can_set_sticker_set (:obj:`bool`): Optional. :obj:`True`, if the bot can change group the
sticker set.
linked_chat_id (:obj:`int`): Optional. Unique identifier for the linked chat, i.e. the
discussion group identifier for a channel and vice versa; for supergroups and channel
chats. Returned only in :meth:`telegram.Bot.get_chat`.
location (:class:`telegram.ChatLocation`): Optional. For supergroups, the location to which
the supergroup is connected. Returned only in :meth:`telegram.Bot.get_chat`.

Args:
id (:obj:`int`): Unique identifier for this chat. This number may be greater than 32 bits
Expand All @@ -71,14 +79,16 @@ class Chat(TelegramObject):
last_name(:obj:`str`, optional): Last name of the other party in a private chat.
photo (:class:`telegram.ChatPhoto`, optional): Chat photo.
Returned only in :meth:`telegram.Bot.get_chat`.
bio (:obj:`str`, optional): Bio of the other party in a private chat. Returned only in
:meth:`telegram.Bot.get_chat`.
description (:obj:`str`, optional): Description, for groups, supergroups and channel chats.
Returned only in :meth:`telegram.Bot.get_chat`.
invite_link (:obj:`str`, optional): Chat invite link, for groups, supergroups and channel
chats. Each administrator in a chat generates their own invite links, so the bot must
first generate the link using ``export_chat_invite_link()``. Returned only
in :meth:`telegram.Bot.get_chat`.
pinned_message (:class:`telegram.Message`, optional): Pinned message, for groups,
supergroups and channels. Returned only in :meth:`telegram.Bot.get_chat`.
pinned_message (:class:`telegram.Message`, optional): The most recent pinned message
(by sending date). Returned only in :meth:`telegram.Bot.get_chat`.
permissions (:class:`telegram.ChatPermissions`): Optional. Default chat member permissions,
for groups and supergroups. Returned only in :meth:`telegram.Bot.get_chat`.
slow_mode_delay (:obj:`int`, optional): For supergroups, the minimum allowed delay between
Expand All @@ -89,6 +99,11 @@ class Chat(TelegramObject):
Returned only in :meth:`telegram.Bot.get_chat`.
can_set_sticker_set (:obj:`bool`, optional): :obj:`True`, if the bot can change group the
sticker set. Returned only in :meth:`telegram.Bot.get_chat`.
linked_chat_id (:obj:`int`, optional): Unique identifier for the linked chat, i.e. the
discussion group identifier for a channel and vice versa; for supergroups and channel
chats. Returned only in :meth:`telegram.Bot.get_chat`.
location (:class:`telegram.ChatLocation`, optional): For supergroups, the location to which
the supergroup is connected. Returned only in :meth:`telegram.Bot.get_chat`.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""
Expand Down Expand Up @@ -119,6 +134,9 @@ def __init__(
sticker_set_name: str = None,
can_set_sticker_set: bool = None,
slow_mode_delay: int = None,
bio: str = None,
linked_chat_id: int = None,
location: ChatLocation = None,
**_kwargs: Any,
):
# Required
Expand All @@ -132,13 +150,16 @@ def __init__(
# TODO: Remove (also from tests), when Telegram drops this completely
self.all_members_are_administrators = _kwargs.get('all_members_are_administrators')
self.photo = photo
self.bio = bio
self.description = description
self.invite_link = invite_link
self.pinned_message = pinned_message
self.permissions = permissions
self.slow_mode_delay = slow_mode_delay
self.sticker_set_name = sticker_set_name
self.can_set_sticker_set = can_set_sticker_set
self.linked_chat_id = linked_chat_id
self.location = location

self.bot = bot
self._id_attrs = (self.id,)
Expand All @@ -151,21 +172,6 @@ def link(self) -> Optional[str]:
return f"https://t.me/{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 All @@ -178,6 +184,7 @@ def de_json(cls, data: JSONDict, bot: 'Bot') -> Optional['Chat']:

data['pinned_message'] = Message.de_json(data.get('pinned_message'), bot)
data['permissions'] = ChatPermissions.de_json(data.get('permissions'), bot)
data['location'] = ChatLocation.de_json(data.get('location'), bot)

return cls(bot=bot, **data)

Expand Down Expand Up @@ -277,6 +284,45 @@ def set_administrator_custom_title(self, *args: Any, **kwargs: Any) -> bool:
"""
return self.bot.set_chat_administrator_custom_title(self.id, *args, **kwargs)

def pin_message(self, *args: Any, **kwargs: Any) -> bool:
"""Shortcut for::

bot.pin_chat_message(chat_id=update.effective_chat.id,
*args,
**kwargs)

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.bot.pin_chat_message(self.id, *args, **kwargs)

def unpin_message(self, *args: Any, **kwargs: Any) -> bool:
"""Shortcut for::

bot.unpin_chat_message(chat_id=update.effective_chat.id,
*args,
**kwargs)

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.bot.unpin_chat_message(self.id, *args, **kwargs)

def unpin_all_messages(self, *args: Any, **kwargs: Any) -> bool:
"""Shortcut for::

bot.unpin_all_chat_messages(chat_id=update.effective_chat.id,
*args,
**kwargs)

Returns:
:obj:`bool`: On success, :obj:`True` is returned.

"""
return self.bot.unpin_all_chat_messages(chat_id=self.id, *args, **kwargs)

def send_message(self, *args: Any, **kwargs: Any) -> 'Message':
"""Shortcut for::

Expand Down Expand Up @@ -477,3 +523,25 @@ def send_poll(self, *args: Any, **kwargs: Any) -> 'Message':

"""
return self.bot.send_poll(self.id, *args, **kwargs)

def send_copy(self, *args: Any, **kwargs: Any) -> 'MessageId':
"""Shortcut for::

bot.copy_message(chat_id=update.effective_chat.id, *args, **kwargs)

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

"""
return self.bot.copy_message(chat_id=self.id, *args, **kwargs)

def copy_message(self, *args: Any, **kwargs: Any) -> 'MessageId':
"""Shortcut for::

bot.copy_message(from_chat_id=update.effective_chat.id, *args, **kwargs)

Returns:
:class:`telegram.Message`: On success, instance representing the message posted.

"""
return self.bot.copy_message(from_chat_id=self.id, *args, **kwargs)
Loading