mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-27 01:34:29 +03:00
Fix async_generator's and missing awaits
This commit is contained in:
parent
8be6adeab4
commit
f86f52d960
|
@ -179,8 +179,9 @@ class ChatMethods(UserMethods):
|
||||||
"""
|
"""
|
||||||
total = [0]
|
total = [0]
|
||||||
kwargs['_total'] = total
|
kwargs['_total'] = total
|
||||||
participants = UserList(x async for x in
|
participants = UserList()
|
||||||
self.iter_participants(*args, **kwargs))
|
async for x in self.iter_participants(*args, **kwargs):
|
||||||
|
participants.append(x)
|
||||||
participants.total = total[0]
|
participants.total = total[0]
|
||||||
return participants
|
return participants
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ from ..tl import types, functions, custom
|
||||||
|
|
||||||
|
|
||||||
class DialogMethods(UserMethods):
|
class DialogMethods(UserMethods):
|
||||||
|
|
||||||
# region Public methods
|
# region Public methods
|
||||||
|
|
||||||
@async_generator
|
@async_generator
|
||||||
|
@ -103,10 +104,13 @@ class DialogMethods(UserMethods):
|
||||||
"""
|
"""
|
||||||
total = [0]
|
total = [0]
|
||||||
kwargs['_total'] = total
|
kwargs['_total'] = total
|
||||||
dialogs = UserList(x async for x in self.iter_dialogs(*args, **kwargs))
|
dialogs = UserList()
|
||||||
|
async for x in self.iter_dialogs(*args, **kwargs):
|
||||||
|
dialogs.append(x)
|
||||||
dialogs.total = total[0]
|
dialogs.total = total[0]
|
||||||
return dialogs
|
return dialogs
|
||||||
|
|
||||||
|
@async_generator
|
||||||
async def iter_drafts(self): # TODO: Ability to provide a `filter`
|
async def iter_drafts(self): # TODO: Ability to provide a `filter`
|
||||||
"""
|
"""
|
||||||
Iterator over all open draft messages.
|
Iterator over all open draft messages.
|
||||||
|
@ -124,6 +128,9 @@ class DialogMethods(UserMethods):
|
||||||
"""
|
"""
|
||||||
Same as :meth:`iter_drafts`, but returns a list instead.
|
Same as :meth:`iter_drafts`, but returns a list instead.
|
||||||
"""
|
"""
|
||||||
return list(x async for x in self.iter_drafts())
|
result = []
|
||||||
|
async for x in self.iter_drafts():
|
||||||
|
result.append(x)
|
||||||
|
return result
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
|
@ -244,7 +244,9 @@ class MessageMethods(UploadMethods, MessageParseMethods):
|
||||||
else:
|
else:
|
||||||
kwargs['limit'] = 1
|
kwargs['limit'] = 1
|
||||||
|
|
||||||
msgs = UserList(x async for x in self.iter_messages(*args, **kwargs))
|
msgs = UserList()
|
||||||
|
async for x in self.iter_messages(*args, **kwargs):
|
||||||
|
msgs.append(x)
|
||||||
msgs.total = total[0]
|
msgs.total = total[0]
|
||||||
if 'ids' in kwargs and not utils.is_list_like(kwargs['ids']):
|
if 'ids' in kwargs and not utils.is_list_like(kwargs['ids']):
|
||||||
return msgs[0]
|
return msgs[0]
|
||||||
|
|
|
@ -269,24 +269,26 @@ class Message:
|
||||||
return bool(self.original_message.reply_to_msg_id)
|
return bool(self.original_message.reply_to_msg_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def buttons(self):
|
async def buttons(self):
|
||||||
"""
|
"""
|
||||||
Returns a matrix (list of lists) containing all buttons of the message
|
Returns a matrix (list of lists) containing all buttons of the message
|
||||||
as `telethon.tl.custom.messagebutton.MessageButton` instances.
|
as `telethon.tl.custom.messagebutton.MessageButton` instances.
|
||||||
"""
|
"""
|
||||||
if self._buttons is None and self.original_message.reply_markup:
|
if self._buttons is None and self.original_message.reply_markup:
|
||||||
|
sender = await self.input_sender
|
||||||
|
chat = await self.input_chat
|
||||||
if isinstance(self.original_message.reply_markup, (
|
if isinstance(self.original_message.reply_markup, (
|
||||||
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
||||||
self._buttons = [[
|
self._buttons = [[
|
||||||
MessageButton(self._client, button, self.input_sender,
|
MessageButton(self._client, button, sender, chat,
|
||||||
self.input_chat, self.original_message.id)
|
self.original_message.id)
|
||||||
for button in row.buttons
|
for button in row.buttons
|
||||||
] for row in self.original_message.reply_markup.rows]
|
] for row in self.original_message.reply_markup.rows]
|
||||||
self._buttons_flat = [x for row in self._buttons for x in row]
|
self._buttons_flat = [x for row in self._buttons for x in row]
|
||||||
return self._buttons
|
return self._buttons
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def button_count(self):
|
async def button_count(self):
|
||||||
"""
|
"""
|
||||||
Returns the total button count.
|
Returns the total button count.
|
||||||
"""
|
"""
|
||||||
|
@ -398,7 +400,7 @@ class Message:
|
||||||
if not self.original_message.reply_to_msg_id:
|
if not self.original_message.reply_to_msg_id:
|
||||||
return None
|
return None
|
||||||
self._reply_message = await self._client.get_messages(
|
self._reply_message = await self._client.get_messages(
|
||||||
self.input_chat if self.is_channel else None,
|
await self.input_chat if self.is_channel else None,
|
||||||
ids=self.original_message.reply_to_msg_id
|
ids=self.original_message.reply_to_msg_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user