add __bool__ dunder method to Message

This commit is contained in:
apepenkov 2023-11-10 00:02:11 +03:00
parent 27d6cce8e2
commit 3976988b33

View File

@ -45,6 +45,9 @@ class Message(metaclass=NoPublicConstructor):
You can get a message from :class:`telethon.events.NewMessage`,
or from methods such as :meth:`telethon.Client.get_messages`.
If the message is empty (like when it's not found using :meth:`telethon.Client.get_messages_with_ids`),
its ``__bool__`` method will yield :data:`False`.
"""
def __init__(
@ -482,6 +485,9 @@ class Message(metaclass=NoPublicConstructor):
else:
return False
def __bool__(self):
return not isinstance(self._raw, types.MessageEmpty)
def build_msg_map(
client: Client, messages: List[abcs.Message], chat_map: Dict[int, Chat]