mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-18 11:06:39 +00:00
Support "string" peers on .get_input_entity
This commit is contained in:
parent
8df4d7c4a5
commit
d30fdbe778
@ -11,7 +11,7 @@ except ImportError:
|
|||||||
socks = None
|
socks = None
|
||||||
|
|
||||||
from . import TelegramBareClient
|
from . import TelegramBareClient
|
||||||
from . import helpers as utils
|
from . import helpers, utils
|
||||||
from .errors import (
|
from .errors import (
|
||||||
RPCError, UnauthorizedError, InvalidParameterError, PhoneCodeEmptyError,
|
RPCError, UnauthorizedError, InvalidParameterError, PhoneCodeEmptyError,
|
||||||
PhoneCodeExpiredError, PhoneCodeHashEmptyError, PhoneCodeInvalidError
|
PhoneCodeExpiredError, PhoneCodeHashEmptyError, PhoneCodeInvalidError
|
||||||
@ -47,7 +47,6 @@ from .tl.types import (
|
|||||||
UpdateNewMessage, UpdateShortSentMessage,
|
UpdateNewMessage, UpdateShortSentMessage,
|
||||||
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel)
|
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel)
|
||||||
from .tl.types.messages import DialogsSlice
|
from .tl.types.messages import DialogsSlice
|
||||||
from .utils import find_user_or_chat, get_extension
|
|
||||||
|
|
||||||
|
|
||||||
class TelegramClient(TelegramBareClient):
|
class TelegramClient(TelegramBareClient):
|
||||||
@ -184,7 +183,7 @@ class TelegramClient(TelegramBareClient):
|
|||||||
elif password:
|
elif password:
|
||||||
salt = self(GetPasswordRequest()).current_salt
|
salt = self(GetPasswordRequest()).current_salt
|
||||||
result = self(CheckPasswordRequest(
|
result = self(CheckPasswordRequest(
|
||||||
utils.get_password_hash(password, salt)
|
helpers.get_password_hash(password, salt)
|
||||||
))
|
))
|
||||||
elif bot_token:
|
elif bot_token:
|
||||||
result = self(ImportBotAuthorizationRequest(
|
result = self(ImportBotAuthorizationRequest(
|
||||||
@ -285,19 +284,20 @@ class TelegramClient(TelegramBareClient):
|
|||||||
break
|
break
|
||||||
|
|
||||||
offset_date = r.messages[-1].date
|
offset_date = r.messages[-1].date
|
||||||
offset_peer = find_user_or_chat(r.dialogs[-1].peer, entities,
|
offset_peer = utils.find_user_or_chat(
|
||||||
entities)
|
r.dialogs[-1].peer, entities, entities
|
||||||
|
)
|
||||||
offset_id = r.messages[-1].id & 4294967296 # Telegram/danog magic
|
offset_id = r.messages[-1].id & 4294967296 # Telegram/danog magic
|
||||||
|
|
||||||
# Sort by message date
|
# Sort by message date
|
||||||
no_date = datetime.fromtimestamp(0)
|
no_date = datetime.fromtimestamp(0)
|
||||||
dialogs = sorted(
|
ds = sorted(
|
||||||
list(dialogs.values()),
|
list(dialogs.values()),
|
||||||
key=lambda d: getattr(messages[d.top_message], 'date', no_date)
|
key=lambda d: getattr(messages[d.top_message], 'date', no_date)
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
dialogs,
|
ds,
|
||||||
[find_user_or_chat(d.peer, entities, entities) for d in dialogs]
|
[utils.find_user_or_chat(d.peer, entities, entities) for d in ds]
|
||||||
)
|
)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
@ -393,10 +393,13 @@ class TelegramClient(TelegramBareClient):
|
|||||||
total_messages = getattr(result, 'count', len(result.messages))
|
total_messages = getattr(result, 'count', len(result.messages))
|
||||||
|
|
||||||
# Iterate over all the messages and find the sender User
|
# Iterate over all the messages and find the sender User
|
||||||
entities = [find_user_or_chat(m.from_id, result.users, result.chats)
|
entities = [
|
||||||
if m.from_id is not None else
|
utils.find_user_or_chat(m.from_id, result.users, result.chats)
|
||||||
find_user_or_chat(m.to_id, result.users, result.chats)
|
if m.from_id is not None else
|
||||||
for m in result.messages]
|
utils.find_user_or_chat(m.to_id, result.users, result.chats)
|
||||||
|
|
||||||
|
for m in result.messages
|
||||||
|
]
|
||||||
|
|
||||||
return total_messages, result.messages, entities
|
return total_messages, result.messages, entities
|
||||||
|
|
||||||
@ -698,7 +701,7 @@ class TelegramClient(TelegramBareClient):
|
|||||||
))
|
))
|
||||||
|
|
||||||
file = self._get_proper_filename(
|
file = self._get_proper_filename(
|
||||||
file, 'document', get_extension(mm_doc),
|
file, 'document', utils.get_extension(mm_doc),
|
||||||
date=date, possible_names=possible_names
|
date=date, possible_names=possible_names
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -895,6 +898,10 @@ class TelegramClient(TelegramBareClient):
|
|||||||
|
|
||||||
If even after
|
If even after
|
||||||
"""
|
"""
|
||||||
|
if isinstance(peer, str):
|
||||||
|
# Let .get_entity resolve the username or phone
|
||||||
|
return utils.get_input_peer(self.get_entity(peer))
|
||||||
|
|
||||||
is_peer = False
|
is_peer = False
|
||||||
if isinstance(peer, int):
|
if isinstance(peer, int):
|
||||||
peer = PeerUser(peer)
|
peer = PeerUser(peer)
|
||||||
|
Loading…
Reference in New Issue
Block a user