mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-10 10:49:39 +00:00
Added native support for Python's datetime object
Now you can make up your Telegram Requests by using the built-in `datetime` instead of manually parsing it
This commit is contained in:
@@ -148,10 +148,10 @@ class TelegramClient:
|
||||
def get_dialogs(self, count=10, offset_date=None, offset_id=0, offset_peer=InputPeerEmpty()):
|
||||
"""Returns a tuple of lists ([dialogs], [displays], [input_peers]) with 'count' items each"""
|
||||
|
||||
r = self.invoke(GetDialogsRequest(offset_date=TelegramClient.get_tg_date(offset_date),
|
||||
offset_id=offset_id,
|
||||
offset_peer=offset_peer,
|
||||
limit=count))
|
||||
r = self.invoke(GetDialogsRequest(offset_date=offset_date,
|
||||
offset_id=offset_id,
|
||||
offset_peer=offset_peer,
|
||||
limit=count))
|
||||
|
||||
return (r.dialogs,
|
||||
[self.find_display_name(d.peer, r.users, r.chats) for d in r.dialogs],
|
||||
@@ -188,7 +188,7 @@ class TelegramClient:
|
||||
"""
|
||||
result = self.invoke(GetHistoryRequest(input_peer,
|
||||
limit=limit,
|
||||
offset_date=self.get_tg_date(offset_date),
|
||||
offset_date=offset_date,
|
||||
offset_id=offset_id,
|
||||
max_id=max_id,
|
||||
min_id=min_id,
|
||||
@@ -198,7 +198,7 @@ class TelegramClient:
|
||||
# simply a messages TLObject. In the later case, no "count" attribute is specified:
|
||||
# the total messages count is retrieved by counting all the retrieved messages
|
||||
total_messages = getattr(result, 'count', len(result.messages))
|
||||
|
||||
|
||||
return (total_messages,
|
||||
result.messages,
|
||||
[usr # Create a list with the users...
|
||||
@@ -220,11 +220,6 @@ class TelegramClient:
|
||||
|
||||
# region Utilities
|
||||
|
||||
@staticmethod
|
||||
def get_tg_date(datetime):
|
||||
"""Parses a datetime Python object to Telegram's required integer Unix timestamp"""
|
||||
return 0 if datetime is None else int(datetime.timestamp())
|
||||
|
||||
@staticmethod
|
||||
def find_display_name(peer, users, chats):
|
||||
"""Searches the display name for peer in both users and chats.
|
||||
|
Reference in New Issue
Block a user