mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
add min & max id support
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
367be6f6eb
commit
dab2ab311b
1 changed files with 23 additions and 10 deletions
|
|
@ -1,20 +1,21 @@
|
|||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
# This file is part of Pyrofork.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# Pyrofork is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# Pyrofork is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Union, Optional, AsyncGenerator
|
||||
|
|
@ -30,7 +31,9 @@ async def get_chunk(
|
|||
limit: int = 0,
|
||||
offset: int = 0,
|
||||
from_message_id: int = 0,
|
||||
from_date: datetime = utils.zero_datetime()
|
||||
from_date: datetime = utils.zero_datetime(),
|
||||
min_id: int = 0,
|
||||
max_id: int = 0
|
||||
):
|
||||
messages = await client.invoke(
|
||||
raw.functions.messages.GetHistory(
|
||||
|
|
@ -39,8 +42,8 @@ async def get_chunk(
|
|||
offset_date=utils.datetime_to_timestamp(from_date),
|
||||
add_offset=offset,
|
||||
limit=limit,
|
||||
max_id=0,
|
||||
min_id=0,
|
||||
max_id=max_id,
|
||||
min_id=min_id,
|
||||
hash=0
|
||||
),
|
||||
sleep_threshold=60
|
||||
|
|
@ -56,7 +59,9 @@ class GetChatHistory:
|
|||
limit: int = 0,
|
||||
offset: int = 0,
|
||||
offset_id: int = 0,
|
||||
offset_date: datetime = utils.zero_datetime()
|
||||
offset_date: datetime = utils.zero_datetime(),
|
||||
min_id: int = 0,
|
||||
max_id: int = 0
|
||||
) -> Optional[AsyncGenerator["types.Message", None]]:
|
||||
"""Get messages from a chat history.
|
||||
|
||||
|
|
@ -84,6 +89,12 @@ class GetChatHistory:
|
|||
offset_date (:py:obj:`~datetime.datetime`, *optional*):
|
||||
Pass a date as offset to retrieve only older messages starting from that date.
|
||||
|
||||
min_id: (``int``, *optional*):
|
||||
The minimum message id. you will not get any message which have id smaller than min_id.
|
||||
|
||||
max_id: (``int``, *optional*):
|
||||
The maximum message id. you will not get any message which have id greater than max_id.
|
||||
|
||||
Returns:
|
||||
``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects.
|
||||
|
||||
|
|
@ -104,7 +115,9 @@ class GetChatHistory:
|
|||
limit=limit,
|
||||
offset=offset,
|
||||
from_message_id=offset_id,
|
||||
from_date=offset_date
|
||||
from_date=offset_date,
|
||||
min_id=min_id,
|
||||
max_id=max_id
|
||||
)
|
||||
|
||||
if not messages:
|
||||
|
|
|
|||
Loading…
Reference in a new issue