Except TypeError on empty access hash from 5018879 thoroughly

This commit is contained in:
Lonami Exo 2018-12-18 08:39:36 +01:00
parent 6839bfcc2d
commit 09f994c105
3 changed files with 19 additions and 14 deletions

View File

@ -150,9 +150,9 @@ class EventCommon(ChatGetter, abc.ABC):
if not self._chat:
return
self._input_chat = utils.get_input_peer(self._chat)
if not getattr(self._input_chat, 'access_hash', True):
# getattr with True to handle the InputPeerSelf() case
try:
self._input_chat = utils.get_input_peer(self._chat)
except TypeError:
try:
self._input_chat = self._client.session.get_input_entity(
self._chat_peer

View File

@ -30,8 +30,11 @@ class Forward(ChatGetter, SenderGetter):
self._sender_id = original.from_id
self._sender = entities.get(original.from_id)
self._input_sender =\
utils.get_input_peer(self._sender) if self._sender else None
try:
self._input_sender =\
utils.get_input_peer(self._sender) if self._sender else None
except TypeError:
self._input_sender = None
self._broadcast = None
if original.channel_id:
@ -41,7 +44,10 @@ class Forward(ChatGetter, SenderGetter):
self._chat_peer = None
self._chat = None
self._input_chat = \
utils.get_input_peer(self._chat) if self._chat else None
try:
self._input_chat = \
utils.get_input_peer(self._chat) if self._chat else None
except TypeError:
self._input_chat = None
# TODO We could reload the message

View File

@ -204,18 +204,17 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
self._client = client
self._sender = entities.get(self._sender_id)
if self._sender:
self._input_sender = utils.get_input_peer(self._sender)
if not getattr(self._input_sender, 'access_hash', True):
try:
self._input_sender = utils.get_input_peer(self._sender)
except TypeError:
self._input_sender = None
self._chat = entities.get(self.chat_id)
self._input_chat = input_chat
if not self._input_chat and self._chat:
self._input_chat = utils.get_input_peer(self._chat)
if not getattr(self._input_chat, 'access_hash', True):
# Telegram may omit the hash in updates -> invalid peer
# However things like InputPeerSelf() or InputPeerChat(id)
# are still valid so default to getting "True" on not found
try:
self._input_chat = utils.get_input_peer(self._chat)
except TypeError:
self._input_chat = None
if self.fwd_from: