| 8 | from aiohttp import web |
| 9 | |
| 10 | class StreamXBot(Client): |
| 11 | |
| 12 | def __init__(self): |
| 13 | super().__init__( |
| 14 | name="vjfiletolink", |
| 15 | api_id=API_ID, |
| 16 | api_hash=API_HASH, |
| 17 | bot_token=BOT_TOKEN, |
| 18 | workers=150, |
| 19 | plugins={"root": "plugins"}, |
| 20 | sleep_threshold=5, |
| 21 | ) |
| 22 | async def iter_messages( |
| 23 | self, |
| 24 | chat_id: Union[int, str], |
| 25 | limit: int, |
| 26 | offset: int = 0, |
| 27 | ) -> Optional[AsyncGenerator["types.Message", None]]: |
| 28 | """Iterate through a chat sequentially. |
| 29 | This convenience method does the same as repeatedly calling :meth:`~pyrogram.Client.get_messages` in a loop, thus saving |
| 30 | you from the hassle of setting up boilerplate code. It is useful for getting the whole chat messages with a |
| 31 | single call. |
| 32 | Parameters: |
| 33 | chat_id (``int`` | ``str``): |
| 34 | Unique identifier (int) or username (str) of the target chat. |
| 35 | For your personal cloud (Saved Messages) you can simply use "me" or "self". |
| 36 | For a contact that exists in your Telegram address book you can use his phone number (str). |
| 37 | |
| 38 | limit (``int``): |
| 39 | Identifier of the last message to be returned. |
| 40 | |
| 41 | offset (``int``, *optional*): |
| 42 | Identifier of the first message to be returned. |
| 43 | Defaults to 0. |
| 44 | Returns: |
| 45 | ``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects. |
| 46 | Example: |
| 47 | .. code-block:: python |
| 48 | for message in app.iter_messages("pyrogram", 1, 15000): |
| 49 | print(message.text) |
| 50 | """ |
| 51 | current = offset |
| 52 | while True: |
| 53 | new_diff = min(200, limit - current) |
| 54 | if new_diff <= 0: |
| 55 | return |
| 56 | messages = await self.get_messages(chat_id, list(range(current, current+new_diff+1))) |
| 57 | for message in messages: |
| 58 | yield message |
| 59 | current += 1 |
| 60 | |
| 61 | StreamBot = StreamXBot() |
| 62 | |