mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-30 09:32:49 +00:00
Add is_public parameter to set_profile_photo and minor fixes (#35)
* Fix invalid usage of input_message_content.write method (without await). Signed-off-by: Aliwoto <aminnimaj@gmail.com> * Fix promote_chat_member using can_post_stories for edit_story permission. Signed-off-by: Aliwoto <aminnimaj@gmail.com> * Refactor get_forum_topics_by_id method and make sure to pass messages parameter to it (if it exists). Signed-off-by: Aliwoto <aminnimaj@gmail.com> * Add fallback parameter to set_profile_photo method. Signed-off-by: Aliwoto <aminnimaj@gmail.com> * Fix download_media method not checking for file_id. Signed-off-by: Aliwoto <aminnimaj@gmail.com> * Rename fallback to is_public * Revert get_forum_topics_by_id.py --------- Signed-off-by: Aliwoto <aminnimaj@gmail.com> Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com>
This commit is contained in:
parent
50dbfd33fe
commit
76d5249daa
@ -87,7 +87,7 @@ class PromoteChatMember:
|
||||
post_messages=privileges.can_post_messages,
|
||||
post_stories=privileges.can_post_stories,
|
||||
edit_messages=privileges.can_edit_messages,
|
||||
edit_stories=privileges.can_post_stories,
|
||||
edit_stories=privileges.can_edit_stories,
|
||||
delete_messages=privileges.can_delete_messages,
|
||||
delete_stories=privileges.can_delete_stories,
|
||||
ban_users=privileges.can_restrict_members,
|
||||
|
@ -104,6 +104,9 @@ class DownloadMedia:
|
||||
# Download from file id
|
||||
await app.download_media(message.photo.file_id)
|
||||
|
||||
# Download document of a message
|
||||
await app.download_media(message.document)
|
||||
|
||||
# Keep track of the progress while downloading
|
||||
async def progress(current, total):
|
||||
print(f"{current * 100 / total:.1f}%")
|
||||
@ -138,6 +141,8 @@ class DownloadMedia:
|
||||
media = getattr(message, message.media.value, None)
|
||||
elif isinstance(message, str):
|
||||
media = message
|
||||
elif hasattr(message, "file_id"):
|
||||
media = getattr(message, "file_id")
|
||||
|
||||
if not media:
|
||||
raise ValueError("This message doesn't contain any downloadable media")
|
||||
|
@ -16,7 +16,7 @@
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Union, BinaryIO
|
||||
from typing import Union, BinaryIO, Optional
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw
|
||||
@ -26,8 +26,9 @@ class SetProfilePhoto:
|
||||
async def set_profile_photo(
|
||||
self: "pyrogram.Client",
|
||||
*,
|
||||
photo: Union[str, BinaryIO] = None,
|
||||
video: Union[str, BinaryIO] = None
|
||||
photo: Optional[Union[str, BinaryIO]] = None,
|
||||
video: Optional[Union[str, BinaryIO]] = None,
|
||||
is_public: Optional[bool] = None
|
||||
) -> bool:
|
||||
"""Set a new profile photo or video (H.264/MPEG-4 AVC video, max 5 seconds).
|
||||
|
||||
@ -52,6 +53,11 @@ class SetProfilePhoto:
|
||||
Pass a file path as string to upload a new video that exists on your local machine or
|
||||
pass a binary file-like object with its attribute ".name" set for in-memory uploads.
|
||||
|
||||
is_public (``bool``, *optional*):
|
||||
If set to True, the chosen profile photo will be shown to users that can't display
|
||||
your main profile photo due to your privacy settings.
|
||||
Defaults to None.
|
||||
|
||||
Returns:
|
||||
``bool``: True on success.
|
||||
|
||||
@ -63,11 +69,15 @@ class SetProfilePhoto:
|
||||
|
||||
# Set a new profile video
|
||||
await app.set_profile_photo(video="new_video.mp4")
|
||||
|
||||
# Set/update your account's public profile photo
|
||||
await app.set_profile_photo(photo="new_photo.jpg", is_public=True)
|
||||
"""
|
||||
|
||||
return bool(
|
||||
await self.invoke(
|
||||
raw.functions.photos.UploadProfilePhoto(
|
||||
fallback=is_public,
|
||||
file=await self.save_file(photo),
|
||||
video=await self.save_file(video)
|
||||
)
|
||||
|
@ -144,7 +144,7 @@ class InlineQueryResultAnimation(InlineQueryResult):
|
||||
thumb=thumb,
|
||||
content=animation,
|
||||
send_message=(
|
||||
self.input_message_content.write(client, self.reply_markup)
|
||||
await self.input_message_content.write(client, self.reply_markup)
|
||||
if self.input_message_content
|
||||
else raw.types.InputBotInlineMessageMediaAuto(
|
||||
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
|
||||
|
Loading…
Reference in New Issue
Block a user