mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-31 22:35:36 +00:00
Merge develop -> asyncio
This commit is contained in:
@@ -24,7 +24,7 @@ if sys.version_info[:3] in [(3, 5, 0), (3, 5, 1), (3, 5, 2)]:
|
|||||||
# Monkey patch the standard "typing" module because Python versions from 3.5.0 to 3.5.2 have a broken one.
|
# Monkey patch the standard "typing" module because Python versions from 3.5.0 to 3.5.2 have a broken one.
|
||||||
sys.modules["typing"] = typing
|
sys.modules["typing"] = typing
|
||||||
|
|
||||||
__version__ = "0.14.0-asyncio"
|
__version__ = "0.14.1-asyncio"
|
||||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||||
__copyright__ = "Copyright (C) 2017-2019 Dan <https://github.com/delivrance>"
|
__copyright__ = "Copyright (C) 2017-2019 Dan <https://github.com/delivrance>"
|
||||||
|
|
||||||
|
@@ -884,7 +884,7 @@ class Client(Methods, BaseClient):
|
|||||||
temp_file_path = await self.get_file(
|
temp_file_path = await self.get_file(
|
||||||
media_type=data.media_type,
|
media_type=data.media_type,
|
||||||
dc_id=data.dc_id,
|
dc_id=data.dc_id,
|
||||||
file_id=data.file_id,
|
document_id=data.document_id,
|
||||||
access_hash=data.access_hash,
|
access_hash=data.access_hash,
|
||||||
thumb_size=data.thumb_size,
|
thumb_size=data.thumb_size,
|
||||||
peer_id=data.peer_id,
|
peer_id=data.peer_id,
|
||||||
@@ -1544,7 +1544,7 @@ class Client(Methods, BaseClient):
|
|||||||
|
|
||||||
async def get_file(self, media_type: int,
|
async def get_file(self, media_type: int,
|
||||||
dc_id: int,
|
dc_id: int,
|
||||||
file_id: int,
|
document_id: int,
|
||||||
access_hash: int,
|
access_hash: int,
|
||||||
thumb_size: str,
|
thumb_size: str,
|
||||||
peer_id: int,
|
peer_id: int,
|
||||||
@@ -1604,21 +1604,21 @@ class Client(Methods, BaseClient):
|
|||||||
)
|
)
|
||||||
elif media_type in (0, 2):
|
elif media_type in (0, 2):
|
||||||
location = types.InputPhotoFileLocation(
|
location = types.InputPhotoFileLocation(
|
||||||
id=file_id,
|
id=document_id,
|
||||||
access_hash=access_hash,
|
access_hash=access_hash,
|
||||||
file_reference=b"",
|
file_reference=b"",
|
||||||
thumb_size=thumb_size
|
thumb_size=thumb_size
|
||||||
)
|
)
|
||||||
elif media_type == 14:
|
elif media_type == 14:
|
||||||
location = types.InputDocumentFileLocation(
|
location = types.InputDocumentFileLocation(
|
||||||
id=file_id,
|
id=document_id,
|
||||||
access_hash=access_hash,
|
access_hash=access_hash,
|
||||||
file_reference=b"",
|
file_reference=b"",
|
||||||
thumb_size=thumb_size
|
thumb_size=thumb_size
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
location = types.InputDocumentFileLocation(
|
location = types.InputDocumentFileLocation(
|
||||||
id=file_id,
|
id=document_id,
|
||||||
access_hash=access_hash,
|
access_hash=access_hash,
|
||||||
file_reference=b"",
|
file_reference=b"",
|
||||||
thumb_size=""
|
thumb_size=""
|
||||||
|
@@ -20,3 +20,5 @@ from .base_client import BaseClient
|
|||||||
from .dispatcher import Dispatcher
|
from .dispatcher import Dispatcher
|
||||||
from .emoji import Emoji
|
from .emoji import Emoji
|
||||||
from .syncer import Syncer
|
from .syncer import Syncer
|
||||||
|
from .file_data import FileData
|
||||||
|
|
||||||
|
@@ -20,7 +20,6 @@ import asyncio
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import re
|
import re
|
||||||
from collections import namedtuple
|
|
||||||
|
|
||||||
from pyrogram import __version__
|
from pyrogram import __version__
|
||||||
from ..style import Markdown, HTML
|
from ..style import Markdown, HTML
|
||||||
@@ -83,10 +82,6 @@ class BaseClient:
|
|||||||
|
|
||||||
mime_types_to_extensions[mime_type] = " ".join(extensions)
|
mime_types_to_extensions[mime_type] = " ".join(extensions)
|
||||||
|
|
||||||
fields = ("media_type", "dc_id", "file_id", "access_hash", "thumb_size", "peer_id", "volume_id", "local_id",
|
|
||||||
"is_big", "file_size", "mime_type", "file_name", "date")
|
|
||||||
FileData = namedtuple("FileData", fields, defaults=(None,) * len(fields))
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.is_bot = None
|
self.is_bot = None
|
||||||
self.dc_id = None
|
self.dc_id = None
|
||||||
|
38
pyrogram/client/ext/file_data.py
Normal file
38
pyrogram/client/ext/file_data.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-2019 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/>.
|
||||||
|
|
||||||
|
|
||||||
|
class FileData:
|
||||||
|
def __init__(
|
||||||
|
self, *, media_type: int = None, dc_id: int = None, document_id: int = None, access_hash: int = None,
|
||||||
|
thumb_size: str = None, peer_id: int = None, volume_id: int = None, local_id: int = None, is_big: bool = None,
|
||||||
|
file_size: int = None, mime_type: str = None, file_name: str = None, date: int = None
|
||||||
|
):
|
||||||
|
self.media_type = media_type
|
||||||
|
self.dc_id = dc_id
|
||||||
|
self.document_id = document_id
|
||||||
|
self.access_hash = access_hash
|
||||||
|
self.thumb_size = thumb_size
|
||||||
|
self.peer_id = peer_id
|
||||||
|
self.volume_id = volume_id
|
||||||
|
self.local_id = local_id
|
||||||
|
self.is_big = is_big
|
||||||
|
self.file_size = file_size
|
||||||
|
self.mime_type = mime_type
|
||||||
|
self.file_name = file_name
|
||||||
|
self.date = date
|
@@ -47,26 +47,30 @@ class GetChatMember(BaseClient):
|
|||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
chat_id = await self.resolve_peer(chat_id)
|
chat = await self.resolve_peer(chat_id)
|
||||||
user_id = await self.resolve_peer(user_id)
|
user = await self.resolve_peer(user_id)
|
||||||
|
|
||||||
if isinstance(chat_id, types.InputPeerChat):
|
if isinstance(chat, types.InputPeerChat):
|
||||||
full_chat = await self.send(
|
full_chat = await self.send(
|
||||||
functions.messages.GetFullChat(
|
functions.messages.GetFullChat(
|
||||||
chat_id=chat_id.chat_id
|
chat_id=chat.chat_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members:
|
for member in pyrogram.ChatMembers._parse(self, full_chat).chat_members:
|
||||||
|
if isinstance(user, types.InputPeerSelf):
|
||||||
if member.user.is_self:
|
if member.user.is_self:
|
||||||
return member
|
return member
|
||||||
|
else:
|
||||||
|
if member.user.id == user.user_id:
|
||||||
|
return member
|
||||||
else:
|
else:
|
||||||
raise UserNotParticipant
|
raise UserNotParticipant
|
||||||
elif isinstance(chat_id, types.InputPeerChannel):
|
elif isinstance(chat, types.InputPeerChannel):
|
||||||
r = await self.send(
|
r = await self.send(
|
||||||
functions.channels.GetParticipant(
|
functions.channels.GetParticipant(
|
||||||
channel=chat_id,
|
channel=chat,
|
||||||
user_id=user_id
|
user_id=user
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ import struct
|
|||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.client.ext import BaseClient, utils
|
from pyrogram.client.ext import BaseClient, FileData, utils
|
||||||
from pyrogram.errors import FileIdInvalid
|
from pyrogram.errors import FileIdInvalid
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ class DownloadMedia(BaseClient):
|
|||||||
mime_type = getattr(media, "mime_type", None)
|
mime_type = getattr(media, "mime_type", None)
|
||||||
date = getattr(media, "date", None)
|
date = getattr(media, "date", None)
|
||||||
|
|
||||||
data = self.FileData(
|
data = FileData(
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
file_size=file_size,
|
file_size=file_size,
|
||||||
mime_type=mime_type,
|
mime_type=mime_type,
|
||||||
@@ -118,7 +118,7 @@ class DownloadMedia(BaseClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_existing_attributes() -> dict:
|
def get_existing_attributes() -> dict:
|
||||||
return dict(filter(lambda x: x[1] is not None, data._asdict().items()))
|
return dict(filter(lambda x: x[1] is not None, data.__dict__.items()))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decoded = utils.decode(file_id_str)
|
decoded = utils.decode(file_id_str)
|
||||||
@@ -128,7 +128,7 @@ class DownloadMedia(BaseClient):
|
|||||||
unpacked = struct.unpack("<iiqqib", decoded)
|
unpacked = struct.unpack("<iiqqib", decoded)
|
||||||
dc_id, peer_id, volume_id, local_id, is_big = unpacked[1:]
|
dc_id, peer_id, volume_id, local_id, is_big = unpacked[1:]
|
||||||
|
|
||||||
data = self.FileData(
|
data = FileData(
|
||||||
**get_existing_attributes(),
|
**get_existing_attributes(),
|
||||||
media_type=media_type,
|
media_type=media_type,
|
||||||
dc_id=dc_id,
|
dc_id=dc_id,
|
||||||
@@ -139,25 +139,25 @@ class DownloadMedia(BaseClient):
|
|||||||
)
|
)
|
||||||
elif media_type in (0, 2, 14):
|
elif media_type in (0, 2, 14):
|
||||||
unpacked = struct.unpack("<iiqqc", decoded)
|
unpacked = struct.unpack("<iiqqc", decoded)
|
||||||
dc_id, file_id, access_hash, thumb_size = unpacked[1:]
|
dc_id, document_id, access_hash, thumb_size = unpacked[1:]
|
||||||
|
|
||||||
data = self.FileData(
|
data = FileData(
|
||||||
**get_existing_attributes(),
|
**get_existing_attributes(),
|
||||||
media_type=media_type,
|
media_type=media_type,
|
||||||
dc_id=dc_id,
|
dc_id=dc_id,
|
||||||
file_id=file_id,
|
document_id=document_id,
|
||||||
access_hash=access_hash,
|
access_hash=access_hash,
|
||||||
thumb_size=thumb_size.decode()
|
thumb_size=thumb_size.decode()
|
||||||
)
|
)
|
||||||
elif media_type in (3, 4, 5, 8, 9, 10, 13):
|
elif media_type in (3, 4, 5, 8, 9, 10, 13):
|
||||||
unpacked = struct.unpack("<iiqq", decoded)
|
unpacked = struct.unpack("<iiqq", decoded)
|
||||||
dc_id, file_id, access_hash = unpacked[1:]
|
dc_id, document_id, access_hash = unpacked[1:]
|
||||||
|
|
||||||
data = self.FileData(
|
data = FileData(
|
||||||
**get_existing_attributes(),
|
**get_existing_attributes(),
|
||||||
media_type=media_type,
|
media_type=media_type,
|
||||||
dc_id=dc_id,
|
dc_id=dc_id,
|
||||||
file_id=file_id,
|
document_id=document_id,
|
||||||
access_hash=access_hash
|
access_hash=access_hash
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@@ -72,7 +72,7 @@ class Animation(Object):
|
|||||||
mime_type: str = None,
|
mime_type: str = None,
|
||||||
file_size: int = None,
|
file_size: int = None,
|
||||||
date: int = None,
|
date: int = None,
|
||||||
thumbs: List[Thumbnail] = None,
|
thumbs: List[Thumbnail] = None
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
@@ -74,7 +74,7 @@ class Audio(Object):
|
|||||||
date: int = None,
|
date: int = None,
|
||||||
performer: str = None,
|
performer: str = None,
|
||||||
title: str = None,
|
title: str = None,
|
||||||
thumbs: List[Thumbnail] = None,
|
thumbs: List[Thumbnail] = None
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ class Document(Object):
|
|||||||
mime_type: str = None,
|
mime_type: str = None,
|
||||||
file_size: int = None,
|
file_size: int = None,
|
||||||
date: int = None,
|
date: int = None,
|
||||||
thumbs: List[Thumbnail] = None,
|
thumbs: List[Thumbnail] = None
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ class StrippedThumbnail(Object):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
client: "pyrogram.BaseClient" = None,
|
client: "pyrogram.BaseClient" = None,
|
||||||
data: bytes,
|
data: bytes
|
||||||
):
|
):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user