2017-07-01 17:08:45 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# A library that provides a Python interface to the Telegram Bot API
|
2024-02-19 20:06:25 +01:00
|
|
|
# Copyright (C) 2015-2024
|
2017-07-01 17:08:45 +02:00
|
|
|
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser Public License for more details.
|
|
|
|
#
|
|
|
|
# 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 ChatPhoto."""
|
2023-06-29 18:17:47 +02:00
|
|
|
from typing import TYPE_CHECKING, Final, Optional
|
2017-07-01 17:08:45 +02:00
|
|
|
|
2022-11-22 11:07:42 +01:00
|
|
|
from telegram import constants
|
2022-05-05 09:27:54 +02:00
|
|
|
from telegram._telegramobject import TelegramObject
|
2021-10-10 15:10:21 +02:00
|
|
|
from telegram._utils.defaultvalue import DEFAULT_NONE
|
|
|
|
from telegram._utils.types import JSONDict, ODVInput
|
2020-10-09 17:22:07 +02:00
|
|
|
|
2020-10-06 19:28:40 +02:00
|
|
|
if TYPE_CHECKING:
|
2022-10-07 11:51:53 +02:00
|
|
|
from telegram import File
|
2020-10-06 19:28:40 +02:00
|
|
|
|
2017-07-01 17:08:45 +02:00
|
|
|
|
|
|
|
class ChatPhoto(TelegramObject):
|
2017-09-01 08:43:08 +02:00
|
|
|
"""This object represents a chat photo.
|
2017-07-01 17:08:45 +02:00
|
|
|
|
2020-07-14 21:33:56 +02:00
|
|
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
|
|
|
considered equal, if their :attr:`small_file_unique_id` and :attr:`big_file_unique_id` are
|
|
|
|
equal.
|
|
|
|
|
2017-07-01 17:08:45 +02:00
|
|
|
Args:
|
2023-01-01 16:24:00 +01:00
|
|
|
small_file_id (:obj:`str`): File identifier of small
|
2022-11-22 11:07:42 +01:00
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
|
|
|
|
chat photo. This file_id can be used only for photo download and only for as long
|
2020-03-28 16:37:26 +01:00
|
|
|
as the photo is not changed.
|
2022-11-22 11:07:42 +01:00
|
|
|
small_file_unique_id (:obj:`str`): Unique file identifier of small
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
|
|
|
|
chat photo, which is supposed to be the same over time and for different bots.
|
2020-03-28 16:37:26 +01:00
|
|
|
Can't be used to download or reuse the file.
|
2023-01-01 16:24:00 +01:00
|
|
|
big_file_id (:obj:`str`): File identifier of big
|
2022-11-22 11:07:42 +01:00
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
|
|
|
|
chat photo. This file_id can be used only for photo download and only for as long as
|
|
|
|
the photo is not changed.
|
|
|
|
big_file_unique_id (:obj:`str`): Unique file identifier of big
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
|
|
|
|
chat photo, which is supposed to be the same over time and for different bots.
|
2020-03-28 16:37:26 +01:00
|
|
|
Can't be used to download or reuse the file.
|
2017-09-01 08:43:08 +02:00
|
|
|
|
2020-12-30 15:59:50 +01:00
|
|
|
Attributes:
|
2022-11-22 11:07:42 +01:00
|
|
|
small_file_id (:obj:`str`): File identifier of small
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
|
|
|
|
chat photo. This file_id can be used only for photo download and only for as long
|
2020-12-30 15:59:50 +01:00
|
|
|
as the photo is not changed.
|
2022-11-22 11:07:42 +01:00
|
|
|
small_file_unique_id (:obj:`str`): Unique file identifier of small
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
|
|
|
|
chat photo, which is supposed to be the same over time and for different bots.
|
2020-12-30 15:59:50 +01:00
|
|
|
Can't be used to download or reuse the file.
|
2022-11-22 11:07:42 +01:00
|
|
|
big_file_id (:obj:`str`): File identifier of big
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
|
|
|
|
chat photo. This file_id can be used only for photo download and only for as long as
|
2020-12-30 15:59:50 +01:00
|
|
|
the photo is not changed.
|
2022-11-22 11:07:42 +01:00
|
|
|
big_file_unique_id (:obj:`str`): Unique file identifier of big
|
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
|
|
|
|
chat photo, which is supposed to be the same over time and for different bots.
|
2020-12-30 15:59:50 +01:00
|
|
|
Can't be used to download or reuse the file.
|
|
|
|
|
2017-07-01 17:08:45 +02:00
|
|
|
"""
|
2017-07-23 22:33:08 +02:00
|
|
|
|
2021-05-29 16:18:16 +02:00
|
|
|
__slots__ = (
|
2024-02-05 19:24:00 +01:00
|
|
|
"big_file_id",
|
2021-05-29 16:18:16 +02:00
|
|
|
"big_file_unique_id",
|
|
|
|
"small_file_id",
|
|
|
|
"small_file_unique_id",
|
|
|
|
)
|
|
|
|
|
2020-03-28 16:37:26 +01:00
|
|
|
def __init__(
|
2020-11-05 18:12:01 +01:00
|
|
|
self,
|
2020-10-06 19:28:40 +02:00
|
|
|
small_file_id: str,
|
|
|
|
small_file_unique_id: str,
|
|
|
|
big_file_id: str,
|
|
|
|
big_file_unique_id: str,
|
2022-10-07 11:51:53 +02:00
|
|
|
*,
|
2023-05-18 07:57:59 +02:00
|
|
|
api_kwargs: Optional[JSONDict] = None,
|
2020-10-06 19:28:40 +02:00
|
|
|
):
|
2022-10-07 11:51:53 +02:00
|
|
|
super().__init__(api_kwargs=api_kwargs)
|
2023-02-02 18:55:07 +01:00
|
|
|
self.small_file_id: str = small_file_id
|
|
|
|
self.small_file_unique_id: str = small_file_unique_id
|
|
|
|
self.big_file_id: str = big_file_id
|
|
|
|
self.big_file_unique_id: str = big_file_unique_id
|
2020-03-28 16:37:26 +01:00
|
|
|
|
|
|
|
self._id_attrs = (
|
|
|
|
self.small_file_unique_id,
|
|
|
|
self.big_file_unique_id,
|
|
|
|
)
|
2017-07-01 17:08:45 +02:00
|
|
|
|
2022-12-15 15:00:36 +01:00
|
|
|
self._freeze()
|
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
async def get_small_file(
|
|
|
|
self,
|
2022-05-18 17:18:44 +02:00
|
|
|
*,
|
2022-04-24 12:38:09 +02:00
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
2023-05-18 07:57:59 +02:00
|
|
|
api_kwargs: Optional[JSONDict] = None,
|
2021-02-19 19:07:48 +01:00
|
|
|
) -> "File":
|
2022-12-15 15:20:04 +01:00
|
|
|
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the small
|
2022-11-22 11:07:42 +01:00
|
|
|
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
|
|
|
|
chat photo
|
2019-09-13 21:07:56 +02:00
|
|
|
|
2020-12-30 13:41:07 +01:00
|
|
|
For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`.
|
2019-09-13 21:07:56 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.File`
|
|
|
|
|
|
|
|
Raises:
|
2021-02-01 17:59:39 +01:00
|
|
|
:class:`telegram.error.TelegramError`
|
2019-09-13 21:07:56 +02:00
|
|
|
|
|
|
|
"""
|
2022-04-24 12:38:09 +02:00
|
|
|
return await self.get_bot().get_file(
|
|
|
|
file_id=self.small_file_id,
|
|
|
|
read_timeout=read_timeout,
|
|
|
|
write_timeout=write_timeout,
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
pool_timeout=pool_timeout,
|
|
|
|
api_kwargs=api_kwargs,
|
2020-12-30 13:41:07 +01:00
|
|
|
)
|
2019-09-13 21:07:56 +02:00
|
|
|
|
2022-04-24 12:38:09 +02:00
|
|
|
async def get_big_file(
|
|
|
|
self,
|
2022-05-18 17:18:44 +02:00
|
|
|
*,
|
2022-04-24 12:38:09 +02:00
|
|
|
read_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
write_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
connect_timeout: ODVInput[float] = DEFAULT_NONE,
|
|
|
|
pool_timeout: ODVInput[float] = DEFAULT_NONE,
|
2023-05-18 07:57:59 +02:00
|
|
|
api_kwargs: Optional[JSONDict] = None,
|
2021-02-19 19:07:48 +01:00
|
|
|
) -> "File":
|
2022-12-15 15:20:04 +01:00
|
|
|
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the
|
2022-11-22 11:07:42 +01:00
|
|
|
big (:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
|
|
|
|
chat photo
|
2019-09-13 21:07:56 +02:00
|
|
|
|
2020-12-30 13:41:07 +01:00
|
|
|
For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`.
|
2019-09-13 21:07:56 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
:class:`telegram.File`
|
|
|
|
|
|
|
|
Raises:
|
2021-02-01 17:59:39 +01:00
|
|
|
:class:`telegram.error.TelegramError`
|
2019-09-13 21:07:56 +02:00
|
|
|
|
|
|
|
"""
|
2022-04-24 12:38:09 +02:00
|
|
|
return await self.get_bot().get_file(
|
|
|
|
file_id=self.big_file_id,
|
|
|
|
read_timeout=read_timeout,
|
|
|
|
write_timeout=write_timeout,
|
|
|
|
connect_timeout=connect_timeout,
|
|
|
|
pool_timeout=pool_timeout,
|
|
|
|
api_kwargs=api_kwargs,
|
2021-10-21 11:17:12 +02:00
|
|
|
)
|
2022-11-22 11:07:42 +01:00
|
|
|
|
2023-06-29 18:17:47 +02:00
|
|
|
SIZE_SMALL: Final[int] = constants.ChatPhotoSize.SMALL
|
2022-11-22 11:07:42 +01:00
|
|
|
""":const:`telegram.constants.ChatPhotoSize.SMALL`
|
|
|
|
|
|
|
|
.. versionadded:: 20.0
|
|
|
|
"""
|
2023-06-29 18:17:47 +02:00
|
|
|
SIZE_BIG: Final[int] = constants.ChatPhotoSize.BIG
|
2022-11-22 11:07:42 +01:00
|
|
|
""":const:`telegram.constants.ChatPhotoSize.BIG`
|
|
|
|
|
|
|
|
.. versionadded:: 20.0
|
|
|
|
"""
|