Update iter_ usages with get_

This commit is contained in:
Lonami Exo 2022-02-04 13:09:57 +01:00
parent 3b12cc3e51
commit ae43a47602
8 changed files with 30 additions and 30 deletions

View File

@ -32,7 +32,7 @@ use these if possible.
print(me.phone) print(me.phone)
# You can print all the dialogs/conversations that you are part of: # You can print all the dialogs/conversations that you are part of:
async for dialog in client.iter_dialogs(): async for dialog in client.get_dialogs():
print(dialog.name, 'has ID', dialog.id) print(dialog.name, 'has ID', dialog.id)
# You can send messages to yourself... # You can send messages to yourself...
@ -62,7 +62,7 @@ use these if possible.
await client.send_file('me', '/home/me/Pictures/holidays.jpg') await client.send_file('me', '/home/me/Pictures/holidays.jpg')
# You can print the message history of any chat: # You can print the message history of any chat:
async for message in client.iter_messages('me'): async for message in client.get_messages('me'):
print(message.id, message.text) print(message.id, message.text)
# You can download media from messages, too! # You can download media from messages, too!

View File

@ -75,7 +75,7 @@ loops or use ``async with``:
async with client: async with client:
# ^ this is an asynchronous with block # ^ this is an asynchronous with block
async for message in client.iter_messages(chat): async for message in client.get_messages(chat):
# ^ this is a for loop over an asynchronous generator # ^ this is a for loop over an asynchronous generator
print(message.sender.username) print(message.sender.username)

View File

@ -28,7 +28,7 @@ In short, you should do this:
buttons = await event.get_buttons() buttons = await event.get_buttons()
async def main(): async def main():
async for message in client.iter_messages('me', 10): async for message in client.get_messages('me', 10):
# Methods from the client always have these properties ready # Methods from the client always have these properties ready
chat = message.input_chat chat = message.input_chat
sender = message.sender sender = message.sender

View File

@ -159,8 +159,8 @@ AdminLogEvent
============= =============
The `AdminLogEvent <telethon.tl.custom.adminlogevent.AdminLogEvent>` object The `AdminLogEvent <telethon.tl.custom.adminlogevent.AdminLogEvent>` object
is returned by the `client.iter_admin_log() is returned by the `client.get_admin_log()
<telethon.client.chats.ChatMethods.iter_admin_log>` method to easily iterate <telethon.client.chats.ChatMethods.get_admin_log>` method to easily iterate
over past "events" (deleted messages, edits, title changes, leaving members…) over past "events" (deleted messages, edits, title changes, leaving members…)
These are all the properties you can find in it: These are all the properties you can find in it:
@ -270,7 +270,7 @@ Dialog
====== ======
The `Dialog <telethon.tl.custom.dialog.Dialog>` object is returned when The `Dialog <telethon.tl.custom.dialog.Dialog>` object is returned when
you call `client.iter_dialogs() <telethon.client.dialogs.DialogMethods.iter_dialogs>`. you call `client.get_dialogs() <telethon.client.dialogs.DialogMethods.get_dialogs>`.
.. currentmodule:: telethon.tl.custom.dialog.Dialog .. currentmodule:: telethon.tl.custom.dialog.Dialog
@ -286,7 +286,7 @@ Draft
====== ======
The `Draft <telethon.tl.custom.draft.Draft>` object is returned when The `Draft <telethon.tl.custom.draft.Draft>` object is returned when
you call `client.iter_drafts() <telethon.client.dialogs.DialogMethods.iter_drafts>`. you call `client.get_drafts() <telethon.client.dialogs.DialogMethods.get_drafts>`.
.. currentmodule:: telethon.tl.custom.draft.Draft .. currentmodule:: telethon.tl.custom.draft.Draft

View File

@ -140,7 +140,7 @@ class _MessagesIter(requestiter.RequestIter):
# trigger `RPC_CALL_FAIL` which is "internal issues"... # trigger `RPC_CALL_FAIL` which is "internal issues"...
if not isinstance(filter, _tl.InputMessagesFilterEmpty) \ if not isinstance(filter, _tl.InputMessagesFilterEmpty) \
and offset_date and not search and not offset_id: and offset_date and not search and not offset_id:
async for m in self.client.iter_messages( async for m in self.client.get_messages(
self.entity, 1, offset_date=offset_date): self.entity, 1, offset_date=offset_date):
self.request.offset_id = m.id + 1 self.request.offset_id = m.id + 1
else: else:

View File

@ -190,7 +190,7 @@ class TelegramClient:
.. code-block:: python .. code-block:: python
async with client.takeout(): async with client.takeout():
async for message in client.iter_messages(chat, wait_time=0): async for message in client.get_messages(chat, wait_time=0):
... # Do something with the message ... # Do something with the message
""" """
@ -214,8 +214,8 @@ class TelegramClient:
flood limits. This is useful if you want to export the data from flood limits. This is useful if you want to export the data from
conversations or mass-download media, since the rate limits will conversations or mass-download media, since the rate limits will
be lower. Only some requests will be affected, and you will need be lower. Only some requests will be affected, and you will need
to adjust the `wait_time` of methods like `client.iter_messages to adjust the `wait_time` of methods like `client.get_messages
<telethon.client.messages.MessageMethods.iter_messages>`. <telethon.client.messages.MessageMethods.get_messages>`.
By default, all parameters are `None`, and you need to enable those By default, all parameters are `None`, and you need to enable those
you plan to use by setting them to either `True` or `False`. you plan to use by setting them to either `True` or `False`.
@ -272,7 +272,7 @@ class TelegramClient:
await client.get_messages('me') # wrapped through takeout (less limits) await client.get_messages('me') # wrapped through takeout (less limits)
async for message in client.iter_messages(chat, wait_time=0): async for message in client.get_messages(chat, wait_time=0):
... # Do something with the message ... # Do something with the message
await client.end_takeout(success=True) await client.end_takeout(success=True)
@ -751,16 +751,16 @@ class TelegramClient:
.. code-block:: python .. code-block:: python
# Show all user IDs in a chat # Show all user IDs in a chat
async for user in client.iter_participants(chat): async for user in client.get_participants(chat):
print(user.id) print(user.id)
# Search by name # Search by name
async for user in client.iter_participants(chat, search='name'): async for user in client.get_participants(chat, search='name'):
print(user.username) print(user.username)
# Filter by admins # Filter by admins
from telethon.tl.types import ChannelParticipantsAdmins from telethon.tl.types import ChannelParticipantsAdmins
async for user in client.iter_participants(chat, filter=ChannelParticipantsAdmins): async for user in client.get_participants(chat, filter=ChannelParticipantsAdmins):
print(user.first_name) print(user.first_name)
# Get a list of 0 people but print the total amount of participants in the chat # Get a list of 0 people but print the total amount of participants in the chat
@ -892,7 +892,7 @@ class TelegramClient:
Example Example
.. code-block:: python .. code-block:: python
async for event in client.iter_admin_log(channel): async for event in client.get_admin_log(channel):
if event.changed_title: if event.changed_title:
print('The title changed from', event.old, 'to', event.new) print('The title changed from', event.old, 'to', event.new)
@ -943,7 +943,7 @@ class TelegramClient:
.. code-block:: python .. code-block:: python
# Download all the profile photos of some user # Download all the profile photos of some user
async for photo in client.iter_profile_photos(user): async for photo in client.get_profile_photos(user):
await client.download_media(photo) await client.download_media(photo)
# Get all the photos of a channel and download the oldest one # Get all the photos of a channel and download the oldest one
@ -1456,7 +1456,7 @@ class TelegramClient:
.. code-block:: python .. code-block:: python
# Print all dialog IDs and the title, nicely formatted # Print all dialog IDs and the title, nicely formatted
async for dialog in client.iter_dialogs(): async for dialog in client.get_dialogs():
print('{:>14}: {}'.format(dialog.id, dialog.title)) print('{:>14}: {}'.format(dialog.id, dialog.title))
# Get all open conversation, print the title of the first # Get all open conversation, print the title of the first
@ -1502,7 +1502,7 @@ class TelegramClient:
await draft.delete() await draft.delete()
# Getting the drafts with 'bot1' and 'bot2' # Getting the drafts with 'bot1' and 'bot2'
async for draft in client.iter_drafts(['bot1', 'bot2']): async for draft in client.get_drafts(['bot1', 'bot2']):
print(draft.text) print(draft.text)
# Get the draft in your chat # Get the draft in your chat
@ -1998,28 +1998,28 @@ class TelegramClient:
.. code-block:: python .. code-block:: python
# From most-recent to oldest # From most-recent to oldest
async for message in client.iter_messages(chat): async for message in client.get_messages(chat):
print(message.id, message.text) print(message.id, message.text)
# From oldest to most-recent # From oldest to most-recent
async for message in client.iter_messages(chat, reverse=True): async for message in client.get_messages(chat, reverse=True):
print(message.id, message.text) print(message.id, message.text)
# Filter by sender, and limit to 10 # Filter by sender, and limit to 10
async for message in client.iter_messages(chat, 10, from_user='me'): async for message in client.get_messages(chat, 10, from_user='me'):
print(message.text) print(message.text)
# Server-side search with fuzzy text # Server-side search with fuzzy text
async for message in client.iter_messages(chat, search='hello'): async for message in client.get_messages(chat, search='hello'):
print(message.id) print(message.id)
# Filter by message type: # Filter by message type:
from telethon.tl.types import InputMessagesFilterPhotos from telethon.tl.types import InputMessagesFilterPhotos
async for message in client.iter_messages(chat, filter=InputMessagesFilterPhotos): async for message in client.get_messages(chat, filter=InputMessagesFilterPhotos):
print(message.photo) print(message.photo)
# Getting comments from a post in a channel: # Getting comments from a post in a channel:
async for message in client.iter_messages(channel, reply_to=123): async for message in client.get_messages(channel, reply_to=123):
print(message.chat.title, message.text) print(message.chat.title, message.text)
# Get 0 photos and print the total to show how many photos there are # Get 0 photos and print the total to show how many photos there are
@ -3337,12 +3337,12 @@ class TelegramClient:
print(utils.get_display_name(me)) print(utils.get_display_name(me))
chat = await client.get_input_entity('username') chat = await client.get_input_entity('username')
async for message in client.iter_messages(chat): async for message in client.get_messages(chat):
... ...
# Note that you could have used the username directly, but it's # Note that you could have used the username directly, but it's
# good to use get_input_entity if you will reuse it a lot. # good to use get_input_entity if you will reuse it a lot.
async for message in client.iter_messages('username'): async for message in client.get_messages('username'):
... ...
# Note that for this to work the phone number must be in your contacts # Note that for this to work the phone number must be in your contacts

View File

@ -75,7 +75,7 @@ class ChatGetter(abc.ABC):
try: try:
# The chat may be recent, look in dialogs # The chat may be recent, look in dialogs
target = self.chat_id target = self.chat_id
async for d in self._client.iter_dialogs(100): async for d in self._client.get_dialogs(100):
if d.id == target: if d.id == target:
self._chat = d.entity self._chat = d.entity
self._input_chat = d.input_entity self._input_chat = d.input_entity

View File

@ -119,7 +119,7 @@ async def root():
# They are logged in, show them some messages from their first dialog # They are logged in, show them some messages from their first dialog
dialog = (await client.get_dialogs())[0] dialog = (await client.get_dialogs())[0]
result = '<h1>{}</h1>'.format(dialog.title) result = '<h1>{}</h1>'.format(dialog.title)
async for m in client.iter_messages(dialog, 10): async for m in client.get_messages(dialog, 10):
result += await(format_message(m)) result += await(format_message(m))
return await render_template_string(BASE_TEMPLATE, content=result) return await render_template_string(BASE_TEMPLATE, content=result)