-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Api 9.0 profile photos #4766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Api 9.0 profile photos #4766
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1fcfb5a
InputProfilePhoto* classes
Bibo-Joshi 134a3b6
set_remove_b_a_profile_photo
Bibo-Joshi 471cd9f
doc update
Bibo-Joshi 6ea9392
update chango fragment
Bibo-Joshi db88e52
Add chango fragment for PR #4766
Bibo-Joshi 129e7ee
update chango fragment
Bibo-Joshi 717cf1a
typos - thanks copilot
Bibo-Joshi ca75aa7
test_official
Bibo-Joshi cecba9c
fix ext bot signature
Bibo-Joshi 08717b0
Update telegram/_files/inputprofilephoto.py
Bibo-Joshi c5a817b
Update telegram/_files/inputprofilephoto.py
Bibo-Joshi a7e289c
reviews :)
Bibo-Joshi dd1bbeb
Add chango fragment for PR #4766
Bibo-Joshi e87abe7
Delete changes/unreleased/4766.JT5nmUmGRG6qDEh5ScMn5f.toml
Bibo-Joshi f8f88c4
Add chango fragment for PR #4766
Bibo-Joshi 6383fe9
Delete changes/unreleased/4766.JT5nmUmGRG6qDEh5ScMn5f.toml
Bibo-Joshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
InputProfilePhoto | ||
================= | ||
|
||
.. autoclass:: telegram.InputProfilePhoto | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
InputProfilePhotoAnimated | ||
========================= | ||
|
||
.. autoclass:: telegram.InputProfilePhotoAnimated | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
InputProfilePhotoStatic | ||
======================= | ||
|
||
.. autoclass:: telegram.InputProfilePhotoStatic | ||
:members: | ||
:show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/usr/bin/env python | ||
# | ||
# A library that provides a Python interface to the Telegram Bot API | ||
# Copyright (C) 2015-2025 | ||
# 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 objects that represents a InputProfilePhoto and subclasses.""" | ||
|
||
import datetime as dtm | ||
from typing import TYPE_CHECKING, Optional, Union | ||
|
||
from telegram import constants | ||
from telegram._telegramobject import TelegramObject | ||
from telegram._utils import enum | ||
from telegram._utils.files import parse_file_input | ||
from telegram._utils.types import FileInput, JSONDict | ||
|
||
if TYPE_CHECKING: | ||
from telegram import InputFile | ||
|
||
|
||
class InputProfilePhoto(TelegramObject): | ||
"""This object describes a profile photo to set. Currently, it can be one of | ||
|
||
* :class:`InputProfilePhotoStatic` | ||
* :class:`InputProfilePhotoAnimated` | ||
|
||
.. versionadded:: NEXT.VERSION | ||
|
||
Args: | ||
type (:obj:`str`): Type of the profile photo. | ||
|
||
Attributes: | ||
type (:obj:`str`): Type of the profile photo. | ||
|
||
""" | ||
|
||
STATIC = constants.InputProfilePhotoType.STATIC | ||
""":obj:`str`: :tg-const:`telegram.constants.InputProfilePhotoType.STATIC`.""" | ||
ANIMATED = constants.InputProfilePhotoType.ANIMATED | ||
""":obj:`str`: :tg-const:`telegram.constants.InputProfilePhotoType.ANIMATED`.""" | ||
|
||
__slots__ = ("type",) | ||
|
||
def __init__( | ||
self, | ||
type: str, # pylint: disable=redefined-builtin | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(api_kwargs=api_kwargs) | ||
self.type: str = enum.get_member(constants.InputProfilePhotoType, type, type) | ||
|
||
self._freeze() | ||
|
||
|
||
class InputProfilePhotoStatic(InputProfilePhoto): | ||
"""A static profile photo in the .JPG format. | ||
|
||
.. versionadded:: NEXT.VERSION | ||
|
||
Args: | ||
photo (:term:`file object` | :class:`~telegram.InputFile` | :obj:`bytes` | \ | ||
:class:`pathlib.Path`): The static profile photo. |uploadinputnopath| | ||
|
||
Attributes: | ||
type (:obj:`str`): :tg-const:`telegram.constants.InputProfilePhotoType.STATIC`. | ||
photo (:class:`telegram.InputFile` | :obj:`str`): The static profile photo. | ||
|
||
""" | ||
|
||
__slots__ = ("photo",) | ||
|
||
def __init__( | ||
self, | ||
photo: FileInput, | ||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(type=constants.InputProfilePhotoType.STATIC, api_kwargs=api_kwargs) | ||
with self._unfrozen(): | ||
# We use local_mode=True because we don't have access to the actual setting and want | ||
# things to work in local mode. | ||
self.photo: Union[str, InputFile] = parse_file_input( | ||
photo, attach=True, local_mode=True | ||
) | ||
|
||
|
||
class InputProfilePhotoAnimated(InputProfilePhoto): | ||
"""An animated profile photo in the MPEG4 format. | ||
|
||
.. versionadded:: NEXT.VERSION | ||
|
||
Args: | ||
animation (:term:`file object` | :class:`~telegram.InputFile` | :obj:`bytes` | \ | ||
:class:`pathlib.Path`): The animated profile photo. |uploadinputnopath| | ||
main_frame_timestamp (:class:`datetime.timedelta` | :obj:`int` | :obj:`float`, optional): | ||
Timestamp in seconds of the frame that will be used as the static profile photo. | ||
Defaults to ``0.0``. | ||
|
||
Attributes: | ||
type (:obj:`str`): :tg-const:`telegram.constants.InputProfilePhotoType.ANIMATED`. | ||
animation (:class:`telegram.InputFile` | :obj:`str`): The animated profile photo. | ||
main_frame_timestamp (:class:`datetime.timedelta`): Optional. Timestamp in seconds of the | ||
Bibo-Joshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
frame that will be used as the static profile photo. Defaults to ``0.0``. | ||
""" | ||
|
||
__slots__ = ("animation", "main_frame_timestamp") | ||
|
||
def __init__( | ||
self, | ||
animation: FileInput, | ||
main_frame_timestamp: Union[float, dtm.timedelta, None] = None, | ||
aelkheir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*, | ||
api_kwargs: Optional[JSONDict] = None, | ||
): | ||
super().__init__(type=constants.InputProfilePhotoType.ANIMATED, api_kwargs=api_kwargs) | ||
with self._unfrozen(): | ||
# We use local_mode=True because we don't have access to the actual setting and want | ||
# things to work in local mode. | ||
self.animation: Union[str, InputFile] = parse_file_input( | ||
animation, attach=True, local_mode=True | ||
) | ||
|
||
if isinstance(main_frame_timestamp, dtm.timedelta): | ||
self.main_frame_timestamp: Optional[dtm.timedelta] = main_frame_timestamp | ||
elif main_frame_timestamp is None: | ||
self.main_frame_timestamp = None | ||
else: | ||
self.main_frame_timestamp = dtm.timedelta(seconds=main_frame_timestamp) | ||
aelkheir marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.