mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-05 08:45:13 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/methods/users/get_user_profile_photos.py
This commit is contained in:
@@ -37,8 +37,8 @@ from .api.errors import Error
|
||||
from .client.types import (
|
||||
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
|
||||
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
|
||||
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
|
||||
VideoNote, Voice, CallbackQuery, Messages
|
||||
Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF,
|
||||
Video, VideoNote, Voice, CallbackQuery, Messages
|
||||
)
|
||||
from .client.types.reply_markup import (
|
||||
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
||||
|
@@ -329,13 +329,23 @@ async def parse_messages(
|
||||
),
|
||||
width=size.w,
|
||||
height=size.h,
|
||||
file_size=file_size,
|
||||
date=photo.date
|
||||
file_size=file_size
|
||||
)
|
||||
|
||||
photo_sizes.append(photo_size)
|
||||
|
||||
photo = photo_sizes
|
||||
photo = pyrogram_types.Photo(
|
||||
id=b64encode(
|
||||
pack(
|
||||
"<qq",
|
||||
photo.id,
|
||||
photo.access_hash
|
||||
),
|
||||
b"-_"
|
||||
).decode().rstrip("="),
|
||||
date=photo.date,
|
||||
sizes=photo_sizes
|
||||
)
|
||||
elif isinstance(media, types.MessageMediaGeo):
|
||||
geo_point = media.geo
|
||||
|
||||
@@ -664,13 +674,23 @@ async def parse_messages(
|
||||
),
|
||||
width=size.w,
|
||||
height=size.h,
|
||||
file_size=file_size,
|
||||
date=photo.date
|
||||
file_size=file_size
|
||||
)
|
||||
|
||||
photo_sizes.append(photo_size)
|
||||
|
||||
new_chat_photo = photo_sizes
|
||||
new_chat_photo = pyrogram_types.Photo(
|
||||
id=b64encode(
|
||||
pack(
|
||||
"<qq",
|
||||
photo.id,
|
||||
photo.access_hash
|
||||
),
|
||||
b"-_"
|
||||
).decode().rstrip("="),
|
||||
date=photo.date,
|
||||
sizes=photo_sizes
|
||||
)
|
||||
|
||||
m = pyrogram_types.Message(
|
||||
message_id=message.id,
|
||||
@@ -757,7 +777,7 @@ def get_offset_date(dialogs):
|
||||
return 0
|
||||
|
||||
|
||||
def parse_photos(photos):
|
||||
def parse_profile_photos(photos):
|
||||
if isinstance(photos, types.photos.Photos):
|
||||
total_count = len(photos.photos)
|
||||
else:
|
||||
@@ -795,13 +815,25 @@ def parse_photos(photos):
|
||||
),
|
||||
width=size.w,
|
||||
height=size.h,
|
||||
file_size=file_size,
|
||||
date=photo.date
|
||||
file_size=file_size
|
||||
)
|
||||
|
||||
photo_sizes.append(photo_size)
|
||||
|
||||
user_profile_photos.append(photo_sizes)
|
||||
user_profile_photos.append(
|
||||
pyrogram_types.Photo(
|
||||
id=b64encode(
|
||||
pack(
|
||||
"<qq",
|
||||
photo.id,
|
||||
photo.access_hash
|
||||
),
|
||||
b"-_"
|
||||
).decode().rstrip("="),
|
||||
date=photo.date,
|
||||
sizes=photo_sizes
|
||||
)
|
||||
)
|
||||
|
||||
return pyrogram_types.UserProfilePhotos(
|
||||
total_count=total_count,
|
||||
|
@@ -77,7 +77,7 @@ class DownloadMedia(BaseClient):
|
||||
"""
|
||||
if isinstance(message, pyrogram_types.Message):
|
||||
if message.photo:
|
||||
media = message.photo[-1]
|
||||
media = message.photo.sizes[-1]
|
||||
elif message.audio:
|
||||
media = message.audio
|
||||
elif message.document:
|
||||
@@ -95,7 +95,7 @@ class DownloadMedia(BaseClient):
|
||||
else:
|
||||
return
|
||||
elif isinstance(message, (
|
||||
pyrogram_types.PhotoSize,
|
||||
pyrogram_types.Photo,
|
||||
pyrogram_types.Audio,
|
||||
pyrogram_types.Document,
|
||||
pyrogram_types.Video,
|
||||
|
@@ -16,6 +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 .delete_profile_photos import DeleteProfilePhotos
|
||||
from .get_me import GetMe
|
||||
from .get_user_profile_photos import GetUserProfilePhotos
|
||||
from .get_users import GetUsers
|
||||
@@ -23,6 +24,7 @@ from .get_users import GetUsers
|
||||
|
||||
class Users(
|
||||
GetUserProfilePhotos,
|
||||
DeleteProfilePhotos,
|
||||
GetUsers,
|
||||
GetMe
|
||||
):
|
||||
|
58
pyrogram/client/methods/users/delete_profile_photos.py
Normal file
58
pyrogram/client/methods/users/delete_profile_photos.py
Normal file
@@ -0,0 +1,58 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram 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 General Public License for more details.
|
||||
#
|
||||
# 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 base64 import b64decode
|
||||
from struct import unpack
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
class DeleteProfilePhotos(BaseClient):
|
||||
def delete_profile_photos(self, id: str or list):
|
||||
"""Use this method to delete your own profile photos
|
||||
|
||||
Args:
|
||||
id (``str`` | ``list``):
|
||||
A single :obj:`Photo <pyrogram.Photo>` id as string or multiple ids as list of strings for deleting
|
||||
more than one photos at once.
|
||||
|
||||
Returns:
|
||||
True on success.
|
||||
|
||||
Raises:
|
||||
:class:`Error <pyrogram.Error>`
|
||||
"""
|
||||
id = id if isinstance(id, list) else [id]
|
||||
input_photos = []
|
||||
|
||||
for i in id:
|
||||
s = unpack("<qq", b64decode(i + "=" * (-len(i) % 4), "-_"))
|
||||
|
||||
input_photos.append(
|
||||
types.InputPhoto(
|
||||
id=s[0],
|
||||
access_hash=s[1]
|
||||
)
|
||||
)
|
||||
|
||||
return bool(self.send(
|
||||
functions.photos.DeletePhotos(
|
||||
id=input_photos
|
||||
)
|
||||
))
|
@@ -48,7 +48,7 @@ class GetUserProfilePhotos(BaseClient):
|
||||
Raises:
|
||||
:class:`Error <pyrogram.Error>`
|
||||
"""
|
||||
return utils.parse_photos(
|
||||
return utils.parse_profile_photos(
|
||||
await self.send(
|
||||
functions.photos.GetUserPhotos(
|
||||
user_id=await self.resolve_peer(user_id),
|
||||
|
@@ -31,6 +31,7 @@ from .location import Location
|
||||
from .message import Message
|
||||
from .message_entity import MessageEntity
|
||||
from .messages import Messages
|
||||
from .photo import Photo
|
||||
from .photo_size import PhotoSize
|
||||
from .reply_markup import (
|
||||
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
||||
|
@@ -89,8 +89,8 @@ class Message(Object):
|
||||
game (:obj:`Game <pyrogram.Game>`, *optional*):
|
||||
Message is a game, information about the game. More about games.
|
||||
|
||||
photo (List of :obj:`PhotoSize <pyrogram.PhotoSize>`, *optional*):
|
||||
Message is a photo, available sizes of the photo.
|
||||
photo (:obj:`Photo <pyrogram.Photo>`, *optional*):
|
||||
Message is a photo, information about the photo.
|
||||
|
||||
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
|
||||
Message is a sticker, information about the sticker.
|
||||
@@ -132,7 +132,7 @@ class Message(Object):
|
||||
new_chat_title (``str``, *optional*):
|
||||
A chat title was changed to this value.
|
||||
|
||||
new_chat_photo (List of :obj:`PhotoSize <pyrogram.PhotoSize>`, *optional*):
|
||||
new_chat_photo (:obj:`Photo <pyrogram.Photo>`, *optional*):
|
||||
A chat photo was change to this value.
|
||||
|
||||
delete_chat_photo (``bool``, *optional*):
|
||||
|
41
pyrogram/client/types/photo.py
Normal file
41
pyrogram/client/types/photo.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram 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 General Public License for more details.
|
||||
#
|
||||
# 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 pyrogram.api.core import Object
|
||||
|
||||
|
||||
class Photo(Object):
|
||||
"""This object represents a Photo
|
||||
|
||||
Args:
|
||||
id (``str``):
|
||||
Unique identifier for this photo.
|
||||
|
||||
date (``int``):
|
||||
Date the photo was sent in Unix time
|
||||
|
||||
sizes (List of :obj:`PhotoSize <pyrogram.PhotoSize>`):
|
||||
Available sizes of this photo
|
||||
"""
|
||||
|
||||
ID = 0xb0700027
|
||||
|
||||
def __init__(self, id: str, date: int, sizes: list):
|
||||
self.id = id
|
||||
self.date = date
|
||||
self.sizes = sizes
|
@@ -32,18 +32,14 @@ class PhotoSize(Object):
|
||||
height (``int``):
|
||||
Photo height.
|
||||
|
||||
file_size (``int``, *optional*):
|
||||
file_size (``int``):
|
||||
File size.
|
||||
|
||||
date (``int``, *optional*):
|
||||
Date the photo was sent in Unix time
|
||||
"""
|
||||
|
||||
ID = 0xb0700005
|
||||
|
||||
def __init__(self, file_id, width, height, file_size=None, date=None):
|
||||
self.file_id = file_id # string
|
||||
self.width = width # int
|
||||
self.height = height # int
|
||||
self.file_size = file_size # flags.0?int
|
||||
self.date = date
|
||||
def __init__(self, file_id: str, width: int, height: int, file_size: int):
|
||||
self.file_id = file_id
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.file_size = file_size
|
||||
|
@@ -35,7 +35,7 @@ class ReplyKeyboardRemove(Object):
|
||||
keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
|
||||
"""
|
||||
|
||||
ID = 0xb0700002
|
||||
ID = 0xb0700023
|
||||
|
||||
def __init__(self, selective: bool = None):
|
||||
self.selective = selective
|
||||
|
@@ -26,12 +26,12 @@ class UserProfilePhotos(Object):
|
||||
total_count (``int``):
|
||||
Total number of profile pictures the target user has.
|
||||
|
||||
photos (List of List of :obj:`PhotoSize <pyrogram.PhotoSize>`):
|
||||
Requested profile pictures (in up to 4 sizes each).
|
||||
photos (List of :obj:`Photo <pyrogram.Photo>`):
|
||||
Requested profile pictures.
|
||||
"""
|
||||
|
||||
ID = 0xb0700014
|
||||
|
||||
def __init__(self, total_count: int, photos: list):
|
||||
self.total_count = total_count # int
|
||||
self.photos = photos # Vector<Vector<PhotoSize>>
|
||||
self.total_count = total_count
|
||||
self.photos = photos
|
||||
|
Reference in New Issue
Block a user