Compare commits

..

15 Commits

Author SHA1 Message Date
Hinrich Mahler 28afeccf70 Bump version to v20.0b0 2022-12-15 15:54:00 +01:00
Bibo-Joshi 9467847d74 Documentation Improvements (#3386)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
Co-authored-by: Viicos <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
2022-12-15 15:20:04 +01:00
Bibo-Joshi b11a0c7778 Make TelegramObject Immutable (#3249) 2022-12-15 15:00:36 +01:00
Bibo-Joshi ff645c6fe2 Reduce Code Duplication in Testing Defaults (#3419) 2022-12-12 10:51:33 +01:00
dependabot[bot] 9c3053b3f9 Bump pytest-xdist from 3.0.2 to 3.1.0 (#3415) 2022-12-11 15:28:12 +01:00
dependabot[bot] 5a6c9cc777 Bump pytest-asyncio from 0.20.2 to 0.20.3 (#3417) 2022-12-11 15:27:51 +01:00
pre-commit-ci[bot] 6e4a1f0a21 pre-commit autoupdate (#3409)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
2022-12-06 11:28:47 +01:00
Aditya f8be97c12c Add Notes and Warnings About Optional Dependencies (#3393) 2022-12-02 12:08:11 +01:00
Harshil 4123e7aa57 Simplify Internals of Bot Methods (#3396) 2022-12-01 19:26:01 +01:00
Dmitry Kolomatskiy 637cc574ab Reduce Code Duplication in Several Bot Methods (#3385) 2022-11-26 19:05:44 +01:00
Hinrich Mahler 3042f187ed Bump version to v20.0a6 2022-11-24 12:32:43 +01:00
Bibo-Joshi 867f742d08 Only Persist Arbitrary callback_data if ExtBot.callback_data_cache is Present (#3384) 2022-11-24 12:13:54 +01:00
Harshil 1724212458 Improve Backwards Compatibility of TelegramObjects Pickle Behavior (#3382)
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
2022-11-24 12:11:37 +01:00
Bibo-Joshi 05c6ca06f8 Fix Naming and Keyword Arguments of File.download_* Methods (#3380) 2022-11-24 12:09:51 +01:00
Poolitzer 8c03f0e2eb Fix Return Value Annotation of Chat.create_forum_topic (#3381)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
2022-11-23 13:21:10 +01:00
216 changed files with 3526 additions and 2211 deletions
+4 -4
View File
@@ -16,11 +16,11 @@ repos:
- --diff
- --check
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/pylint
rev: v2.15.5
rev: v2.15.8
hooks:
- id: pylint
files: ^(telegram|examples)/.*\.py$
@@ -38,7 +38,7 @@ repos:
- aiolimiter~=1.0.0
- . # this basically does `pip install -e .`
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
name: mypy-ptb
@@ -65,7 +65,7 @@ repos:
- cachetools~=5.2.0
- . # this basically does `pip install -e .`
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
rev: v3.3.0
hooks:
- id: pyupgrade
files: ^(telegram|examples|tests)/.*\.py$
+58
View File
@@ -1,6 +1,64 @@
=========
Changelog
=========
Version 20.0b0
==============
*Released 2022-12-15*
This is the technical changelog for version 20.0b0. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel <https://t.me/pythontelegrambotchannel>`_.
Major Changes
-------------
- Make `TelegramObject` Immutable (`#3249`_)
Minor Changes, Documentation Improvements and CI
------------------------------------------------
- Reduce Code Duplication in Testing ``Defaults`` (`#3419`_)
- Add Notes and Warnings About Optional Dependencies (`#3393`_)
- Simplify Internals of ``Bot`` Methods (`#3396`_)
- Reduce Code Duplication in Several ``Bot`` Methods (`#3385`_)
- Documentation Improvements (`#3386`_, `#3395`_, `#3398`_, `#3403`_)
Dependencies
------------
- Bump ``pytest-xdist`` from 3.0.2 to 3.1.0 (`#3415`_)
- Bump ``pytest-asyncio`` from 0.20.2 to 0.20.3 (`#3417`_)
- ``pre-commit`` autoupdate (`#3409`_)
.. _`#3249`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3249
.. _`#3419`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3419
.. _`#3393`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3393
.. _`#3396`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3396
.. _`#3385`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3385
.. _`#3386`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3386
.. _`#3395`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3395
.. _`#3398`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3398
.. _`#3403`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3403
.. _`#3415`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3415
.. _`#3417`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3417
.. _`#3409`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3409
Version 20.0a6
==============
*Released 2022-11-24*
This is the technical changelog for version 20.0a6. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel <https://t.me/pythontelegrambotchannel>`_.
Bug Fixes
---------
- Only Persist Arbitrary ``callback_data`` if ``ExtBot.callback_data_cache`` is Present (`#3384`_)
- Improve Backwards Compatibility of ``TelegramObjects`` Pickle Behavior (`#3382`_)
- Fix Naming and Keyword Arguments of ``File.download_*`` Methods (`#3380`_)
- Fix Return Value Annotation of ``Chat.create_forum_topic`` (`#3381`_)
.. _`#3384`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3384
.. _`#3382`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3382
.. _`#3380`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3380
.. _`#3381`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3381
Version 20.0a5
==============
+1 -1
View File
@@ -1,6 +1,6 @@
sphinx==5.3.0
sphinx-pypi-upload
furo==2022.9.29
furo==2022.12.7
git+https://github.com/harshil21/furo-sphinx-search@be5cfa221a01f6e259bb2bb1f76d6ede7ffc1f11#egg=furo-sphinx-search
sphinx-paramlinks==0.5.4
sphinxcontrib-mermaid==0.7.1
+2 -2
View File
@@ -29,9 +29,9 @@ author = "Leandro Toledo"
# built documents.
#
# The short X.Y version.
version = "20.0a5" # telegram.__version__[:3]
version = "20.0b0" # telegram.__version__[:3]
# The full version, including alpha/beta/rc tags.
release = "20.0a5" # telegram.__version__
release = "20.0b0" # telegram.__version__
# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = "5.1.1"
+3
View File
@@ -40,6 +40,7 @@ up a job to send a message to that user after 30 seconds. The user can
also cancel the timer by sending ``/unset``. To learn more about the
``JobQueue``, read `this wiki
article <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue>`__.
Note: To use ``JobQueue``, you must install PTB via ``pip install python-telegram-bot[job-queue]``
:any:`examples.conversationbot`
-------------------------------
@@ -115,6 +116,7 @@ Dont forget to enable and configure payments with
`@BotFather <https://telegram.me/BotFather>`_. Check out this
`guide <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport>`__
on Telegram passports in PTB.
Note: To use Telegram Passport, you must install PTB via ``pip install python-telegram-bot[passport]``
:any:`examples.paymentbot`
--------------------------
@@ -162,6 +164,7 @@ combination with ``telegram.ext.Application``.
This example showcases how PTBs “arbitrary callback data” feature can be
used.
Note: To use arbitrary callback data, you must install PTB via ``pip install python-telegram-bot[callback-data]``
Pure API
--------
+1
View File
@@ -2,6 +2,7 @@ Available Types
---------------
.. toctree::
:titlesonly:
telegram.animation
telegram.audio
+1
View File
@@ -2,6 +2,7 @@ Arbitrary Callback Data
-----------------------
.. toctree::
:titlesonly:
telegram.ext.callbackdatacache
telegram.ext.invalidcallbackdata
@@ -2,6 +2,7 @@ Handlers
--------
.. toctree::
:titlesonly:
telegram.ext.basehandler
telegram.ext.callbackqueryhandler
@@ -2,6 +2,7 @@ Persistence
-----------
.. toctree::
:titlesonly:
telegram.ext.basepersistence
telegram.ext.dictpersistence
@@ -2,6 +2,7 @@ Rate Limiting
-------------
.. toctree::
:titlesonly:
telegram.ext.baseratelimiter
telegram.ext.aioratelimiter
+1
View File
@@ -2,6 +2,7 @@ Games
-----
.. toctree::
:titlesonly:
telegram.callbackgame
telegram.game
+1
View File
@@ -2,6 +2,7 @@ Inline Mode
-----------
.. toctree::
:titlesonly:
telegram.choseninlineresult
telegram.inlinequery
+1
View File
@@ -2,6 +2,7 @@ Passport
--------
.. toctree::
:titlesonly:
telegram.credentials
telegram.datacredentials
+1
View File
@@ -2,6 +2,7 @@ Payments
--------
.. toctree::
:titlesonly:
telegram.invoice
telegram.labeledprice
+2
View File
@@ -4,6 +4,8 @@ telegram.request Module
.. versionadded:: 20.0
.. toctree::
:titlesonly:
telegram.request.baserequest
telegram.request.requestdata
telegram.request.httpxrequest
+1
View File
@@ -2,6 +2,7 @@ Stickers
--------
.. toctree::
:titlesonly:
telegram.maskposition
telegram.sticker
+1 -1
View File
@@ -4,4 +4,4 @@ telegram.TelegramObject
.. autoclass:: telegram.TelegramObject
:members:
:show-inheritance:
:special-members: __repr__, __getitem__, __eq__, __hash__, __setstate__, __getstate__, __deepcopy__
:special-members: __repr__, __getitem__, __eq__, __hash__, __setstate__, __getstate__, __deepcopy__, __setattr__, __delattr__
+1
View File
@@ -2,6 +2,7 @@ Auxiliary modules
=================
.. toctree::
:titlesonly:
telegram.constants
telegram.error
+7 -1
View File
@@ -40,4 +40,10 @@
.. |disable_notification| replace:: Sends the message silently. Users will receive a notification with no sound.
.. |reply_to_msg_id| replace:: If the message is a reply, ID of the original message.
.. |reply_to_msg_id| replace:: If the message is a reply, ID of the original message.
.. |sequenceclassargs| replace:: Accepts any :class:`collections.abc.Sequence` as input instead of just a list. The input is converted to a tuple.
.. |tupleclassattrs| replace:: This attribute is now an immutable tuple.
.. |alwaystuple| replace:: This attribute is now always a tuple, that may be empty.
+4
View File
@@ -6,6 +6,10 @@
For detailed info on arbitrary callback data, see the wiki page at
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Arbitrary-callback_data
Note:
To use arbitrary callback data, you must install PTB via
`pip install python-telegram-bot[callback-data]`
"""
import logging
from typing import List, Tuple, cast
+1 -1
View File
@@ -81,7 +81,7 @@ async def photo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Stores the photo and asks for a location."""
user = update.message.from_user
photo_file = await update.message.photo[-1].get_file()
await photo_file.download_to_memory("user_photo.jpg")
await photo_file.download_to_drive("user_photo.jpg")
logger.info("Photo of %s: %s", user.first_name, "user_photo.jpg")
await update.message.reply_text(
"Gorgeous! Now, send me your location please, or send /skip if you don't want to."
+8 -5
View File
@@ -10,6 +10,9 @@ See https://telegram.org/blog/passport for info about what telegram passport is.
See https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport
for how to use Telegram Passport properly with python-telegram-bot.
Note:
To use Telegram Passport, you must install PTB via
`pip install python-telegram-bot[passport]`
"""
import logging
from pathlib import Path
@@ -77,25 +80,25 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
for file in data.files:
actual_file = await file.get_file()
print(actual_file)
await actual_file.download_to_memory()
await actual_file.download_to_drive()
if (
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
and data.front_side
):
front_file = await data.front_side.get_file()
print(data.type, front_file)
await front_file.download_to_memory()
await front_file.download_to_drive()
if data.type in ("driver_license" and "identity_card") and data.reverse_side:
reverse_file = await data.reverse_side.get_file()
print(data.type, reverse_file)
await reverse_file.download_to_memory()
await reverse_file.download_to_drive()
if (
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
and data.selfie
):
selfie_file = await data.selfie.get_file()
print(data.type, selfie_file)
await selfie_file.download_to_memory()
await selfie_file.download_to_drive()
if data.translation and data.type in (
"passport",
"driver_license",
@@ -111,7 +114,7 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
for file in data.translation:
actual_file = await file.get_file()
print(actual_file)
await actual_file.download_to_memory()
await actual_file.download_to_drive()
def main() -> None:
+4
View File
@@ -16,6 +16,10 @@ Usage:
Basic Alarm Bot example, sends a message after a set time.
Press Ctrl-C on the command line or send a signal to the process to stop the
bot.
Note:
To use arbitrary callback data, you must install ptb via
`pip install python-telegram-bot[callback-data]`
"""
import logging
+2 -2
View File
@@ -1,9 +1,9 @@
pre-commit
pytest==7.2.0
pytest-asyncio==0.20.2
pytest-asyncio==0.20.3
pytest-timeout==2.1.0 # used to timeout tests
pytest-xdist==3.0.2 # xdist runs tests in parallel
pytest-xdist==3.1.0 # xdist runs tests in parallel
flaky # Used for flaky tests (flaky decorator)
beautifulsoup4 # used in test_official for parsing tg docs
+2
View File
@@ -21,6 +21,7 @@ disable = duplicate-code,too-many-arguments,too-many-public-methods,too-few-publ
missing-class-docstring,too-many-locals,too-many-lines,too-many-branches,
too-many-statements
enable=useless-suppression ; Warns about unused pylint ignores
exclude-protected=_unfrozen
[tool:pytest]
testpaths = tests
@@ -60,6 +61,7 @@ disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
show_error_codes = True
implicit_optional = True
# For some files, it's easier to just disable strict-optional all together instead of
# cluttering the code with `# type: ignore`s or stuff like
+598 -740
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -55,6 +55,8 @@ class BotCommand(TelegramObject):
self._id_attrs = (self.command, self.description)
self._freeze()
MIN_COMMAND: ClassVar[int] = constants.BotCommandLimit.MIN_COMMAND
""":const:`telegram.constants.BotCommandLimit.MIN_COMMAND`
+22 -13
View File
@@ -80,6 +80,8 @@ class BotCommandScope(TelegramObject):
self.type = type
self._id_attrs = (self.type,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BotCommandScope"]:
"""Converts JSON data to the appropriate :class:`BotCommandScope` object, i.e. takes
@@ -128,6 +130,7 @@ class BotCommandScopeDefault(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.DEFAULT, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllPrivateChats(BotCommandScope):
@@ -143,6 +146,7 @@ class BotCommandScopeAllPrivateChats(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_PRIVATE_CHATS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllGroupChats(BotCommandScope):
@@ -157,6 +161,7 @@ class BotCommandScopeAllGroupChats(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_GROUP_CHATS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllChatAdministrators(BotCommandScope):
@@ -171,6 +176,7 @@ class BotCommandScopeAllChatAdministrators(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_CHAT_ADMINISTRATORS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeChat(BotCommandScope):
@@ -193,10 +199,11 @@ class BotCommandScopeChat(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
class BotCommandScopeChatAdministrators(BotCommandScope):
@@ -219,10 +226,11 @@ class BotCommandScopeChatAdministrators(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_ADMINISTRATORS, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
class BotCommandScopeChatMember(BotCommandScope):
@@ -248,8 +256,9 @@ class BotCommandScopeChatMember(BotCommandScope):
def __init__(self, chat_id: Union[str, int], user_id: int, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_MEMBER, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self.user_id = user_id
self._id_attrs = (self.type, self.chat_id, self.user_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self.user_id = user_id
self._id_attrs = (self.type, self.chat_id, self.user_id)
+4 -2
View File
@@ -134,6 +134,8 @@ class CallbackQuery(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["CallbackQuery"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -590,7 +592,7 @@ class CallbackQuery(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List["GameHighScore"]:
) -> Tuple["GameHighScore", ...]:
"""Shortcut for either::
await update.callback_query.message.get_game_high_score(*args, **kwargs)
@@ -606,7 +608,7 @@ class CallbackQuery(TelegramObject):
:meth:`telegram.Message.get_game_high_scores`.
Returns:
List[:class:`telegram.GameHighScore`]
Tuple[:class:`telegram.GameHighScore`]
"""
if self.inline_message_id:
+19 -12
View File
@@ -20,15 +20,17 @@
"""This module contains an object that represents a Telegram Chat."""
from datetime import datetime
from html import escape
from typing import TYPE_CHECKING, ClassVar, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, ClassVar, List, Optional, Sequence, Tuple, Union
from telegram import constants
from telegram._chatlocation import ChatLocation
from telegram._chatpermissions import ChatPermissions
from telegram._files.chatphoto import ChatPhoto
from telegram._forumtopic import ForumTopic
from telegram._menubutton import MenuButton
from telegram._telegramobject import TelegramObject
from telegram._utils import enum
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import DVInput, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram.helpers import escape_markdown
@@ -152,7 +154,7 @@ class Chat(TelegramObject):
(has topics_ enabled).
.. versionadded:: 20.0
active_usernames (List[:obj:`str`], optional): If set, the list of all `active chat
active_usernames (Sequence[:obj:`str`], optional): If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels. Returned
only in :meth:`telegram.Bot.get_chat`.
@@ -233,10 +235,12 @@ class Chat(TelegramObject):
(has topics_ enabled).
.. versionadded:: 20.0
active_usernames (List[:obj:`str`]): Optional. If set, the list of all `active chat
active_usernames (Tuple[:obj:`str`]): Optional. If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels. Returned
only in :meth:`telegram.Bot.get_chat`.
This list is empty if the chat has no active usernames or this chat instance was not
obtained via :meth:`~telegram.Bot.get_chat`.
.. versionadded:: 20.0
emoji_status_custom_emoji_id (:obj:`str`): Optional. Custom emoji identifier of emoji
@@ -317,7 +321,7 @@ class Chat(TelegramObject):
join_by_request: bool = None,
has_restricted_voice_and_video_messages: bool = None,
is_forum: bool = None,
active_usernames: List[str] = None,
active_usernames: Sequence[str] = None,
emoji_status_custom_emoji_id: str = None,
*,
api_kwargs: JSONDict = None,
@@ -351,11 +355,13 @@ class Chat(TelegramObject):
self.join_by_request = join_by_request
self.has_restricted_voice_and_video_messages = has_restricted_voice_and_video_messages
self.is_forum = is_forum
self.active_usernames = active_usernames
self.active_usernames = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id = emoji_status_custom_emoji_id
self._id_attrs = (self.id,)
self._freeze()
@property
def full_name(self) -> Optional[str]:
"""
@@ -545,7 +551,7 @@ class Chat(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List["ChatMember"]:
) -> Tuple["ChatMember", ...]:
"""Shortcut for::
await bot.get_chat_administrators(update.effective_chat.id, *args, **kwargs)
@@ -554,7 +560,7 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat_administrators`.
Returns:
List[:class:`telegram.ChatMember`]: A list of administrators in a chat. An Array of
Tuple[:class:`telegram.ChatMember`]: A tuple of administrators in a chat. An Array of
:class:`telegram.ChatMember` objects that contains information about all
chat administrators except other bots. If the chat is a group or a supergroup
and no administrators were appointed, only the creator will be returned.
@@ -1291,7 +1297,7 @@ class Chat(TelegramObject):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
) -> List["Message"]:
) -> Tuple["Message", ...]:
"""Shortcut for::
await bot.send_media_group(update.effective_chat.id, *args, **kwargs)
@@ -1299,7 +1305,8 @@ class Chat(TelegramObject):
For the documentation of the arguments, please see :meth:`telegram.Bot.send_media_group`.
Returns:
List[:class:`telegram.Message`]: On success, instance representing the message posted.
Tuple[:class:`telegram.Message`]: On success, a tuple of :class:`~telegram.Message`
instances that were sent is returned.
"""
return await self.get_bot().send_media_group(
@@ -2628,7 +2635,7 @@ class Chat(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
) -> ForumTopic:
"""Shortcut for::
await bot.create_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs)
@@ -2639,7 +2646,7 @@ class Chat(TelegramObject):
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
:class:`telegram.ForumTopic`
"""
return await self.get_bot().create_forum_topic(
chat_id=self.id,
@@ -2832,7 +2839,7 @@ class Chat(TelegramObject):
await bot.get_chat_menu_button(chat_id=update.effective_chat.id, *args, **kwargs)
For the documentation of the arguments, please see
:meth:`telegram.Bot.set_chat_menu_button`.
:meth:`telegram.Bot.get_chat_menu_button`.
Caution:
Can only work, if the chat is a private chat.
+2
View File
@@ -167,6 +167,8 @@ class ChatAdministratorRights(TelegramObject):
self.can_manage_topics,
)
self._freeze()
@classmethod
def all_rights(cls) -> "ChatAdministratorRights":
"""
+2
View File
@@ -141,6 +141,8 @@ class ChatInviteLink(TelegramObject):
self.is_revoked,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatInviteLink"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -88,6 +88,8 @@ class ChatJoinRequest(TelegramObject):
self._id_attrs = (self.chat, self.from_user, self.date)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatJoinRequest"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -62,6 +62,8 @@ class ChatLocation(TelegramObject):
self._id_attrs = (self.location,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatLocation"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+36 -28
View File
@@ -98,6 +98,8 @@ class ChatMember(TelegramObject):
self._id_attrs = (self.user, self.status)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMember"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -159,8 +161,9 @@ class ChatMemberOwner(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.OWNER, user=user, api_kwargs=api_kwargs)
self.is_anonymous = is_anonymous
self.custom_title = custom_title
with self._unfrozen():
self.is_anonymous = is_anonymous
self.custom_title = custom_title
class ChatMemberAdministrator(ChatMember):
@@ -295,20 +298,21 @@ class ChatMemberAdministrator(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.ADMINISTRATOR, user=user, api_kwargs=api_kwargs)
self.can_be_edited = can_be_edited
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title
with self._unfrozen():
self.can_be_edited = can_be_edited
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title
class ChatMemberMember(ChatMember):
@@ -337,6 +341,7 @@ class ChatMemberMember(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.MEMBER, user=user, api_kwargs=api_kwargs)
self._freeze()
class ChatMemberRestricted(ChatMember):
@@ -439,17 +444,18 @@ class ChatMemberRestricted(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.RESTRICTED, user=user, api_kwargs=api_kwargs)
self.is_member = is_member
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date
with self._unfrozen():
self.is_member = is_member
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date
class ChatMemberLeft(ChatMember):
@@ -477,6 +483,7 @@ class ChatMemberLeft(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.LEFT, user=user, api_kwargs=api_kwargs)
self._freeze()
class ChatMemberBanned(ChatMember):
@@ -510,4 +517,5 @@ class ChatMemberBanned(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.BANNED, user=user, api_kwargs=api_kwargs)
self.until_date = until_date
with self._unfrozen():
self.until_date = until_date
+2
View File
@@ -108,6 +108,8 @@ class ChatMemberUpdated(TelegramObject):
self.new_chat_member,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMemberUpdated"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -142,6 +142,8 @@ class ChatPermissions(TelegramObject):
self.can_manage_topics,
)
self._freeze()
@classmethod
def all_permissions(cls) -> "ChatPermissions":
"""
+2
View File
@@ -86,6 +86,8 @@ class ChosenInlineResult(TelegramObject):
self._id_attrs = (self.result_id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChosenInlineResult"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -88,6 +88,8 @@ class Dice(TelegramObject):
self._id_attrs = (self.value, self.emoji)
self._freeze()
DICE: ClassVar[str] = constants.DiceEmoji.DICE # skipcq: PTC-W0052
""":const:`telegram.constants.DiceEmoji.DICE`"""
DARTS: ClassVar[str] = constants.DiceEmoji.DARTS
+1 -1
View File
@@ -79,7 +79,7 @@ class _BaseMedium(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file`
"""Convenience wrapper over :meth:`telegram.Bot.get_file`
For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`.
+8 -7
View File
@@ -82,10 +82,11 @@ class Animation(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
+8 -7
View File
@@ -86,10 +86,11 @@ class Audio(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.duration = duration
# Optional
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.duration = duration
# Optional
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_name = file_name
+4 -2
View File
@@ -100,6 +100,8 @@ class ChatPhoto(TelegramObject):
self.big_file_unique_id,
)
self._freeze()
async def get_small_file(
self,
*,
@@ -109,7 +111,7 @@ class ChatPhoto(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the small
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the small
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
chat photo
@@ -140,7 +142,7 @@ class ChatPhoto(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the
big (:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
chat photo
+2
View File
@@ -66,3 +66,5 @@ class Contact(TelegramObject):
self.vcard = vcard
self._id_attrs = (self.phone_number,)
self._freeze()
+4 -3
View File
@@ -73,6 +73,7 @@ class Document(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Optional
self.mime_type = mime_type
self.file_name = file_name
+59 -18
View File
@@ -36,21 +36,21 @@ if TYPE_CHECKING:
class File(TelegramObject):
"""
This object represents a file ready to be downloaded. The file can be e.g. downloaded with
:attr:`download_to_memory`. It is guaranteed that the link will be valid for at least 1 hour.
:attr:`download_to_drive`. It is guaranteed that the link will be valid for at least 1 hour.
When the link expires, a new one can be requested by calling :meth:`telegram.Bot.get_file`.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`file_unique_id` is equal.
.. versionchanged:: 20.0:
``download`` was split into :meth:`download_to_memory` and :meth:`download_to_object`.
``download`` was split into :meth:`download_to_drive` and :meth:`download_to_memory`.
Note:
* Maximum file size to download is
:tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD`.
* If you obtain an instance of this class from :attr:`telegram.PassportFile.get_file`,
then it will automatically be decrypted as it downloads when you call e.g.
:meth:`download_to_memory`.
:meth:`download_to_drive`.
Args:
file_id (:obj:`str`): Identifier for this file, which can be used to download
@@ -59,7 +59,7 @@ class File(TelegramObject):
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`int`, optional): Optional. File size in bytes, if known.
file_path (:obj:`str`, optional): File path. Use e.g. :meth:`download_to_memory` to get the
file_path (:obj:`str`, optional): File path. Use e.g. :meth:`download_to_drive` to get the
file.
Attributes:
@@ -68,7 +68,7 @@ class File(TelegramObject):
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`str`): Optional. File size in bytes.
file_path (:obj:`str`): Optional. File path. Use e.g. :meth:`download_to_memory` to get
file_path (:obj:`str`): Optional. File path. Use e.g. :meth:`download_to_drive` to get
the file.
"""
@@ -102,6 +102,8 @@ class File(TelegramObject):
self._id_attrs = (self.file_unique_id,)
self._freeze()
def _get_encoded_url(self) -> str:
"""Convert any UTF-8 char in :obj:`File.file_path` into a url encoded ASCII string."""
sres = urllib_parse.urlsplit(str(self.file_path))
@@ -114,9 +116,10 @@ class File(TelegramObject):
def _prepare_decrypt(self, buf: bytes) -> bytes:
return decrypt(b64decode(self._credentials.secret), b64decode(self._credentials.hash), buf)
async def download_to_memory(
async def download_to_drive(
self,
custom_path: FilePathInput = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -130,14 +133,13 @@ class File(TelegramObject):
Note:
If :paramref:`custom_path` isn't provided and :attr:`file_path` is the path of a
local file (which is the case when a Bot API Server is running in local mode), this
method will just return the path.
local file (which is the case when a Bot API Server is running in local mode), this
method will just return the path.
The only exception to this are encrypted files (e.g. a passport file). For these, a
file with the prefix `decrypted_` will be created in the same directory as the
original file in order to decrypt the file without changing the existing one
in-place.
file with the prefix `decrypted_` will be created in the same directory as the
original file in order to decrypt the file without changing the existing one
in-place.
.. versionchanged:: 20.0
@@ -145,12 +147,13 @@ class File(TelegramObject):
* Returns :class:`pathlib.Path` object in cases where previously a :obj:`str` was
returned.
* This method was previously called ``download``. It was split into
:meth:`download_to_memory` and :meth:`download_to_object`.
:meth:`download_to_drive` and :meth:`download_to_memory`.
Args:
custom_path (:class:`pathlib.Path` | :obj:`str` , optional): The path where the file
will be saved to. If not specified, will be saved in the current working directory.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
@@ -207,9 +210,10 @@ class File(TelegramObject):
filename.write_bytes(buf)
return filename
async def download_to_object(
async def download_to_memory(
self,
out: BinaryIO,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -222,10 +226,11 @@ class File(TelegramObject):
.. versionadded:: 20.0
Args:
out (:obj:`io.BufferedIOBase`): A file-like object. Must be opened for writing in
binary mode.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
@@ -256,12 +261,42 @@ class File(TelegramObject):
buf = self._prepare_decrypt(buf)
out.write(buf)
async def download_as_bytearray(self, buf: bytearray = None) -> bytearray:
async def download_as_bytearray(
self,
buf: bytearray = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
) -> bytearray:
"""Download this file and return it as a bytearray.
Args:
buf (:obj:`bytearray`, optional): Extend the given bytearray with the downloaded data.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
Returns:
:obj:`bytearray`: The same object as :paramref:`buf` if it was specified. Otherwise a
newly allocated :obj:`bytearray`.
@@ -273,7 +308,13 @@ class File(TelegramObject):
if is_local_file(self.file_path):
bytes_data = Path(self.file_path).read_bytes()
else:
bytes_data = await self.get_bot().request.retrieve(self._get_encoded_url())
bytes_data = await self.get_bot().request.retrieve(
self._get_encoded_url(),
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
)
if self._credentials:
buf.extend(self._prepare_decrypt(bytes_data))
else:
+99 -41
View File
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Base class for Telegram InputMedia Objects."""
from typing import List, Optional, Tuple, Union
from typing import Optional, Sequence, Union
from telegram._files.animation import Animation
from telegram._files.audio import Audio
@@ -27,6 +27,7 @@ from telegram._files.photosize import PhotoSize
from telegram._files.video import Video
from telegram._messageentity import MessageEntity
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.files import parse_file_input
from telegram._utils.types import FileInput, JSONDict, ODVInput
@@ -55,7 +56,11 @@ class InputMedia(TelegramObject):
caption (:obj:`str`, optional): Caption of the media to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
parse_mode (:obj:`str`, optional): |parse_mode|
Attributes:
@@ -63,8 +68,13 @@ class InputMedia(TelegramObject):
media (:obj:`str` | :class:`telegram.InputFile`): Media to send.
caption (:obj:`str`): Optional. Caption of the media to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
"""
__slots__ = ("caption", "caption_entities", "media", "parse_mode", "type")
@@ -74,7 +84,7 @@ class InputMedia(TelegramObject):
media_type: str,
media: Union[str, InputFile, MediaType],
caption: str = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
*,
api_kwargs: JSONDict = None,
@@ -83,9 +93,11 @@ class InputMedia(TelegramObject):
self.type = media_type
self.media = media
self.caption = caption
self.caption_entities = caption_entities
self.caption_entities = parse_sequence_arg(caption_entities)
self.parse_mode = parse_mode
self._freeze()
@staticmethod
def _parse_thumb_input(thumb: Optional[FileInput]) -> Optional[Union[str, InputFile]]:
# We use local_mode=True because we don't have access to the actual setting and want
@@ -124,7 +136,11 @@ class InputMediaAnimation(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
width (:obj:`int`, optional): Animation width.
height (:obj:`int`, optional): Animation height.
duration (:obj:`int`, optional): Animation duration in seconds.
@@ -134,8 +150,13 @@ class InputMediaAnimation(InputMedia):
media (:obj:`str` | :class:`telegram.InputFile`): Animation to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
width (:obj:`int`): Optional. Animation width.
height (:obj:`int`): Optional. Animation height.
@@ -154,7 +175,7 @@ class InputMediaAnimation(InputMedia):
width: int = None,
height: int = None,
duration: int = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -177,10 +198,11 @@ class InputMediaAnimation(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.width = width
self.height = height
self.duration = duration
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.width = width
self.height = height
self.duration = duration
class InputMediaPhoto(InputMedia):
@@ -202,15 +224,22 @@ class InputMediaPhoto(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.PHOTO`.
media (:obj:`str` | :class:`telegram.InputFile`): Photo to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
"""
@@ -221,7 +250,7 @@ class InputMediaPhoto(InputMedia):
media: Union[FileInput, PhotoSize],
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -238,6 +267,8 @@ class InputMediaPhoto(InputMedia):
api_kwargs=api_kwargs,
)
self._freeze()
class InputMediaVideo(InputMedia):
"""Represents a video to be sent.
@@ -266,7 +297,11 @@ class InputMediaVideo(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
width (:obj:`int`, optional): Video width.
height (:obj:`int`, optional): Video height.
duration (:obj:`int`, optional): Video duration in seconds.
@@ -283,8 +318,12 @@ class InputMediaVideo(InputMedia):
media (:obj:`str` | :class:`telegram.InputFile`): Video file to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
width (:obj:`int`): Optional. Video width.
height (:obj:`int`): Optional. Video height.
duration (:obj:`int`): Optional. Video duration in seconds.
@@ -306,7 +345,7 @@ class InputMediaVideo(InputMedia):
supports_streaming: bool = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb: FileInput = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -330,11 +369,12 @@ class InputMediaVideo(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.width = width
self.height = height
self.duration = duration
self.thumb = self._parse_thumb_input(thumb)
self.supports_streaming = supports_streaming
with self._unfrozen():
self.width = width
self.height = height
self.duration = duration
self.thumb = self._parse_thumb_input(thumb)
self.supports_streaming = supports_streaming
class InputMediaAudio(InputMedia):
@@ -361,7 +401,11 @@ class InputMediaAudio(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
performer (:obj:`str`, optional): Performer of the audio as defined by sender or by audio
tags.
@@ -377,8 +421,12 @@ class InputMediaAudio(InputMedia):
media (:obj:`str` | :class:`telegram.InputFile`): Audio file to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
duration (:obj:`int`): Duration of the audio in seconds.
performer (:obj:`str`): Optional. Performer of the audio as defined by sender or by audio
tags.
@@ -398,7 +446,7 @@ class InputMediaAudio(InputMedia):
duration: int = None,
performer: str = None,
title: str = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -421,10 +469,11 @@ class InputMediaAudio(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.duration = duration
self.title = title
self.performer = performer
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.duration = duration
self.title = title
self.performer = performer
class InputMediaDocument(InputMedia):
@@ -446,7 +495,11 @@ class InputMediaDocument(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
thumb (:term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | :obj:`str`, \
optional): |thumbdocstringnopath|
@@ -461,8 +514,12 @@ class InputMediaDocument(InputMedia):
media (:obj:`str` | :class:`telegram.InputFile`): File to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
disable_content_type_detection (:obj:`bool`): Optional. Disables automatic server-side
content type detection for files uploaded using multipart/form-data. Always true, if
@@ -479,7 +536,7 @@ class InputMediaDocument(InputMedia):
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -495,5 +552,6 @@ class InputMediaDocument(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.disable_content_type_detection = disable_content_type_detection
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.disable_content_type_detection = disable_content_type_detection
+2
View File
@@ -93,6 +93,8 @@ class Location(TelegramObject):
self._id_attrs = (self.longitude, self.latitude)
self._freeze()
HORIZONTAL_ACCURACY: ClassVar[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
+4 -3
View File
@@ -68,6 +68,7 @@ class PhotoSize(_BaseMedium):
file_size=file_size,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
with self._unfrozen():
# Required
self.width = width
self.height = height
+31 -18
View File
@@ -17,14 +17,14 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains objects that represent stickers."""
from typing import TYPE_CHECKING, ClassVar, List, Optional
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence
from telegram import constants
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.file import File
from telegram._files.photosize import PhotoSize
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -150,18 +150,19 @@ class Sticker(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.is_animated = is_animated
self.is_video = is_video
self.type = type
# Optional
self.emoji = emoji
self.set_name = set_name
self.mask_position = mask_position
self.premium_animation = premium_animation
self.custom_emoji_id = custom_emoji_id
with self._unfrozen():
# Required
self.width = width
self.height = height
self.is_animated = is_animated
self.is_video = is_video
self.type = type
# Optional
self.emoji = emoji
self.set_name = set_name
self.mask_position = mask_position
self.premium_animation = premium_animation
self.custom_emoji_id = custom_emoji_id
REGULAR: ClassVar[str] = constants.StickerType.REGULAR
""":const:`telegram.constants.StickerType.REGULAR`"""
@@ -206,7 +207,11 @@ class StickerSet(TelegramObject):
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
stickers (Sequence[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
|sequenceclassargs|
sticker_type (:obj:`str`): Type of stickers in the set, currently one of
:attr:`telegram.Sticker.REGULAR`, :attr:`telegram.Sticker.MASK`,
:attr:`telegram.Sticker.CUSTOM_EMOJI`.
@@ -222,7 +227,11 @@ class StickerSet(TelegramObject):
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
stickers (Tuple[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
|tupleclassattrs|
sticker_type (:obj:`str`): Type of stickers in the set.
.. versionadded:: 20.0
@@ -246,7 +255,7 @@ class StickerSet(TelegramObject):
name: str,
title: str,
is_animated: bool,
stickers: List[Sticker],
stickers: Sequence[Sticker],
is_video: bool,
sticker_type: str,
thumb: PhotoSize = None,
@@ -258,13 +267,15 @@ class StickerSet(TelegramObject):
self.title = title
self.is_animated = is_animated
self.is_video = is_video
self.stickers = stickers
self.stickers = parse_sequence_arg(stickers)
self.sticker_type = sticker_type
# Optional
self.thumb = thumb
self._id_attrs = (self.name,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["StickerSet"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -339,3 +350,5 @@ class MaskPosition(TelegramObject):
self.scale = scale
self._id_attrs = (self.point, self.x_shift, self.y_shift, self.scale)
self._freeze()
+2
View File
@@ -97,6 +97,8 @@ class Venue(TelegramObject):
self._id_attrs = (self.location, self.title)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Venue"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+8 -7
View File
@@ -82,10 +82,11 @@ class Video(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
+4 -3
View File
@@ -73,6 +73,7 @@ class VideoNote(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.length = length
self.duration = duration
with self._unfrozen():
# Required
self.length = length
self.duration = duration
+5 -4
View File
@@ -67,7 +67,8 @@ class Voice(_BaseMedium):
file_size=file_size,
api_kwargs=api_kwargs,
)
# Required
self.duration = duration
# Optional
self.mime_type = mime_type
with self._unfrozen():
# Required
self.duration = duration
# Optional
self.mime_type = mime_type
+2
View File
@@ -83,6 +83,8 @@ class ForceReply(TelegramObject):
self._id_attrs = (self.selective,)
self._freeze()
MIN_INPUT_FIELD_PLACEHOLDER: ClassVar[int] = constants.ReplyLimit.MIN_INPUT_FIELD_PLACEHOLDER
""":const:`telegram.constants.ReplyLimit.MIN_INPUT_FIELD_PLACEHOLDER`
+4
View File
@@ -66,6 +66,8 @@ class ForumTopic(TelegramObject):
self._id_attrs = (self.message_thread_id, self.name, self.icon_color)
self._freeze()
class ForumTopicCreated(TelegramObject):
"""
@@ -107,6 +109,8 @@ class ForumTopicCreated(TelegramObject):
self._id_attrs = (self.name, self.icon_color)
self._freeze()
class ForumTopicClosed(TelegramObject):
"""
+30 -15
View File
@@ -17,14 +17,14 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Game."""
import sys
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence
from telegram._files.animation import Animation
from telegram._files.photosize import PhotoSize
from telegram._messageentity import MessageEntity
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -42,30 +42,46 @@ class Game(TelegramObject):
Args:
title (:obj:`str`): Title of the game.
description (:obj:`str`): Description of the game.
photo (List[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game message
in chats.
photo (Sequence[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
message in chats.
.. versionchanged:: 20.0
|sequenceclassargs|
text (:obj:`str`, optional): Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
using :meth:`telegram.Bot.edit_message_text`.
0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
text_entities (List[:class:`telegram.MessageEntity`], optional): Special entities that
text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that
appear in text, such as usernames, URLs, bot commands, etc.
.. versionchanged:: 20.0
|sequenceclassargs|
animation (:class:`telegram.Animation`, optional): Animation that will be displayed in the
game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.
Attributes:
title (:obj:`str`): Title of the game.
description (:obj:`str`): Description of the game.
photo (List[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game message
in chats.
photo (Tuple[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
message in chats.
.. versionchanged:: 20.0
|tupleclassattrs|
text (:obj:`str`): Optional. Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
using :meth:`telegram.Bot.edit_message_text`.
text_entities (List[:class:`telegram.MessageEntity`]): Special entities that
text_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special entities that
appear in text, such as usernames, URLs, bot commands, etc.
This list is empty if the message does not contain text entities.
.. versionchanged:: 20.0
|tupleclassattrs|
animation (:class:`telegram.Animation`): Optional. Animation that will be displayed in the
game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.
@@ -84,9 +100,9 @@ class Game(TelegramObject):
self,
title: str,
description: str,
photo: List[PhotoSize],
photo: Sequence[PhotoSize],
text: str = None,
text_entities: List[MessageEntity] = None,
text_entities: Sequence[MessageEntity] = None,
animation: Animation = None,
*,
api_kwargs: JSONDict = None,
@@ -95,14 +111,16 @@ class Game(TelegramObject):
# Required
self.title = title
self.description = description
self.photo = photo
self.photo = parse_sequence_arg(photo)
# Optionals
self.text = text
self.text_entities = text_entities or []
self.text_entities = parse_sequence_arg(text_entities)
self.animation = animation
self._id_attrs = (self.title, self.description, self.photo)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Game"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -178,6 +196,3 @@ class Game(TelegramObject):
for entity in self.text_entities
if entity.type in types
}
def __hash__(self) -> int:
return hash((self.title, self.description, tuple(p for p in self.photo)))
+2
View File
@@ -56,6 +56,8 @@ class GameHighScore(TelegramObject):
self._id_attrs = (self.position, self.user, self.score)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["GameHighScore"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+5 -2
View File
@@ -202,6 +202,8 @@ class InlineKeyboardButton(TelegramObject):
self._id_attrs = ()
self._set_id_attrs()
self._freeze()
def _set_id_attrs(self) -> None:
self._id_attrs = (
self.text,
@@ -239,8 +241,9 @@ class InlineKeyboardButton(TelegramObject):
Args:
callback_data (:class:`object`): The new callback data.
"""
self.callback_data = callback_data
self._set_id_attrs()
with self._unfrozen():
self.callback_data = callback_data
self._set_id_attrs()
MIN_CALLBACK_DATA: ClassVar[int] = constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA
""":const:`telegram.constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA`
+19 -13
View File
@@ -17,8 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram InlineKeyboardMarkup."""
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, List, Optional, Sequence
from telegram._inline.inlinekeyboardbutton import InlineKeyboardButton
from telegram._telegramobject import TelegramObject
@@ -41,12 +40,20 @@ class InlineKeyboardMarkup(TelegramObject):
* :any:`Inline Keyboard 2 <examples.inlinekeyboard2>`
Args:
inline_keyboard (List[List[:class:`telegram.InlineKeyboardButton`]]): List of button rows,
each represented by a list of InlineKeyboardButton objects.
inline_keyboard (Sequence[Sequence[:class:`telegram.InlineKeyboardButton`]]): Sequence of
button rows, each represented by a sequence of :class:`~telegram.InlineKeyboardButton`
objects.
.. versionchanged:: 20.0
|sequenceclassargs|
Attributes:
inline_keyboard (List[List[:class:`telegram.InlineKeyboardButton`]]): List of button rows,
each represented by a list of InlineKeyboardButton objects.
inline_keyboard (Tuple[Tuple[:class:`telegram.InlineKeyboardButton`]]): Tuple of
button rows, each represented by a tuple of :class:`~telegram.InlineKeyboardButton`
objects.
.. versionchanged:: 20.0
|tupleclassattrs|
"""
@@ -54,21 +61,23 @@ class InlineKeyboardMarkup(TelegramObject):
def __init__(
self,
inline_keyboard: List[List[InlineKeyboardButton]],
inline_keyboard: Sequence[Sequence[InlineKeyboardButton]],
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
if not check_keyboard_type(inline_keyboard):
raise ValueError(
"The parameter `inline_keyboard` should be a list of "
"list of InlineKeyboardButtons"
"The parameter `inline_keyboard` should be a sequence of sequences of "
"InlineKeyboardButtons"
)
# Required
self.inline_keyboard = inline_keyboard
self.inline_keyboard = tuple(tuple(row) for row in inline_keyboard)
self._id_attrs = (self.inline_keyboard,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["InlineKeyboardMarkup"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -134,6 +143,3 @@ class InlineKeyboardMarkup(TelegramObject):
"""
button_grid = [[button] for button in button_column]
return cls(button_grid, **kwargs) # type: ignore[arg-type]
def __hash__(self) -> int:
return hash(tuple(tuple(button for button in row) for row in self.inline_keyboard))
+2
View File
@@ -106,6 +106,8 @@ class InlineQuery(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["InlineQuery"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -64,6 +64,8 @@ class InlineQueryResult(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
MIN_ID_LENGTH: ClassVar[int] = constants.InlineQueryResultLimit.MIN_ID_LENGTH
""":const:`telegram.constants.InlineQueryResultLimit.MIN_ID_LENGTH`
+11 -10
View File
@@ -102,14 +102,15 @@ class InlineQueryResultArticle(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
self.title = title
self.input_message_content = input_message_content
with self._unfrozen():
self.title = title
self.input_message_content = input_message_content
# Optional
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optional
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+24 -15
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultAudio."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -49,7 +49,10 @@ class InlineQueryResultAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -68,7 +71,12 @@ class InlineQueryResultAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -99,21 +107,22 @@ class InlineQueryResultAudio(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
self.audio_url = audio_url
self.title = title
with self._unfrozen():
self.audio_url = audio_url
self.title = title
# Optionals
self.performer = performer
self.audio_duration = audio_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.performer = performer
self.audio_duration = audio_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedAudio."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -46,7 +46,11 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -61,8 +65,13 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
caption (:obj:`str`): Optional. Caption,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optionals): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -87,17 +96,18 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
self.audio_file_id = audio_file_id
with self._unfrozen():
self.audio_file_id = audio_file_id
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedDocument."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -48,7 +48,11 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -66,7 +70,12 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -95,19 +104,20 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
self.title = title
self.document_file_id = document_file_id
with self._unfrozen():
self.title = title
self.document_file_id = document_file_id
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+23 -13
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedGif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -48,7 +48,11 @@ class InlineQueryResultCachedGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -65,7 +69,12 @@ class InlineQueryResultCachedGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -92,18 +101,19 @@ class InlineQueryResultCachedGif(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
self.gif_file_id = gif_file_id
with self._unfrozen():
self.gif_file_id = gif_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -48,7 +48,11 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -65,7 +69,12 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -92,18 +101,19 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
self.mpeg4_file_id = mpeg4_file_id
with self._unfrozen():
self.mpeg4_file_id = mpeg4_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto"""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -49,7 +49,11 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -67,7 +71,12 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -96,19 +105,20 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
self.photo_file_id = photo_file_id
with self._unfrozen():
self.photo_file_id = photo_file_id
# Optionals
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -71,8 +71,9 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.STICKER, id, api_kwargs=api_kwargs)
self.sticker_file_id = sticker_file_id
with self._unfrozen():
self.sticker_file_id = sticker_file_id
# Optionals
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVideo."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -49,7 +49,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -67,7 +67,12 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -96,19 +101,20 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
self.video_file_id = video_file_id
self.title = title
with self._unfrozen():
self.video_file_id = video_file_id
self.title = title
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVoice."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -47,7 +47,10 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -64,7 +67,12 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -91,18 +99,19 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
self.voice_file_id = voice_file_id
self.title = title
with self._unfrozen():
self.voice_file_id = voice_file_id
self.title = title
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+11 -10
View File
@@ -101,14 +101,15 @@ class InlineQueryResultContact(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.CONTACT, id, api_kwargs=api_kwargs)
self.phone_number = phone_number
self.first_name = first_name
with self._unfrozen():
self.phone_number = phone_number
self.first_name = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optionals
self.last_name = last_name
self.vcard = vcard
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+28 -18
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultDocument"""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -47,7 +47,11 @@ class InlineQueryResultDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
document_url (:obj:`str`): A valid URL for the file.
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
or "application/zip".
@@ -70,7 +74,12 @@ class InlineQueryResultDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
document_url (:obj:`str`): A valid URL for the file.
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
or "application/zip".
@@ -114,23 +123,24 @@ class InlineQueryResultDocument(InlineQueryResult):
thumb_width: int = None,
thumb_height: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
self.document_url = document_url
self.title = title
self.mime_type = mime_type
with self._unfrozen():
self.document_url = document_url
self.title = title
self.mime_type = mime_type
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+4 -3
View File
@@ -58,7 +58,8 @@ class InlineQueryResultGame(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.GAME, id, api_kwargs=api_kwargs)
self.id = id
self.game_short_name = game_short_name
with self._unfrozen():
self.id = id
self.game_short_name = game_short_name
self.reply_markup = reply_markup
self.reply_markup = reply_markup
+28 -18
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultGif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -54,7 +54,11 @@ class InlineQueryResultGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -77,7 +81,12 @@ class InlineQueryResultGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -114,24 +123,25 @@ class InlineQueryResultGif(InlineQueryResult):
gif_duration: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb_mime_type: str = None,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
self.gif_url = gif_url
self.thumb_url = thumb_url
with self._unfrozen():
self.gif_url = gif_url
self.thumb_url = thumb_url
# Optionals
self.gif_width = gif_width
self.gif_height = gif_height
self.gif_duration = gif_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
# Optionals
self.gif_width = gif_width
self.gif_height = gif_height
self.gif_duration = gif_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
+16 -15
View File
@@ -127,22 +127,23 @@ class InlineQueryResultLocation(InlineQueryResult):
):
# Required
super().__init__(constants.InlineQueryResultType.LOCATION, id, api_kwargs=api_kwargs)
self.latitude = latitude
self.longitude = longitude
self.title = title
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
# Optionals
self.live_period = live_period
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)
# Optionals
self.live_period = live_period
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)
HORIZONTAL_ACCURACY: ClassVar[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
+29 -18
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -54,7 +54,11 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -77,7 +81,13 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -114,24 +124,25 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
mpeg4_duration: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb_mime_type: str = None,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
self.mpeg4_url = mpeg4_url
self.thumb_url = thumb_url
with self._unfrozen():
self.mpeg4_url = mpeg4_url
self.thumb_url = thumb_url
# Optional
self.mpeg4_width = mpeg4_width
self.mpeg4_height = mpeg4_height
self.mpeg4_duration = mpeg4_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
# Optional
self.mpeg4_width = mpeg4_width
self.mpeg4_height = mpeg4_height
self.mpeg4_duration = mpeg4_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
+27 -17
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -52,7 +52,11 @@ class InlineQueryResultPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -74,7 +78,12 @@ class InlineQueryResultPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -109,22 +118,23 @@ class InlineQueryResultPhoto(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
self.photo_url = photo_url
self.thumb_url = thumb_url
with self._unfrozen():
self.photo_url = photo_url
self.thumb_url = thumb_url
# Optionals
self.photo_width = photo_width
self.photo_height = photo_height
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.photo_width = photo_width
self.photo_height = photo_height
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+15 -14
View File
@@ -124,18 +124,19 @@ class InlineQueryResultVenue(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+37 -26
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVideo."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -54,7 +54,11 @@ class InlineQueryResultVideo(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
video_width (:obj:`int`, optional): Video width.
video_height (:obj:`int`, optional): Video height.
video_duration (:obj:`int`, optional): Video duration in seconds.
@@ -75,18 +79,24 @@ class InlineQueryResultVideo(InlineQueryResult):
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
thumb_url (:obj:`str`): URL of the thumbnail (JPEG only) for the video.
title (:obj:`str`): Title for the result.
caption (:obj:`str`, optional): Caption of the video to be sent,
caption (:obj:`str`): Optional. Caption of the video to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
video_width (:obj:`int`, optional): Video width.
video_height (:obj:`int`, optional): Video height.
video_duration (:obj:`int`, optional): Video duration in seconds.
description (:obj:`str`, optional): Short description of the result.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Sequence[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
video_width (:obj:`int`): Optional. Video width.
video_height (:obj:`int`): Optional. Video height.
video_duration (:obj:`int`): Optional. Video duration in seconds.
description (:obj:`str`): Optional. Short description of the result.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
message to be sent instead of the video. This field is required if
InlineQueryResultVideo is used to send an HTML-page as a result
(e.g., a YouTube video).
@@ -124,25 +134,26 @@ class InlineQueryResultVideo(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
self.video_url = video_url
self.mime_type = mime_type
self.thumb_url = thumb_url
self.title = title
with self._unfrozen():
self.video_url = video_url
self.mime_type = mime_type
self.thumb_url = thumb_url
self.title = title
# Optional
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.video_width = video_width
self.video_height = video_height
self.video_duration = video_duration
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optional
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.video_width = video_width
self.video_height = video_height
self.video_duration = video_duration
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+24 -14
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVoice."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -48,7 +48,11 @@ class InlineQueryResultVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
voice_duration (:obj:`int`, optional): Recording duration in seconds.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
@@ -66,7 +70,12 @@ class InlineQueryResultVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
voice_duration (:obj:`int`): Optional. Recording duration in seconds.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
@@ -96,20 +105,21 @@ class InlineQueryResultVoice(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
self.voice_url = voice_url
self.title = title
with self._unfrozen():
self.voice_url = voice_url
self.title = title
# Optional
self.voice_duration = voice_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optional
self.voice_duration = voice_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -65,3 +65,5 @@ class InputContactMessageContent(InputMessageContent):
self.vcard = vcard
self._id_attrs = (self.phone_number,)
self._freeze()
+29 -23
View File
@@ -17,11 +17,11 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a class that represents a Telegram InputInvoiceMessageContent."""
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional, Sequence
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._payment.labeledprice import LabeledPrice
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -52,20 +52,30 @@ class InputInvoiceMessageContent(InputMessageContent):
`@Botfather <https://t.me/Botfather>`_.
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_
prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
prices (Sequence[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
etc.)
.. versionchanged:: 20.0
|sequenceclassargs|
max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the
*smallest* units of the currency (integer, **not** float/double). For example, for a
maximum tip of US$ 1.45 pass ``max_tip_amount = 145``. See the ``exp`` parameter in
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it
shows the number of digits past the decimal point for each currency (2 for the majority
of currencies). Defaults to ``0``.
suggested_tip_amounts (List[:obj:`int`], optional): An array of suggested
suggested_tip_amounts (Sequence[:obj:`int`], optional): An array of suggested
amounts of tip in the *smallest* units of the currency (integer, **not** float/double).
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
positive, passed in a strictly increased order and must not exceed
:attr:`max_tip_amount`.
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
provider_data (:obj:`str`, optional): An object for data about the invoice,
which will be shared with the payment provider. A detailed description of the required
fields should be provided by the payment provider.
@@ -104,12 +114,20 @@ class InputInvoiceMessageContent(InputMessageContent):
`@Botfather <https://t.me/Botfather>`_.
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_
prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
prices (Tuple[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
components.
.. versionchanged:: 20.0
|tupleclassattrs|
max_tip_amount (:obj:`int`): Optional. The maximum accepted amount for tips in the smallest
units of the currency (integer, not float/double).
suggested_tip_amounts (List[:obj:`int`]): Optional. An array of suggested
suggested_tip_amounts (Tuple[:obj:`int`]): Optional. An array of suggested
amounts of tip in the smallest units of the currency (integer, not float/double).
.. versionchanged:: 20.0
|tupleclassattrs|
provider_data (:obj:`str`): Optional. An object for data about the invoice,
which will be shared with the payment provider.
photo_url (:obj:`str`): Optional. URL of the product photo for the invoice.
@@ -163,9 +181,9 @@ class InputInvoiceMessageContent(InputMessageContent):
payload: str,
provider_token: str,
currency: str,
prices: List[LabeledPrice],
prices: Sequence[LabeledPrice],
max_tip_amount: int = None,
suggested_tip_amounts: List[int] = None,
suggested_tip_amounts: Sequence[int] = None,
provider_data: str = None,
photo_url: str = None,
photo_size: int = None,
@@ -188,10 +206,10 @@ class InputInvoiceMessageContent(InputMessageContent):
self.payload = payload
self.provider_token = provider_token
self.currency = currency
self.prices = prices
self.prices = parse_sequence_arg(prices)
# Optionals
self.max_tip_amount = max_tip_amount
self.suggested_tip_amounts = suggested_tip_amounts
self.suggested_tip_amounts = parse_sequence_arg(suggested_tip_amounts)
self.provider_data = provider_data
self.photo_url = photo_url
self.photo_size = photo_size
@@ -214,19 +232,7 @@ class InputInvoiceMessageContent(InputMessageContent):
self.prices,
)
def __hash__(self) -> int:
# we override this as self.prices is a list and not hashable
prices = tuple(self.prices)
return hash(
(
self.title,
self.description,
self.payload,
self.provider_token,
self.currency,
prices,
)
)
self._freeze()
@classmethod
def de_json(
@@ -97,6 +97,8 @@ class InputLocationMessageContent(InputMessageContent):
self._id_attrs = (self.latitude, self.longitude)
self._freeze()
HORIZONTAL_ACCURACY: ClassVar[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
+17 -6
View File
@@ -17,11 +17,11 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InputTextMessageContent."""
from typing import List, Tuple, Union
from typing import Sequence
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
@@ -42,7 +42,11 @@ class InputTextMessageContent(InputMessageContent):
:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in the
sent message.
@@ -51,7 +55,12 @@ class InputTextMessageContent(InputMessageContent):
1-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
disable_web_page_preview (:obj:`bool`): Optional. Disables link previews for links in the
sent message.
@@ -64,7 +73,7 @@ class InputTextMessageContent(InputMessageContent):
message_text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
@@ -73,7 +82,9 @@ class InputTextMessageContent(InputMessageContent):
self.message_text = message_text
# Optionals
self.parse_mode = parse_mode
self.entities = entities
self.entities = parse_sequence_arg(entities)
self.disable_web_page_preview = disable_web_page_preview
self._id_attrs = (self.message_text,)
self._freeze()
@@ -101,3 +101,5 @@ class InputVenueMessageContent(InputMessageContent):
self.longitude,
self.title,
)
self._freeze()
+2
View File
@@ -107,6 +107,8 @@ class KeyboardButton(TelegramObject):
self.web_app,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["KeyboardButton"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -48,3 +48,5 @@ class KeyboardButtonPollType(TelegramObject):
self.type = type
self._id_attrs = (self.type,)
self._freeze()
+2
View File
@@ -88,3 +88,5 @@ class LoginUrl(TelegramObject):
self.request_write_access = request_write_access
self._id_attrs = (self.url,)
self._freeze()
+8 -3
View File
@@ -62,6 +62,8 @@ class MenuButton(TelegramObject):
self._id_attrs = (self.type,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["MenuButton"]:
"""Converts JSON data to the appropriate :class:`MenuButton` object, i.e. takes
@@ -114,6 +116,7 @@ class MenuButtonCommands(MenuButton):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=constants.MenuButtonType.COMMANDS, api_kwargs=api_kwargs)
self._freeze()
class MenuButtonWebApp(MenuButton):
@@ -144,10 +147,11 @@ class MenuButtonWebApp(MenuButton):
def __init__(self, text: str, web_app: WebAppInfo, *, api_kwargs: JSONDict = None):
super().__init__(type=constants.MenuButtonType.WEB_APP, api_kwargs=api_kwargs)
self.text = text
self.web_app = web_app
with self._unfrozen():
self.text = text
self.web_app = web_app
self._id_attrs = (self.type, self.text, self.web_app)
self._id_attrs = (self.type, self.text, self.web_app)
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["MenuButtonWebApp"]:
@@ -174,3 +178,4 @@ class MenuButtonDefault(MenuButton):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=constants.MenuButtonType.DEFAULT, api_kwargs=api_kwargs)
self._freeze()
+75 -32
View File
@@ -21,7 +21,7 @@
import datetime
import sys
from html import escape
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence, Tuple, Union
from telegram._chat import Chat
from telegram._dice import Dice
@@ -48,6 +48,7 @@ from telegram._poll import Poll
from telegram._proximityalerttriggered import ProximityAlertTriggered
from telegram._telegramobject import TelegramObject
from telegram._user import User
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.datetime import from_timestamp
from telegram._utils.defaultvalue import DEFAULT_NONE, DefaultValue
from telegram._utils.types import DVInput, FileInput, JSONDict, ODVInput, ReplyMarkup
@@ -140,15 +141,23 @@ class Message(TelegramObject):
message belongs to.
text (:obj:`str`, optional): For text messages, the actual UTF-8 text of the message,
0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
entities (List[:class:`telegram.MessageEntity`], optional): For text messages, special
entities (Sequence[:class:`telegram.MessageEntity`], optional): For text messages, special
entities like usernames, URLs, bot commands, etc. that appear in the text. See
:attr:`parse_entity` and :attr:`parse_entities` methods for how to use properly.
This list is empty if the message does not contain entities.
caption_entities (List[:class:`telegram.MessageEntity`], optional): For messages with a
.. versionchanged:: 20.0
|sequenceclassargs|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): For messages with a
Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the
caption. See :attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities`
methods for how to use properly. This list is empty if the message does not contain
caption entities.
.. versionchanged:: 20.0
|sequenceclassargs|
audio (:class:`telegram.Audio`, optional): Message is an audio file, information
about the file.
document (:class:`telegram.Document`, optional): Message is a general file, information
@@ -157,8 +166,12 @@ class Message(TelegramObject):
about the animation. For backward compatibility, when this field is set, the document
field will also be set.
game (:class:`telegram.Game`, optional): Message is a game, information about the game.
photo (List[:class:`telegram.PhotoSize`], optional): Message is a photo, available sizes
of the photo. This list is empty if the message does not contain a photo.
photo (Sequence[:class:`telegram.PhotoSize`], optional): Message is a photo, available
sizes of the photo. This list is empty if the message does not contain a photo.
.. versionchanged:: 20.0
|sequenceclassargs|
sticker (:class:`telegram.Sticker`, optional): Message is a sticker, information
about the sticker.
video (:class:`telegram.Video`, optional): Message is a video, information about the
@@ -167,9 +180,13 @@ class Message(TelegramObject):
the file.
video_note (:class:`telegram.VideoNote`, optional): Message is a video note, information
about the video message.
new_chat_members (List[:class:`telegram.User`], optional): New members that were added to
the group or supergroup and information about them (the bot itself may be one of these
members). This list is empty if the message does not contain new chat members.
new_chat_members (Sequence[:class:`telegram.User`], optional): New members that were added
to the group or supergroup and information about them (the bot itself may be one of
these members). This list is empty if the message does not contain new chat members.
.. versionchanged:: 20.0
|sequenceclassargs|
caption (:obj:`str`, optional): Caption for the animation, audio, document, photo, video
or voice, 0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters.
contact (:class:`telegram.Contact`, optional): Message is a shared contact, information
@@ -182,8 +199,12 @@ class Message(TelegramObject):
left_chat_member (:class:`telegram.User`, optional): A member was removed from the group,
information about them (this member may be the bot itself).
new_chat_title (:obj:`str`, optional): A chat title was changed to this value.
new_chat_photo (List[:class:`telegram.PhotoSize`], optional): A chat photo was changed to
this value. This list is empty if the message does not contain a new chat photo.
new_chat_photo (Sequence[:class:`telegram.PhotoSize`], optional): A chat photo was changed
to this value. This list is empty if the message does not contain a new chat photo.
.. versionchanged:: 20.0
|sequenceclassargs|
delete_chat_photo (:obj:`bool`, optional): Service message: The chat photo was deleted.
group_chat_created (:obj:`bool`, optional): Service message: The group has been created.
supergroup_chat_created (:obj:`bool`, optional): Service message: The supergroup has been
@@ -309,15 +330,23 @@ class Message(TelegramObject):
message belongs to.
text (:obj:`str`): Optional. For text messages, the actual UTF-8 text of the message,
0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
entities (List[:class:`telegram.MessageEntity`]): Optional. For text messages, special
entities (Tuple[:class:`telegram.MessageEntity`]): Optional. For text messages, special
entities like usernames, URLs, bot commands, etc. that appear in the text. See
:attr:`parse_entity` and :attr:`parse_entities` methods for how to use properly.
This list is empty if the message does not contain entities.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. For messages with a
.. versionchanged:: 20.0
|tupleclassattrs|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. For messages with a
Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the
caption. See :attr:`Message.parse_caption_entity` and :attr:`parse_caption_entities`
methods for how to use properly. This list is empty if the message does not contain
caption entities.
.. versionchanged:: 20.0
|tupleclassattrs|
audio (:class:`telegram.Audio`): Optional. Message is an audio file, information
about the file.
document (:class:`telegram.Document`): Optional. Message is a general file, information
@@ -326,8 +355,12 @@ class Message(TelegramObject):
about the animation. For backward compatibility, when this field is set, the document
field will also be set.
game (:class:`telegram.Game`): Optional. Message is a game, information about the game.
photo (List[:class:`telegram.PhotoSize`]): Optional. Message is a photo, available sizes
of the photo. This list is empty if the message does not contain a photo.
photo (Tuple[:class:`telegram.PhotoSize`]): Optional. Message is a photo, available
sizes of the photo. This list is empty if the message does not contain a photo.
.. versionchanged:: 20.0
|tupleclassattrs|
sticker (:class:`telegram.Sticker`): Optional. Message is a sticker, information
about the sticker.
video (:class:`telegram.Video`): Optional. Message is a video, information about the
@@ -336,9 +369,13 @@ class Message(TelegramObject):
the file.
video_note (:class:`telegram.VideoNote`): Optional. Message is a video note, information
about the video message.
new_chat_members (List[:class:`telegram.User`]): Optional. New members that were added to
the group or supergroup and information about them (the bot itself may be one of these
members). This list is empty if the message does not contain new chat members.
new_chat_members (Tuple[:class:`telegram.User`]): Optional. New members that were added
to the group or supergroup and information about them (the bot itself may be one of
these members). This list is empty if the message does not contain new chat members.
.. versionchanged:: 20.0
|tupleclassattrs|
caption (:obj:`str`): Optional. Caption for the animation, audio, document, photo, video
or voice, 0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters.
contact (:class:`telegram.Contact`): Optional. Message is a shared contact, information
@@ -351,8 +388,12 @@ class Message(TelegramObject):
left_chat_member (:class:`telegram.User`): Optional. A member was removed from the group,
information about them (this member may be the bot itself).
new_chat_title (:obj:`str`): Optional. A chat title was changed to this value.
new_chat_photo (List[:class:`telegram.PhotoSize`]): A chat photo was changed to
new_chat_photo (Tuple[:class:`telegram.PhotoSize`]): A chat photo was changed to
this value. This list is empty if the message does not contain a new chat photo.
.. versionchanged:: 20.0
|tupleclassattrs|
delete_chat_photo (:obj:`bool`): Optional. Service message: The chat photo was deleted.
group_chat_created (:obj:`bool`): Optional. Service message: The group has been created.
supergroup_chat_created (:obj:`bool`): Optional. Service message: The supergroup has been
@@ -528,24 +569,24 @@ class Message(TelegramObject):
reply_to_message: "Message" = None,
edit_date: datetime.datetime = None,
text: str = None,
entities: List["MessageEntity"] = None,
caption_entities: List["MessageEntity"] = None,
entities: Sequence["MessageEntity"] = None,
caption_entities: Sequence["MessageEntity"] = None,
audio: Audio = None,
document: Document = None,
game: Game = None,
photo: List[PhotoSize] = None,
photo: Sequence[PhotoSize] = None,
sticker: Sticker = None,
video: Video = None,
voice: Voice = None,
video_note: VideoNote = None,
new_chat_members: List[User] = None,
new_chat_members: Sequence[User] = None,
caption: str = None,
contact: Contact = None,
location: Location = None,
venue: Venue = None,
left_chat_member: User = None,
new_chat_title: str = None,
new_chat_photo: List[PhotoSize] = None,
new_chat_photo: Sequence[PhotoSize] = None,
delete_chat_photo: bool = None,
group_chat_created: bool = None,
supergroup_chat_created: bool = None,
@@ -601,12 +642,12 @@ class Message(TelegramObject):
self.edit_date = edit_date
self.has_protected_content = has_protected_content
self.text = text
self.entities = entities or []
self.caption_entities = caption_entities or []
self.entities = parse_sequence_arg(entities)
self.caption_entities = parse_sequence_arg(caption_entities)
self.audio = audio
self.game = game
self.document = document
self.photo = photo or []
self.photo = parse_sequence_arg(photo)
self.sticker = sticker
self.video = video
self.voice = voice
@@ -615,10 +656,10 @@ class Message(TelegramObject):
self.contact = contact
self.location = location
self.venue = venue
self.new_chat_members = new_chat_members or []
self.new_chat_members = parse_sequence_arg(new_chat_members)
self.left_chat_member = left_chat_member
self.new_chat_title = new_chat_title
self.new_chat_photo = new_chat_photo or []
self.new_chat_photo = parse_sequence_arg(new_chat_photo)
self.delete_chat_photo = bool(delete_chat_photo)
self.group_chat_created = bool(group_chat_created)
self.supergroup_chat_created = bool(supergroup_chat_created)
@@ -657,6 +698,8 @@ class Message(TelegramObject):
self._id_attrs = (self.message_id, self.chat)
self._freeze()
@property
def chat_id(self) -> int:
""":obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`."""
@@ -1095,7 +1138,7 @@ class Message(TelegramObject):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
) -> List["Message"]:
) -> Tuple["Message", ...]:
"""Shortcut for::
await bot.send_media_group(update.effective_message.chat_id, *args, **kwargs)
@@ -1109,7 +1152,7 @@ class Message(TelegramObject):
chats.
Returns:
List[:class:`telegram.Message`]: An array of the sent Messages.
Tuple[:class:`telegram.Message`]: An array of the sent Messages.
Raises:
:class:`telegram.error.TelegramError`
@@ -2596,7 +2639,7 @@ class Message(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List["GameHighScore"]:
) -> Tuple["GameHighScore", ...]:
"""Shortcut for::
await bot.get_game_high_scores(
@@ -2612,7 +2655,7 @@ class Message(TelegramObject):
behaviour is undocumented and might be changed by Telegram.
Returns:
List[:class:`telegram.GameHighScore`]
Tuple[:class:`telegram.GameHighScore`]
"""
return await self.get_bot().get_game_high_scores(
chat_id=self.chat_id,
@@ -54,3 +54,5 @@ class MessageAutoDeleteTimerChanged(TelegramObject):
self.message_auto_delete_time = message_auto_delete_time
self._id_attrs = (self.message_auto_delete_time,)
self._freeze()
+2
View File
@@ -115,6 +115,8 @@ class MessageEntity(TelegramObject):
self._id_attrs = (self.type, self.offset, self.length)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["MessageEntity"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -42,3 +42,5 @@ class MessageId(TelegramObject):
self.message_id = message_id
self._id_attrs = (self.message_id,)
self._freeze()
+33 -12
View File
@@ -19,7 +19,7 @@
# pylint: disable=missing-module-docstring, redefined-builtin
import json
from base64 import b64decode
from typing import TYPE_CHECKING, List, Optional, no_type_check
from typing import TYPE_CHECKING, Optional, Sequence, no_type_check
try:
from cryptography.hazmat.backends import default_backend
@@ -38,6 +38,7 @@ except ImportError:
CRYPTO_INSTALLED = False
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
from telegram.error import PassportDecryptionError
@@ -155,6 +156,8 @@ class EncryptedCredentials(TelegramObject):
self._decrypted_secret: Optional[str] = None
self._decrypted_data: Optional["Credentials"] = None
self._freeze()
@property
def decrypted_secret(self) -> str:
"""
@@ -226,6 +229,8 @@ class Credentials(TelegramObject):
self.secure_data = secure_data
self.nonce = nonce
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Credentials"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -312,6 +317,8 @@ class SecureData(TelegramObject):
self.passport = passport
self.personal_details = personal_details
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["SecureData"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -356,14 +363,23 @@ class SecureValue(TelegramObject):
selfie (:class:`telegram.FileCredentials`): Optional. Credentials for encrypted selfie
of the user with a document. Can be available for "passport", "driver_license",
"identity_card" and "internal_passport".
translation (List[:class:`telegram.FileCredentials`]): Optional. Credentials for an
translation (Tuple[:class:`telegram.FileCredentials`]): Optional. Credentials for an
encrypted translation of the document. Available for "passport", "driver_license",
"identity_card", "internal_passport", "utility_bill", "bank_statement",
"rental_agreement", "passport_registration" and "temporary_registration".
files (List[:class:`telegram.FileCredentials`]): Optional. Credentials for encrypted
.. versionchanged:: 20.0
|tupleclassattrs|
files (Tuple[:class:`telegram.FileCredentials`]): Optional. Credentials for encrypted
files. Available for "utility_bill", "bank_statement", "rental_agreement",
"passport_registration" and "temporary_registration" types.
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
"""
__slots__ = ("data", "front_side", "reverse_side", "selfie", "files", "translation")
@@ -374,8 +390,8 @@ class SecureValue(TelegramObject):
front_side: "FileCredentials" = None,
reverse_side: "FileCredentials" = None,
selfie: "FileCredentials" = None,
files: List["FileCredentials"] = None,
translation: List["FileCredentials"] = None,
files: Sequence["FileCredentials"] = None,
translation: Sequence["FileCredentials"] = None,
*,
api_kwargs: JSONDict = None,
):
@@ -384,8 +400,10 @@ class SecureValue(TelegramObject):
self.front_side = front_side
self.reverse_side = reverse_side
self.selfie = selfie
self.files = files
self.translation = translation
self.files = parse_sequence_arg(files)
self.translation = parse_sequence_arg(translation)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["SecureValue"]:
@@ -414,12 +432,13 @@ class _CredentialsBase(TelegramObject):
self, hash: str, secret: str, *, api_kwargs: JSONDict = None # skipcq: PYL-W0622
):
super().__init__(api_kwargs=api_kwargs)
self.hash = hash
self.secret = secret
with self._unfrozen():
self.hash = hash
self.secret = secret
# Aliases just to be sure
self.file_hash = self.hash
self.data_hash = self.hash
# Aliases just to be sure
self.file_hash = self.hash
self.data_hash = self.hash
class DataCredentials(_CredentialsBase):
@@ -440,6 +459,7 @@ class DataCredentials(_CredentialsBase):
def __init__(self, data_hash: str, secret: str, *, api_kwargs: JSONDict = None):
super().__init__(hash=data_hash, secret=secret, api_kwargs=api_kwargs)
self._freeze()
class FileCredentials(_CredentialsBase):
@@ -460,3 +480,4 @@ class FileCredentials(_CredentialsBase):
def __init__(self, file_hash: str, secret: str, *, api_kwargs: JSONDict = None):
super().__init__(hash=file_hash, secret=secret, api_kwargs=api_kwargs)
self._freeze()
+6
View File
@@ -84,6 +84,8 @@ class PersonalDetails(TelegramObject):
self.last_name_native = last_name_native
self.middle_name_native = middle_name_native
self._freeze()
class ResidentialAddress(TelegramObject):
"""
@@ -127,6 +129,8 @@ class ResidentialAddress(TelegramObject):
self.country_code = country_code
self.post_code = post_code
self._freeze()
class IdDocumentData(TelegramObject):
"""
@@ -149,3 +153,5 @@ class IdDocumentData(TelegramObject):
super().__init__(api_kwargs=api_kwargs)
self.document_no = document_no
self.expiry_date = expiry_date
self._freeze()
+34 -9
View File
@@ -18,12 +18,13 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram EncryptedPassportElement."""
from base64 import b64decode
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional, Sequence
from telegram._passport.credentials import decrypt_json
from telegram._passport.data import IdDocumentData, PersonalDetails, ResidentialAddress
from telegram._passport.passportfile import PassportFile
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -58,9 +59,14 @@ class EncryptedPassportElement(TelegramObject):
"phone_number" type.
email (:obj:`str`, optional): User's verified email address, available only for "email"
type.
files (List[:class:`telegram.PassportFile`], optional): Array of encrypted/decrypted files
files (Sequence[:class:`telegram.PassportFile`], optional): Array of encrypted/decrypted
files
with documents provided by the user, available for "utility_bill", "bank_statement",
"rental_agreement", "passport_registration" and "temporary_registration" types.
.. versionchanged:: 20.0
|sequenceclassargs|
front_side (:class:`telegram.PassportFile`, optional): Encrypted/decrypted file with the
front side of the document, provided by the user. Available for "passport",
"driver_license", "identity_card" and "internal_passport".
@@ -70,12 +76,16 @@ class EncryptedPassportElement(TelegramObject):
selfie (:class:`telegram.PassportFile`, optional): Encrypted/decrypted file with the
selfie of the user holding a document, provided by the user; available for "passport",
"driver_license", "identity_card" and "internal_passport".
translation (List[:class:`telegram.PassportFile`], optional): Array of encrypted/decrypted
translation (Sequence[:class:`telegram.PassportFile`], optional): Array of
encrypted/decrypted
files with translated versions of documents provided by the user. Available if
requested for "passport", "driver_license", "identity_card", "internal_passport",
"utility_bill", "bank_statement", "rental_agreement", "passport_registration" and
"temporary_registration" types.
.. versionchanged:: 20.0
|sequenceclassargs|
Attributes:
type (:obj:`str`): Element type. One of "personal_details", "passport", "driver_license",
"identity_card", "internal_passport", "address", "utility_bill", "bank_statement",
@@ -91,9 +101,16 @@ class EncryptedPassportElement(TelegramObject):
"phone_number" type.
email (:obj:`str`): Optional. User's verified email address, available only for "email"
type.
files (List[:class:`telegram.PassportFile`]): Optional. Array of encrypted/decrypted files
files (Tuple[:class:`telegram.PassportFile`]): Optional. Array of encrypted/decrypted
files
with documents provided by the user, available for "utility_bill", "bank_statement",
"rental_agreement", "passport_registration" and "temporary_registration" types.
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
front_side (:class:`telegram.PassportFile`): Optional. Encrypted/decrypted file with the
front side of the document, provided by the user. Available for "passport",
"driver_license", "identity_card" and "internal_passport".
@@ -103,12 +120,18 @@ class EncryptedPassportElement(TelegramObject):
selfie (:class:`telegram.PassportFile`): Optional. Encrypted/decrypted file with the
selfie of the user holding a document, provided by the user; available for "passport",
"driver_license", "identity_card" and "internal_passport".
translation (List[:class:`telegram.PassportFile`]): Optional. Array of encrypted/decrypted
translation (Tuple[:class:`telegram.PassportFile`]): Optional. Array of
encrypted/decrypted
files with translated versions of documents provided by the user. Available if
requested for "passport", "driver_license", "identity_card", "internal_passport",
"utility_bill", "bank_statement", "rental_agreement", "passport_registration" and
"temporary_registration" types.
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
"""
__slots__ = (
@@ -131,11 +154,11 @@ class EncryptedPassportElement(TelegramObject):
data: PersonalDetails = None,
phone_number: str = None,
email: str = None,
files: List[PassportFile] = None,
files: Sequence[PassportFile] = None,
front_side: PassportFile = None,
reverse_side: PassportFile = None,
selfie: PassportFile = None,
translation: List[PassportFile] = None,
translation: Sequence[PassportFile] = None,
credentials: "Credentials" = None, # pylint: disable=unused-argument
*,
api_kwargs: JSONDict = None,
@@ -148,11 +171,11 @@ class EncryptedPassportElement(TelegramObject):
self.data = data
self.phone_number = phone_number
self.email = email
self.files = files
self.files = parse_sequence_arg(files)
self.front_side = front_side
self.reverse_side = reverse_side
self.selfie = selfie
self.translation = translation
self.translation = parse_sequence_arg(translation)
self.hash = hash
self._id_attrs = (
@@ -166,6 +189,8 @@ class EncryptedPassportElement(TelegramObject):
self.selfie,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["EncryptedPassportElement"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+30 -15
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Contains information about Telegram Passport data shared with the bot by the user."""
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._passport.credentials import EncryptedCredentials
from telegram._passport.encryptedpassportelement import EncryptedPassportElement
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -39,13 +39,23 @@ class PassportData(TelegramObject):
attribute :attr:`telegram.Credentials.nonce`.
Args:
data (List[:class:`telegram.EncryptedPassportElement`]): Array with encrypted information
about documents and other Telegram Passport elements that was shared with the bot.
data (Sequence[:class:`telegram.EncryptedPassportElement`]): Array with encrypted
information about documents and other Telegram Passport elements that was shared with
the bot.
.. versionchanged:: 20.0
|sequenceclassargs|
credentials (:class:`telegram.EncryptedCredentials`)): Encrypted credentials.
Attributes:
data (List[:class:`telegram.EncryptedPassportElement`]): Array with encrypted information
about documents and other Telegram Passport elements that was shared with the bot.
data (Tuple[:class:`telegram.EncryptedPassportElement`]): Array with encrypted
information about documents and other Telegram Passport elements that was shared with
the bot.
.. versionchanged:: 20.0
|tupleclassattrs|
credentials (:class:`telegram.EncryptedCredentials`): Encrypted credentials.
@@ -55,19 +65,21 @@ class PassportData(TelegramObject):
def __init__(
self,
data: List[EncryptedPassportElement],
data: Sequence[EncryptedPassportElement],
credentials: EncryptedCredentials,
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.data = data
self.data = parse_sequence_arg(data)
self.credentials = credentials
self._decrypted_data: Optional[List[EncryptedPassportElement]] = None
self._decrypted_data: Optional[Tuple[EncryptedPassportElement]] = None
self._id_attrs = tuple([x.type for x in data] + [credentials.hash])
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["PassportData"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -82,23 +94,26 @@ class PassportData(TelegramObject):
return super().de_json(data=data, bot=bot)
@property
def decrypted_data(self) -> List[EncryptedPassportElement]:
def decrypted_data(self) -> Tuple[EncryptedPassportElement, ...]:
"""
List[:class:`telegram.EncryptedPassportElement`]: Lazily decrypt and return information
Tuple[:class:`telegram.EncryptedPassportElement`]: Lazily decrypt and return information
about documents and other Telegram Passport elements which were shared with the bot.
.. versionchanged:: 20.0
Returns a tuple instead of a list.
Raises:
telegram.error.PassportDecryptionError: Decryption failed. Usually due to bad
private/public key but can also suggest malformed/tampered data.
"""
if self._decrypted_data is None:
self._decrypted_data = [
EncryptedPassportElement.de_json_decrypted( # type: ignore[misc]
self._decrypted_data = tuple( # type: ignore[assignment]
EncryptedPassportElement.de_json_decrypted(
element.to_dict(), self.get_bot(), self.decrypted_credentials
)
for element in self.data
]
return self._decrypted_data
)
return self._decrypted_data # type: ignore[return-value]
@property
def decrypted_credentials(self) -> "Credentials":
+36 -19
View File
@@ -54,6 +54,8 @@ class PassportElementError(TelegramObject):
self._id_attrs = (self.source, self.type)
self._freeze()
class PassportElementErrorDataField(PassportElementError):
"""
@@ -95,10 +97,17 @@ class PassportElementErrorDataField(PassportElementError):
):
# Required
super().__init__("data", type, message, api_kwargs=api_kwargs)
self.field_name = field_name
self.data_hash = data_hash
with self._unfrozen():
self.field_name = field_name
self.data_hash = data_hash
self._id_attrs = (self.source, self.type, self.field_name, self.data_hash, self.message)
self._id_attrs = (
self.source,
self.type,
self.field_name,
self.data_hash,
self.message,
)
class PassportElementErrorFile(PassportElementError):
@@ -131,9 +140,10 @@ class PassportElementErrorFile(PassportElementError):
def __init__(self, type: str, file_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("file", type, message, api_kwargs=api_kwargs)
self.file_hash = file_hash
with self._unfrozen():
self.file_hash = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
class PassportElementErrorFiles(PassportElementError):
@@ -166,9 +176,10 @@ class PassportElementErrorFiles(PassportElementError):
def __init__(self, type: str, file_hashes: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("files", type, message, api_kwargs=api_kwargs)
self.file_hashes = file_hashes
with self._unfrozen():
self.file_hashes = file_hashes
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
class PassportElementErrorFrontSide(PassportElementError):
@@ -201,9 +212,10 @@ class PassportElementErrorFrontSide(PassportElementError):
def __init__(self, type: str, file_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("front_side", type, message, api_kwargs=api_kwargs)
self.file_hash = file_hash
with self._unfrozen():
self.file_hash = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
class PassportElementErrorReverseSide(PassportElementError):
@@ -236,9 +248,10 @@ class PassportElementErrorReverseSide(PassportElementError):
def __init__(self, type: str, file_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("reverse_side", type, message, api_kwargs=api_kwargs)
self.file_hash = file_hash
with self._unfrozen():
self.file_hash = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
class PassportElementErrorSelfie(PassportElementError):
@@ -269,9 +282,10 @@ class PassportElementErrorSelfie(PassportElementError):
def __init__(self, type: str, file_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("selfie", type, message, api_kwargs=api_kwargs)
self.file_hash = file_hash
with self._unfrozen():
self.file_hash = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
class PassportElementErrorTranslationFile(PassportElementError):
@@ -306,9 +320,10 @@ class PassportElementErrorTranslationFile(PassportElementError):
def __init__(self, type: str, file_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("translation_file", type, message, api_kwargs=api_kwargs)
self.file_hash = file_hash
with self._unfrozen():
self.file_hash = file_hash
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
self._id_attrs = (self.source, self.type, self.file_hash, self.message)
class PassportElementErrorTranslationFiles(PassportElementError):
@@ -343,9 +358,10 @@ class PassportElementErrorTranslationFiles(PassportElementError):
def __init__(self, type: str, file_hashes: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("translation_files", type, message, api_kwargs=api_kwargs)
self.file_hashes = file_hashes
with self._unfrozen():
self.file_hashes = file_hashes
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
self._id_attrs = (self.source, self.type, self.message) + tuple(file_hashes)
class PassportElementErrorUnspecified(PassportElementError):
@@ -374,6 +390,7 @@ class PassportElementErrorUnspecified(PassportElementError):
def __init__(self, type: str, element_hash: str, message: str, *, api_kwargs: JSONDict = None):
# Required
super().__init__("unspecified", type, message, api_kwargs=api_kwargs)
self.element_hash = element_hash
with self._unfrozen():
self.element_hash = element_hash
self._id_attrs = (self.source, self.type, self.element_hash, self.message)
self._id_attrs = (self.source, self.type, self.element_hash, self.message)

Some files were not shown because too many files have changed in this diff Show More