mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/methods/users/get_user_profile_photos.py
This commit is contained in:
commit
a2b4d59cdb
16 changed files with 174 additions and 38 deletions
|
|
@ -494,17 +494,16 @@ def start():
|
||||||
f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",")
|
f.write("\n 0xb0700015: \"pyrogram.client.types.ChatPhoto\",")
|
||||||
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
|
f.write("\n 0xb0700016: \"pyrogram.client.types.ChatMember\",")
|
||||||
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
|
f.write("\n 0xb0700017: \"pyrogram.client.types.Sticker\",")
|
||||||
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
|
|
||||||
f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",")
|
|
||||||
|
|
||||||
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
|
f.write("\n 0xb0700018: \"pyrogram.client.types.reply_markup.ForceReply\",")
|
||||||
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")
|
f.write("\n 0xb0700019: \"pyrogram.client.types.reply_markup.InlineKeyboardButton\",")
|
||||||
f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",")
|
f.write("\n 0xb0700020: \"pyrogram.client.types.reply_markup.InlineKeyboardMarkup\",")
|
||||||
f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",")
|
f.write("\n 0xb0700021: \"pyrogram.client.types.reply_markup.KeyboardButton\",")
|
||||||
f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",")
|
f.write("\n 0xb0700022: \"pyrogram.client.types.reply_markup.ReplyKeyboardMarkup\",")
|
||||||
f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",")
|
f.write("\n 0xb0700023: \"pyrogram.client.types.reply_markup.ReplyKeyboardRemove\",")
|
||||||
|
f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\",")
|
||||||
f.write("\n 0xb0700024: \"pyrogram.client.types.CallbackQuery\"")
|
f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",")
|
||||||
|
f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",")
|
||||||
|
f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",")
|
||||||
|
|
||||||
f.write("\n}\n")
|
f.write("\n}\n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ Client
|
||||||
send_chat_action
|
send_chat_action
|
||||||
download_media
|
download_media
|
||||||
get_user_profile_photos
|
get_user_profile_photos
|
||||||
|
delete_profile_photos
|
||||||
edit_message_text
|
edit_message_text
|
||||||
edit_message_caption
|
edit_message_caption
|
||||||
edit_message_reply_markup
|
edit_message_reply_markup
|
||||||
|
|
|
||||||
5
docs/source/pyrogram/types/Photo.rst
Normal file
5
docs/source/pyrogram/types/Photo.rst
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
Photo
|
||||||
|
=====
|
||||||
|
|
||||||
|
.. autoclass:: pyrogram.Photo
|
||||||
|
:members:
|
||||||
|
|
@ -9,6 +9,7 @@ Types
|
||||||
Message
|
Message
|
||||||
MessageEntity
|
MessageEntity
|
||||||
Messages
|
Messages
|
||||||
|
Photo
|
||||||
PhotoSize
|
PhotoSize
|
||||||
Audio
|
Audio
|
||||||
Document
|
Document
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ from .api.errors import Error
|
||||||
from .client.types import (
|
from .client.types import (
|
||||||
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
|
Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto,
|
||||||
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
|
InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity,
|
||||||
PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, Video,
|
Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF,
|
||||||
VideoNote, Voice, CallbackQuery, Messages
|
Video, VideoNote, Voice, CallbackQuery, Messages
|
||||||
)
|
)
|
||||||
from .client.types.reply_markup import (
|
from .client.types.reply_markup import (
|
||||||
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
||||||
|
|
|
||||||
|
|
@ -329,13 +329,23 @@ async def parse_messages(
|
||||||
),
|
),
|
||||||
width=size.w,
|
width=size.w,
|
||||||
height=size.h,
|
height=size.h,
|
||||||
file_size=file_size,
|
file_size=file_size
|
||||||
date=photo.date
|
|
||||||
)
|
)
|
||||||
|
|
||||||
photo_sizes.append(photo_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):
|
elif isinstance(media, types.MessageMediaGeo):
|
||||||
geo_point = media.geo
|
geo_point = media.geo
|
||||||
|
|
||||||
|
|
@ -664,13 +674,23 @@ async def parse_messages(
|
||||||
),
|
),
|
||||||
width=size.w,
|
width=size.w,
|
||||||
height=size.h,
|
height=size.h,
|
||||||
file_size=file_size,
|
file_size=file_size
|
||||||
date=photo.date
|
|
||||||
)
|
)
|
||||||
|
|
||||||
photo_sizes.append(photo_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(
|
m = pyrogram_types.Message(
|
||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
|
|
@ -757,7 +777,7 @@ def get_offset_date(dialogs):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def parse_photos(photos):
|
def parse_profile_photos(photos):
|
||||||
if isinstance(photos, types.photos.Photos):
|
if isinstance(photos, types.photos.Photos):
|
||||||
total_count = len(photos.photos)
|
total_count = len(photos.photos)
|
||||||
else:
|
else:
|
||||||
|
|
@ -795,13 +815,25 @@ def parse_photos(photos):
|
||||||
),
|
),
|
||||||
width=size.w,
|
width=size.w,
|
||||||
height=size.h,
|
height=size.h,
|
||||||
file_size=file_size,
|
file_size=file_size
|
||||||
date=photo.date
|
|
||||||
)
|
)
|
||||||
|
|
||||||
photo_sizes.append(photo_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(
|
return pyrogram_types.UserProfilePhotos(
|
||||||
total_count=total_count,
|
total_count=total_count,
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class DownloadMedia(BaseClient):
|
||||||
"""
|
"""
|
||||||
if isinstance(message, pyrogram_types.Message):
|
if isinstance(message, pyrogram_types.Message):
|
||||||
if message.photo:
|
if message.photo:
|
||||||
media = message.photo[-1]
|
media = message.photo.sizes[-1]
|
||||||
elif message.audio:
|
elif message.audio:
|
||||||
media = message.audio
|
media = message.audio
|
||||||
elif message.document:
|
elif message.document:
|
||||||
|
|
@ -95,7 +95,7 @@ class DownloadMedia(BaseClient):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
elif isinstance(message, (
|
elif isinstance(message, (
|
||||||
pyrogram_types.PhotoSize,
|
pyrogram_types.Photo,
|
||||||
pyrogram_types.Audio,
|
pyrogram_types.Audio,
|
||||||
pyrogram_types.Document,
|
pyrogram_types.Document,
|
||||||
pyrogram_types.Video,
|
pyrogram_types.Video,
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from .delete_profile_photos import DeleteProfilePhotos
|
||||||
from .get_me import GetMe
|
from .get_me import GetMe
|
||||||
from .get_user_profile_photos import GetUserProfilePhotos
|
from .get_user_profile_photos import GetUserProfilePhotos
|
||||||
from .get_users import GetUsers
|
from .get_users import GetUsers
|
||||||
|
|
@ -23,6 +24,7 @@ from .get_users import GetUsers
|
||||||
|
|
||||||
class Users(
|
class Users(
|
||||||
GetUserProfilePhotos,
|
GetUserProfilePhotos,
|
||||||
|
DeleteProfilePhotos,
|
||||||
GetUsers,
|
GetUsers,
|
||||||
GetMe
|
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:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>`
|
:class:`Error <pyrogram.Error>`
|
||||||
"""
|
"""
|
||||||
return utils.parse_photos(
|
return utils.parse_profile_photos(
|
||||||
await self.send(
|
await self.send(
|
||||||
functions.photos.GetUserPhotos(
|
functions.photos.GetUserPhotos(
|
||||||
user_id=await self.resolve_peer(user_id),
|
user_id=await self.resolve_peer(user_id),
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ from .location import Location
|
||||||
from .message import Message
|
from .message import Message
|
||||||
from .message_entity import MessageEntity
|
from .message_entity import MessageEntity
|
||||||
from .messages import Messages
|
from .messages import Messages
|
||||||
|
from .photo import Photo
|
||||||
from .photo_size import PhotoSize
|
from .photo_size import PhotoSize
|
||||||
from .reply_markup import (
|
from .reply_markup import (
|
||||||
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,8 @@ class Message(Object):
|
||||||
game (:obj:`Game <pyrogram.Game>`, *optional*):
|
game (:obj:`Game <pyrogram.Game>`, *optional*):
|
||||||
Message is a game, information about the game. More about games.
|
Message is a game, information about the game. More about games.
|
||||||
|
|
||||||
photo (List of :obj:`PhotoSize <pyrogram.PhotoSize>`, *optional*):
|
photo (:obj:`Photo <pyrogram.Photo>`, *optional*):
|
||||||
Message is a photo, available sizes of the photo.
|
Message is a photo, information about the photo.
|
||||||
|
|
||||||
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
|
sticker (:obj:`Sticker <pyrogram.Sticker>`, *optional*):
|
||||||
Message is a sticker, information about the sticker.
|
Message is a sticker, information about the sticker.
|
||||||
|
|
@ -132,7 +132,7 @@ class Message(Object):
|
||||||
new_chat_title (``str``, *optional*):
|
new_chat_title (``str``, *optional*):
|
||||||
A chat title was changed to this value.
|
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.
|
A chat photo was change to this value.
|
||||||
|
|
||||||
delete_chat_photo (``bool``, *optional*):
|
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``):
|
height (``int``):
|
||||||
Photo height.
|
Photo height.
|
||||||
|
|
||||||
file_size (``int``, *optional*):
|
file_size (``int``):
|
||||||
File size.
|
File size.
|
||||||
|
|
||||||
date (``int``, *optional*):
|
|
||||||
Date the photo was sent in Unix time
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ID = 0xb0700005
|
ID = 0xb0700005
|
||||||
|
|
||||||
def __init__(self, file_id, width, height, file_size=None, date=None):
|
def __init__(self, file_id: str, width: int, height: int, file_size: int):
|
||||||
self.file_id = file_id # string
|
self.file_id = file_id
|
||||||
self.width = width # int
|
self.width = width
|
||||||
self.height = height # int
|
self.height = height
|
||||||
self.file_size = file_size # flags.0?int
|
self.file_size = file_size
|
||||||
self.date = date
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
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):
|
def __init__(self, selective: bool = None):
|
||||||
self.selective = selective
|
self.selective = selective
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,12 @@ class UserProfilePhotos(Object):
|
||||||
total_count (``int``):
|
total_count (``int``):
|
||||||
Total number of profile pictures the target user has.
|
Total number of profile pictures the target user has.
|
||||||
|
|
||||||
photos (List of List of :obj:`PhotoSize <pyrogram.PhotoSize>`):
|
photos (List of :obj:`Photo <pyrogram.Photo>`):
|
||||||
Requested profile pictures (in up to 4 sizes each).
|
Requested profile pictures.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ID = 0xb0700014
|
ID = 0xb0700014
|
||||||
|
|
||||||
def __init__(self, total_count: int, photos: list):
|
def __init__(self, total_count: int, photos: list):
|
||||||
self.total_count = total_count # int
|
self.total_count = total_count
|
||||||
self.photos = photos # Vector<Vector<PhotoSize>>
|
self.photos = photos
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue