mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-05 00:35:10 +00:00
Merge branch 'develop' into asyncio
# Conflicts: # pyrogram/client/client.py # pyrogram/client/methods/messages/send_media_group.py # pyrogram/client/methods/utilities/download_media.py
This commit is contained in:
@@ -199,10 +199,9 @@ class Client(Methods, BaseClient):
|
||||
self.dispatcher = Dispatcher(self, workers)
|
||||
|
||||
def __enter__(self):
|
||||
self.start()
|
||||
return self
|
||||
return self.start()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
def __exit__(self, *args):
|
||||
self.stop()
|
||||
|
||||
@property
|
||||
@@ -284,6 +283,8 @@ class Client(Methods, BaseClient):
|
||||
|
||||
mimetypes.init()
|
||||
|
||||
return self
|
||||
|
||||
async def stop(self):
|
||||
"""Use this method to manually stop the Client.
|
||||
Requires no parameters.
|
||||
@@ -318,6 +319,8 @@ class Client(Methods, BaseClient):
|
||||
self.is_started = False
|
||||
await self.session.stop()
|
||||
|
||||
return self
|
||||
|
||||
async def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
|
||||
"""Blocks the program execution until one of the signals are received,
|
||||
then gently stop the Client by closing the underlying connection.
|
||||
@@ -439,6 +442,8 @@ class Client(Methods, BaseClient):
|
||||
else:
|
||||
self.user_id = r.user.id
|
||||
|
||||
print("Logged in successfully as @{}".format(r.user.username))
|
||||
|
||||
async def authorize_user(self):
|
||||
phone_number_invalid_raises = self.phone_number is not None
|
||||
phone_code_invalid_raises = self.phone_code is not None
|
||||
@@ -623,7 +628,7 @@ class Client(Methods, BaseClient):
|
||||
self.password = None
|
||||
self.user_id = r.user.id
|
||||
|
||||
print("Login successful")
|
||||
print("Logged in successfully as {}".format(r.user.first_name))
|
||||
|
||||
def fetch_peers(self, entities: list):
|
||||
for entity in entities:
|
||||
@@ -1234,7 +1239,7 @@ class Client(Methods, BaseClient):
|
||||
version: int = 0,
|
||||
size: int = None,
|
||||
progress: callable = None,
|
||||
progress_args: tuple = None) -> str:
|
||||
progress_args: tuple = ()) -> str:
|
||||
with await self.media_sessions_lock:
|
||||
session = self.media_sessions.get(dc_id, None)
|
||||
|
||||
@@ -1316,7 +1321,7 @@ class Client(Methods, BaseClient):
|
||||
offset += limit
|
||||
|
||||
if progress:
|
||||
progress(self, min(offset, size), size, *progress_args)
|
||||
progress(self, min(offset, size) if size != 0 else offset, size, *progress_args)
|
||||
|
||||
r = await session.send(
|
||||
functions.upload.GetFile(
|
||||
@@ -1398,7 +1403,7 @@ class Client(Methods, BaseClient):
|
||||
offset += limit
|
||||
|
||||
if progress:
|
||||
progress(self, min(offset, size), size, *progress_args)
|
||||
progress(self, min(offset, size) if size != 0 else offset, size, *progress_args)
|
||||
|
||||
if len(chunk) < limit:
|
||||
break
|
||||
|
@@ -338,6 +338,7 @@ async def parse_messages(
|
||||
video_note = None
|
||||
sticker = None
|
||||
document = None
|
||||
web_page = None
|
||||
|
||||
media = message.media
|
||||
|
||||
@@ -585,6 +586,8 @@ async def parse_messages(
|
||||
file_size=doc.size,
|
||||
date=doc.date
|
||||
)
|
||||
elif isinstance(media, types.MessageMediaWebPage):
|
||||
web_page = True
|
||||
else:
|
||||
media = None
|
||||
|
||||
@@ -632,6 +635,7 @@ async def parse_messages(
|
||||
video_note=video_note,
|
||||
sticker=sticker,
|
||||
document=document,
|
||||
web_page=web_page,
|
||||
views=message.views,
|
||||
via_bot=parse_user(users.get(message.via_bot_id, None)),
|
||||
outgoing=message.out,
|
||||
|
@@ -118,6 +118,9 @@ class Filters:
|
||||
venue = create("Venue", lambda _, m: bool(m.venue))
|
||||
"""Filter messages that contain :obj:`Venue <pyrogram.api.types.pyrogram.Venue>` objects."""
|
||||
|
||||
web_page = create("WebPage", lambda _, m: m.web_page)
|
||||
"""Filter messages sent with a webpage preview."""
|
||||
|
||||
private = create("Private", lambda _, m: bool(m.chat and m.chat.type == "private"))
|
||||
"""Filter messages sent in private chats."""
|
||||
|
||||
@@ -169,6 +172,9 @@ class Filters:
|
||||
mentioned = create("Mentioned", lambda _, m: bool(m.mentioned))
|
||||
"""Filter messages containing mentions"""
|
||||
|
||||
via_bot = create("ViaBot", lambda _, m: bool(m.via_bot))
|
||||
"""Filter messages sent via inline bots"""
|
||||
|
||||
service = create("Service", lambda _, m: bool(m.service))
|
||||
"""Filter service messages. A service message contains any of the following fields set
|
||||
|
||||
|
@@ -27,6 +27,13 @@ class OnCallbackQuery(BaseClient):
|
||||
callback queries. This does the same thing as :meth:`add_handler` using the
|
||||
:class:`CallbackQueryHandler`.
|
||||
|
||||
.. note::
|
||||
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.
|
||||
|
||||
To reference your own function after it has been decorated, you need to access
|
||||
*my_function[0].callback*, that is, the *callback* field of Handler object which is the the
|
||||
first element in the tuple.
|
||||
|
||||
Args:
|
||||
filters (:obj:`Filters <pyrogram.Filters>`):
|
||||
Pass one or more filters to allow only a subset of callback queries to be passed
|
||||
|
@@ -27,6 +27,13 @@ class OnDeletedMessages(BaseClient):
|
||||
deleted messages. This does the same thing as :meth:`add_handler` using the
|
||||
:class:`DeletedMessagesHandler`.
|
||||
|
||||
.. note::
|
||||
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.
|
||||
|
||||
To reference your own function after it has been decorated, you need to access
|
||||
*my_function[0].callback*, that is, the *callback* field of Handler object which is the the
|
||||
first element in the tuple.
|
||||
|
||||
Args:
|
||||
filters (:obj:`Filters <pyrogram.Filters>`):
|
||||
Pass one or more filters to allow only a subset of messages to be passed
|
||||
|
@@ -27,6 +27,13 @@ class OnMessage(BaseClient):
|
||||
messages. This does the same thing as :meth:`add_handler` using the
|
||||
:class:`MessageHandler`.
|
||||
|
||||
.. note::
|
||||
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.
|
||||
|
||||
To reference your own function after it has been decorated, you need to access
|
||||
*my_function[0].callback*, that is, the *callback* field of Handler object which is the the
|
||||
first element in the tuple.
|
||||
|
||||
Args:
|
||||
filters (:obj:`Filters <pyrogram.Filters>`):
|
||||
Pass one or more filters to allow only a subset of messages to be passed
|
||||
|
@@ -26,6 +26,13 @@ class OnRawUpdate(BaseClient):
|
||||
raw updates. This does the same thing as :meth:`add_handler` using the
|
||||
:class:`RawUpdateHandler`.
|
||||
|
||||
.. note::
|
||||
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.
|
||||
|
||||
To reference your own function after it has been decorated, you need to access
|
||||
*my_function[0].callback*, that is, the *callback* field of Handler object which is the the
|
||||
first element in the tuple.
|
||||
|
||||
Args:
|
||||
group (``int``, *optional*):
|
||||
The group identifier, defaults to 0.
|
||||
|
@@ -27,6 +27,13 @@ class OnUserStatus(BaseClient):
|
||||
user status updates. This does the same thing as :meth:`add_handler` using the
|
||||
:class:`UserStatusHandler`.
|
||||
|
||||
.. note::
|
||||
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.
|
||||
|
||||
To reference your own function after it has been decorated, you need to access
|
||||
*my_function[0].callback*, that is, the *callback* field of Handler object which is the the
|
||||
first element in the tuple.
|
||||
|
||||
Args:
|
||||
filters (:obj:`Filters <pyrogram.Filters>`):
|
||||
Pass one or more filters to allow only a subset of UserStatus updated to be passed in your function.
|
||||
|
@@ -108,6 +108,7 @@ class SendMediaGroup(BaseClient):
|
||||
peer=await self.resolve_peer(chat_id),
|
||||
media=types.InputMediaUploadedDocument(
|
||||
file=await self.save_file(i.media),
|
||||
thumb=None if i.thumb is None else self.save_file(i.thumb),
|
||||
mime_type=mimetypes.types_map[".mp4"],
|
||||
attributes=[
|
||||
types.DocumentAttributeVideo(
|
||||
|
@@ -28,7 +28,7 @@ class DownloadMedia(BaseClient):
|
||||
file_name: str = "",
|
||||
block: bool = True,
|
||||
progress: callable = None,
|
||||
progress_args: tuple = None):
|
||||
progress_args: tuple = ()):
|
||||
"""Use this method to download the media from a Message.
|
||||
|
||||
Args:
|
||||
|
@@ -134,6 +134,12 @@ class Message(Object):
|
||||
venue (:obj:`Venue <pyrogram.Venue>`, *optional*):
|
||||
Message is a venue, information about the venue.
|
||||
|
||||
web_page (``bool``, *optional*):
|
||||
Message was sent with a webpage preview.
|
||||
**Note:** Support for web pages is still basic; a simple boolean is set in case the message contains a
|
||||
web page preview. In future versions this property could turn into a full web page object that contains
|
||||
more details.
|
||||
|
||||
new_chat_members (List of :obj:`User <pyrogram.User>`, *optional*):
|
||||
New members that were added to the group or supergroup and information about them
|
||||
(the bot itself may be one of these members).
|
||||
@@ -246,6 +252,7 @@ class Message(Object):
|
||||
contact=None,
|
||||
location=None,
|
||||
venue=None,
|
||||
web_page=None,
|
||||
new_chat_members: list = None,
|
||||
left_chat_member=None,
|
||||
new_chat_title: str = None,
|
||||
@@ -297,6 +304,7 @@ class Message(Object):
|
||||
self.contact = contact # flags.22?Contact
|
||||
self.location = location # flags.23?Location
|
||||
self.venue = venue # flags.24?Venue
|
||||
self.web_page = web_page
|
||||
self.new_chat_members = new_chat_members # flags.25?Vector<User>
|
||||
self.left_chat_member = left_chat_member # flags.26?User
|
||||
self.new_chat_title = new_chat_title # flags.27?string
|
||||
|
Reference in New Issue
Block a user