Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V13 API 6.2 implementation #3203

Merged
merged 7 commits into from Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
:target: https://pypi.org/project/python-telegram-bot/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-6.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.2-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -112,7 +112,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **6.1** are supported.
All types and methods of the Telegram Bot API **6.2** are supported.

==========
Installing
Expand Down
4 changes: 2 additions & 2 deletions README_RAW.rst
Expand Up @@ -20,7 +20,7 @@ We have a vibrant community of developers helping each other in our `Telegram gr
:target: https://pypi.org/project/python-telegram-bot-raw/
:alt: Supported Python versions

.. image:: https://img.shields.io/badge/Bot%20API-6.1-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.2-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions

Expand Down Expand Up @@ -105,7 +105,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================

All types and methods of the Telegram Bot API **6.1** are supported.
All types and methods of the Telegram Bot API **6.2** are supported.

==========
Installing
Expand Down
46 changes: 45 additions & 1 deletion telegram/bot.py
Expand Up @@ -4813,6 +4813,36 @@ def get_sticker_set(

return StickerSet.de_json(result, self) # type: ignore[return-value, arg-type]

@log
def get_custom_emoji_stickers(
self,
custom_emoji_ids: List[str],
*,
timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List[Sticker]:
# skipcq: FLK-D207
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
"""
Use this method to get information about emoji stickers by their identifiers.

Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
Args:
custom_emoji_ids (List[:obj:`str`]): List of custom emoji identifiers.
At most 200 custom emoji identifiers can be specified.
Keyword Args:
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during
creation of the connection pool).
api_kwargs (:obj:`dict`, optional): Arbitrary keyword arguments to be passed to the
Telegram API.
Returns:
List[:class:`telegram.Sticker`]
Raises:
:class:`telegram.error.TelegramError`
"""
data: JSONDict = {"custom_emoji_ids": custom_emoji_ids}
result = self._post("getCustomEmojiStickers", data, timeout=timeout, api_kwargs=api_kwargs)
return Sticker.de_list(result, self) # type: ignore[return-value, arg-type]

@log
def upload_sticker_file(
self,
Expand Down Expand Up @@ -4871,6 +4901,7 @@ def create_new_sticker_set(
tgs_sticker: FileInput = None,
api_kwargs: JSONDict = None,
webm_sticker: FileInput = None,
sticker_type: str = None,
) -> bool:
"""
Use this method to create new sticker set owned by a user.
Expand All @@ -4887,6 +4918,10 @@ def create_new_sticker_set(
The png_sticker and tgs_sticker argument can be either a file_id, an URL or a file from
disk ``open(filename, 'rb')``

.. versionchanged:: 13.14
The parameter ``contains_masks`` has been depreciated. Use ``sticker_type``
instead.

Args:
user_id (:obj:`int`): User identifier of created sticker set owner.
name (:obj:`str`): Short name of sticker set, to be used in t.me/addstickers/ URLs
Expand Down Expand Up @@ -4924,6 +4959,12 @@ def create_new_sticker_set(
should be created.
mask_position (:class:`telegram.MaskPosition`, optional): Position where the mask
should be placed on faces.
sticker_type (:obj:`str`, optional): Type of stickers in the set, pass
:attr:`telegram.Sticker.REGULAR` or :attr:`telegram.Sticker.MASK`. Custom emoji
sticker sets can't be created via the Bot API at the moment. By default, a
regular sticker set is created.

.. versionadded:: 13.13
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during
creation of the connection pool).
Expand Down Expand Up @@ -4951,7 +4992,8 @@ def create_new_sticker_set(
# We need to_json() instead of to_dict() here, because we're sending a media
# message here, which isn't json dumped by utils.request
data['mask_position'] = mask_position.to_json()

if sticker_type is not None:
data['sticker_type'] = sticker_type
result = self._post('createNewStickerSet', data, timeout=timeout, api_kwargs=api_kwargs)

return result # type: ignore[return-value]
Expand Down Expand Up @@ -6206,6 +6248,8 @@ def __hash__(self) -> int:
"""Alias for :meth:`unpin_all_chat_messages`"""
getStickerSet = get_sticker_set
"""Alias for :meth:`get_sticker_set`"""
getCustomEmojiStickers = get_custom_emoji_stickers
"""Alias for :meth:`get_custom_emoji_stickers`"""
uploadStickerFile = upload_sticker_file
"""Alias for :meth:`upload_sticker_file`"""
createNewStickerSet = create_new_sticker_set
Expand Down
12 changes: 12 additions & 0 deletions telegram/chat.py
Expand Up @@ -126,6 +126,10 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat`.

.. versionadded:: 13.13
has_restricted_voice_and_video_messages (:obj:`bool`, optional): :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat. Returned only in :meth:`telegram.Bot.get_chat`.
.. versionadded:: 13.14
Bibo-Joshi marked this conversation as resolved.
Show resolved Hide resolved
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

Attributes:
Expand Down Expand Up @@ -180,6 +184,11 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat`.

.. versionadded:: 13.13
has_restricted_voice_and_video_messages (:obj:`bool`): Optional. :obj:`True`, if the
privacy settings of the other party restrict sending voice and video note messages
in the private chat. Returned only in :meth:`telegram.Bot.get_chat`.

.. versionadded:: 13.14
"""

__slots__ = (
Expand Down Expand Up @@ -207,6 +216,7 @@ class Chat(TelegramObject):
'has_private_forwards',
'join_to_send_messages',
'join_by_request',
'has_restricted_voice_and_video_messages',
'_id_attrs',
)

Expand Down Expand Up @@ -249,6 +259,7 @@ def __init__(
has_protected_content: bool = None,
join_to_send_messages: bool = None,
join_by_request: bool = None,
has_restricted_voice_and_video_messages: bool = None,
**_kwargs: Any,
):
# Required
Expand Down Expand Up @@ -279,6 +290,7 @@ def __init__(
self.location = location
self.join_to_send_messages = join_to_send_messages
self.join_by_request = join_by_request
self.has_restricted_voice_and_video_messages = has_restricted_voice_and_video_messages

self.bot = bot
self._id_attrs = (self.id,)
Expand Down
26 changes: 24 additions & 2 deletions telegram/constants.py
Expand Up @@ -21,7 +21,7 @@
`Telegram Bots API <https://core.telegram.org/bots/api>`_.

Attributes:
BOT_API_VERSION (:obj:`str`): `6.1`. Telegram Bot API version supported by this
BOT_API_VERSION (:obj:`str`): `6.2`. Telegram Bot API version supported by this
version of `python-telegram-bot`. Also available as ``telegram.bot_api_version``.

.. versionadded:: 13.4
Expand Down Expand Up @@ -144,6 +144,9 @@
MESSAGEENTITY_SPOILER (:obj:`str`): ``'spoiler'``

.. versionadded:: 13.10
MESSAGEENTITY_CUSTOM_EMOJI (:obj:`str`): ``'custom_emoji'``

.. versionadded:: 13.14
MESSAGEENTITY_ALL_TYPES (List[:obj:`str`]): List of all the types of message entity.

:class:`telegram.ParseMode`:
Expand All @@ -160,6 +163,19 @@
POLL_QUIZ (:obj:`str`): ``'quiz'``
MAX_POLL_QUESTION_LENGTH (:obj:`int`): 300
MAX_POLL_OPTION_LENGTH (:obj:`int`): 100
:class:`telegram.Sticker`:

Attributes:

STICKER_REGULAR (:obj:`str`)= ``'regular'``

.. versionadded:: 13.14
STICKER_MASK (:obj:`str`) = ``'mask'``

.. versionadded:: 13.14
STICKER_CUSTOM_EMOJI (:obj:`str`) = ``'custom_emoji'``

.. versionadded:: 13.14

:class:`telegram.MaskPosition`:

Expand Down Expand Up @@ -247,7 +263,7 @@
"""
from typing import List

BOT_API_VERSION: str = '6.1'
BOT_API_VERSION: str = '6.2'
MAX_MESSAGE_LENGTH: int = 4096
MAX_CAPTION_LENGTH: int = 1024
ANONYMOUS_ADMIN_ID: int = 1087968824
Expand Down Expand Up @@ -325,6 +341,7 @@
MESSAGEENTITY_UNDERLINE: str = 'underline'
MESSAGEENTITY_STRIKETHROUGH: str = 'strikethrough'
MESSAGEENTITY_SPOILER: str = 'spoiler'
MESSAGEENTITY_CUSTOM_EMOJI: str = 'custom_emoji'
MESSAGEENTITY_ALL_TYPES: List[str] = [
MESSAGEENTITY_MENTION,
MESSAGEENTITY_HASHTAG,
Expand All @@ -342,6 +359,7 @@
MESSAGEENTITY_UNDERLINE,
MESSAGEENTITY_STRIKETHROUGH,
MESSAGEENTITY_SPOILER,
MESSAGEENTITY_CUSTOM_EMOJI,
]

PARSEMODE_MARKDOWN: str = 'Markdown'
Expand All @@ -353,6 +371,10 @@
MAX_POLL_QUESTION_LENGTH: int = 300
MAX_POLL_OPTION_LENGTH: int = 100

STICKER_REGULAR: str = "regular"
STICKER_MASK: str = "mask"
STICKER_CUSTOM_EMOJI: str = "custom_emoji"

STICKER_FOREHEAD: str = 'forehead'
STICKER_EYES: str = 'eyes'
STICKER_MOUTH: str = 'mouth'
Expand Down