mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-26 09:14:31 +03:00
Return None from ChatGetter when there isn't enough info
This commit is contained in:
parent
35ba9848d9
commit
83789aaa42
|
@ -133,7 +133,7 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
"""
|
||||
_event_name = 'Event'
|
||||
|
||||
def __init__(self, chat_peer=None, msg_id=None, broadcast=False):
|
||||
def __init__(self, chat_peer=None, msg_id=None, broadcast=None):
|
||||
super().__init__(chat_peer, broadcast=broadcast)
|
||||
self._entities = {}
|
||||
self._client = None
|
||||
|
|
|
@ -108,23 +108,39 @@ class ChatGetter(abc.ABC):
|
|||
|
||||
@property
|
||||
def is_private(self):
|
||||
"""True if the message was sent as a private message."""
|
||||
return isinstance(self._chat_peer, types.PeerUser)
|
||||
"""
|
||||
``True`` if the message was sent as a private message.
|
||||
|
||||
Returns ``None`` if there isn't enough information
|
||||
(e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
|
||||
"""
|
||||
return isinstance(self._chat_peer, types.PeerUser) if self._chat_peer else None
|
||||
|
||||
@property
|
||||
def is_group(self):
|
||||
"""True if the message was sent on a group or megagroup."""
|
||||
if self._broadcast is None and self.chat:
|
||||
self._broadcast = getattr(self.chat, 'broadcast', None)
|
||||
"""
|
||||
True if the message was sent on a group or megagroup.
|
||||
|
||||
return (
|
||||
isinstance(self._chat_peer, (types.PeerChat, types.PeerChannel))
|
||||
and not self._broadcast
|
||||
)
|
||||
Returns ``None`` if there isn't enough information
|
||||
(e.g. on `events.MessageDeleted <telethon.events.messagedeleted.MessageDeleted>`).
|
||||
"""
|
||||
# TODO Cache could tell us more in the future
|
||||
if self._broadcast is None and hasattr(self.chat, 'broadcast'):
|
||||
self._broadcast = bool(self.chat.broadcast)
|
||||
|
||||
if isinstance(self._chat_peer, types.PeerChannel):
|
||||
if self._broadcast is None:
|
||||
return None
|
||||
else:
|
||||
return not self._broadcast
|
||||
|
||||
return isinstance(self._chat_peer, types.PeerChat)
|
||||
|
||||
@property
|
||||
def is_channel(self):
|
||||
"""True if the message was sent on a megagroup or channel."""
|
||||
"""``True`` if the message was sent on a megagroup or channel."""
|
||||
# The only case where chat peer could be none is in MessageDeleted,
|
||||
# however those always have the peer in channels.
|
||||
return isinstance(self._chat_peer, types.PeerChannel)
|
||||
|
||||
async def _refetch_chat(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user