Merge branch 'develop' into asyncio

# Conflicts:
#	pyrogram/client/ext/utils.py
#	pyrogram/client/methods/messages/get_messages.py
This commit is contained in:
Dan 2018-10-28 19:53:45 +01:00
commit 2e53129c0c
8 changed files with 55 additions and 50 deletions

View File

@ -118,7 +118,8 @@ class BaseClient:
def get_messages( def get_messages(
self, self,
chat_id: int or str, chat_id: int or str,
message_ids, message_ids: int or list = None,
reply_to_message_ids: int or list = None,
replies: int = 1 replies: int = 1
): ):
pass pass

View File

@ -7849,8 +7849,3 @@ class Emoji:
REVERSED_THUMBS_UP_SIGN_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f592\U0001f3ff" REVERSED_THUMBS_UP_SIGN_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f592\U0001f3ff"
LEFT_WRITING_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f58e\U0001f3ff" LEFT_WRITING_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f58e\U0001f3ff"
REVERSED_VICTORY_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f594\U0001f3ff" REVERSED_VICTORY_HAND_EMOJI_MODIFIER_FITZPATRICK_TYPE_6 = "\U0001f594\U0001f3ff"
with open("suca.txt", "w") as f:
for k, v in Emoji.__dict__.items():
if not k.startswith("__"):
f.write("{},{}\n".format(k, v))

View File

@ -650,7 +650,8 @@ async def parse_messages(
while True: while True:
try: try:
m.reply_to_message = await client.get_messages( m.reply_to_message = await client.get_messages(
m.chat.id, message.reply_to_msg_id, m.chat.id,
reply_to_message_ids=message.id,
replies=replies - 1 replies=replies - 1
) )
except FloodWait as e: except FloodWait as e:
@ -762,7 +763,8 @@ async def parse_messages(
while True: while True:
try: try:
m.pinned_message = await client.get_messages( m.pinned_message = await client.get_messages(
m.chat.id, message.reply_to_msg_id, m.chat.id,
reply_to_message_ids=message.id,
replies=0 replies=0
) )
except FloodWait as e: except FloodWait as e:
@ -960,7 +962,7 @@ async def parse_chat_full(
if full_chat.pinned_msg_id: if full_chat.pinned_msg_id:
parsed_chat.pinned_message = await client.get_messages( parsed_chat.pinned_message = await client.get_messages(
parsed_chat.id, parsed_chat.id,
full_chat.pinned_msg_id message_ids=full_chat.pinned_msg_id
) )
if isinstance(full_chat.exported_invite, types.ChatInviteExported): if isinstance(full_chat.exported_invite, types.ChatInviteExported):

View File

@ -183,6 +183,7 @@ class Filters:
prefix (``str`` | ``list``, *optional*): prefix (``str`` | ``list``, *optional*):
A prefix or a list of prefixes as string the filter should look for. A prefix or a list of prefixes as string the filter should look for.
Defaults to "/" (slash). Examples: ".", "!", ["/", "!", "."]. Defaults to "/" (slash). Examples: ".", "!", ["/", "!", "."].
Can be None or "" (empty string) to allow commands with no prefix at all.
separator (``str``, *optional*): separator (``str``, *optional*):
The command arguments separator. Defaults to " " (white space). The command arguments separator. Defaults to " " (white space).
@ -214,7 +215,7 @@ class Filters:
else {c if case_sensitive else {c if case_sensitive
else c.lower() else c.lower()
for c in command}, for c in command},
p=set(prefix), p=set(prefix) if prefix else {""},
s=separator, s=separator,
cs=case_sensitive cs=case_sensitive
) )

View File

@ -23,9 +23,10 @@ from ...ext import BaseClient, utils
class GetMessages(BaseClient): class GetMessages(BaseClient):
async def get_messages(self, async def get_messages(self,
chat_id: int or str, chat_id: int or str,
message_ids, message_ids: int or list = None,
reply_to_message_ids: int or list = None,
replies: int = 1): replies: int = 1):
"""Use this method to get messages that belong to a specific chat. """Use this method to get one or more messages that belong to a specific chat.
You can retrieve up to 200 messages at once. You can retrieve up to 200 messages at once.
Args: Args:
@ -34,36 +35,46 @@ class GetMessages(BaseClient):
For your personal cloud (Saved Messages) you can simply use "me" or "self". For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str). For a contact that exists in your Telegram address book you can use his phone number (str).
message_ids (``iterable``): message_ids (``iterable``, *optional*):
A list of Message identifiers in the chat specified in *chat_id* or a single message id, as integer. Pass a single message identifier or a list of message ids (as integers) to get the content of the
Iterators and Generators are also accepted. message themselves. Iterators and Generators are also accepted.
reply_to_message_ids (``iterable``, *optional*):
Pass a single message identifier or a list of message ids (as integers) to get the content of
the previous message you replied to using this message. Iterators and Generators are also accepted.
If *message_ids* is set, this argument will be ignored.
replies (``int``, *optional*): replies (``int``, *optional*):
The number of subsequent replies to get for each message. Defaults to 1. The number of subsequent replies to get for each message. Defaults to 1.
Returns: Returns:
On success and in case *message_ids* was a list, the returned value will be a list of the requested On success and in case *message_ids* or *reply_to_message_ids* was a list, the returned value will be a
:obj:`Messages <pyrogram.Messages>` even if a list contains just one element, otherwise if list of the requested :obj:`Messages <pyrogram.Messages>` even if a list contains just one element,
*message_ids* was an integer, the single requested :obj:`Message <pyrogram.Message>` otherwise if *message_ids* or *reply_to_message_ids* was an integer, the single requested
is returned. :obj:`Message <pyrogram.Message>` is returned.
Raises: Raises:
:class:`Error <pyrogram.Error>` :class:`Error <pyrogram.Error>`
""" """
ids, ids_type = (
(message_ids, types.InputMessageID) if message_ids
else (reply_to_message_ids, types.InputMessageReplyTo) if reply_to_message_ids
else (None, None)
)
if ids is None:
raise ValueError("No argument supplied")
peer = await self.resolve_peer(chat_id) peer = await self.resolve_peer(chat_id)
is_iterable = not isinstance(message_ids, int)
message_ids = list(message_ids) if is_iterable else [message_ids] is_iterable = not isinstance(ids, int)
message_ids = [types.InputMessageID(i) for i in message_ids] ids = list(ids) if is_iterable else [ids]
ids = [ids_type(i) for i in ids]
if isinstance(peer, types.InputPeerChannel): if isinstance(peer, types.InputPeerChannel):
rpc = functions.channels.GetMessages( rpc = functions.channels.GetMessages(channel=peer, id=ids)
channel=peer,
id=message_ids
)
else: else:
rpc = functions.messages.GetMessages( rpc = functions.messages.GetMessages(id=ids)
id=message_ids
)
r = await self.send(rpc) r = await self.send(rpc)

View File

@ -83,9 +83,6 @@ class Message(Object):
document (:obj:`Document <pyrogram.Document>`, *optional*): document (:obj:`Document <pyrogram.Document>`, *optional*):
Message is a general file, information about the file. Message is a general file, information about the file.
game (:obj:`Game <pyrogram.Game>`, *optional*):
Message is a game, information about the game. More about games.
photo (:obj:`Photo <pyrogram.Photo>`, *optional*): photo (:obj:`Photo <pyrogram.Photo>`, *optional*):
Message is a photo, information about the photo. Message is a photo, information about the photo.
@ -225,7 +222,6 @@ class Message(Object):
caption_entities: list = None, caption_entities: list = None,
audio=None, audio=None,
document=None, document=None,
game=None,
photo=None, photo=None,
sticker=None, sticker=None,
animation=None, animation=None,
@ -276,7 +272,6 @@ class Message(Object):
self.caption_entities = caption_entities # flags.12?Vector<MessageEntity> self.caption_entities = caption_entities # flags.12?Vector<MessageEntity>
self.audio = audio # flags.13?Audio self.audio = audio # flags.13?Audio
self.document = document # flags.14?Document self.document = document # flags.14?Document
self.game = game # flags.15?Game
self.photo = photo # flags.16?Vector<PhotoSize> self.photo = photo # flags.16?Vector<PhotoSize>
self.sticker = sticker # flags.17?Sticker self.sticker = sticker # flags.17?Sticker
self.animation = animation self.animation = animation

View File

@ -41,12 +41,12 @@ class User(Object):
is_bot (``bool``): is_bot (``bool``):
True, if this user is a bot. True, if this user is a bot.
status (:obj:`UserStatus <pyrogram.UserStatus>`):
User's Last Seen status. Empty for bots.
first_name (``str``): first_name (``str``):
User's or bot's first name. User's or bot's first name.
status (:obj:`UserStatus <pyrogram.UserStatus>`, *optional*):
User's Last Seen status. Empty for bots.
last_name (``str``, *optional*): last_name (``str``, *optional*):
User's or bot's last name. User's or bot's last name.
@ -76,8 +76,8 @@ class User(Object):
is_mutual_contact: bool, is_mutual_contact: bool,
is_deleted: bool, is_deleted: bool,
is_bot: bool, is_bot: bool,
status,
first_name: str, first_name: str,
status=None,
last_name: str = None, last_name: str = None,
username: str = None, username: str = None,
language_code: str = None, language_code: str = None,
@ -91,8 +91,8 @@ class User(Object):
self.is_mutual_contact = is_mutual_contact self.is_mutual_contact = is_mutual_contact
self.is_deleted = is_deleted self.is_deleted = is_deleted
self.is_bot = is_bot self.is_bot = is_bot
self.status = status
self.first_name = first_name self.first_name = first_name
self.status = status
self.last_name = last_name self.last_name = last_name
self.username = username self.username = username
self.language_code = language_code self.language_code = language_code

View File

@ -28,35 +28,35 @@ class UserStatus(Object):
"recently", "within_week", "within_month" or "long_time_ago" fields set. "recently", "within_week", "within_month" or "long_time_ago" fields set.
Args: Args:
user_id (``int``): user_id (``int``, *optional*):
User's id. Only available for UserStatus updates. User's id. Only available for incoming UserStatus updates.
online (``bool``): online (``bool``, *optional*):
True if the user is online in this moment, None otherwise. True if the user is online in this very moment, None otherwise.
If True, the "date" field will be also set containing the online expiration date (i.e.: the date when a If True, the "date" field will be also set containing the online expiration date (i.e.: the date when a
user will automatically go offline in case of no action by his client). user will automatically go offline in case of no action by his client).
offline (``bool``): offline (``bool``, *optional*):
True if the user is offline and has the Last Seen privacy setting visible for everybody, None otherwise. True if the user is offline in this moment and has the Last Seen privacy setting public, None otherwise.
If True, the "date" field will be also set containing the last seen date (i.e.: the date when a user If True, the "date" field will be also set containing the last seen date (i.e.: the date when a user
was online the last time). was online the last time).
date (``int``): date (``int``, *optional*):
Exact date in unix time. Available only in case "online" or "offline" equals to True. Exact date in unix time. Available only in case "online" or "offline" equals to True.
recently (``bool``): recently (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 1 second and 2-3 days ago, True for users with hidden Last Seen privacy that have been online between 1 second and 2-3 days ago,
None otherwise. None otherwise.
within_week (``bool``): within_week (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 2-3 and seven days ago, True for users with hidden Last Seen privacy that have been online between 2-3 and seven days ago,
None otherwise. None otherwise.
within_month (``bool``): within_month (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online between 6-7 days and a month ago, True for users with hidden Last Seen privacy that have been online between 6-7 days and a month ago,
None otherwise. None otherwise.
long_time_ago (``bool``): long_time_ago (``bool``, *optional*):
True for users with hidden Last Seen privacy that have been online more than a month ago (this is also True for users with hidden Last Seen privacy that have been online more than a month ago (this is also
always shown to blocked users), None otherwise. always shown to blocked users), None otherwise.
""" """