From a1b22e0911181570abee528f6141a04516c8dca8 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 28 May 2018 18:25:01 +0200 Subject: [PATCH] Support incoming=False to indicate outgoing=True --- telethon/events/newmessage.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/telethon/events/newmessage.py b/telethon/events/newmessage.py index ec0133e6..082c9737 100644 --- a/telethon/events/newmessage.py +++ b/telethon/events/newmessage.py @@ -28,8 +28,16 @@ class NewMessage(EventBuilder): """ def __init__(self, incoming=None, outgoing=None, chats=None, blacklist_chats=False, pattern=None): + if incoming is not None and outgoing is None: + outgoing = not incoming + elif outgoing is not None and incoming is None: + incoming = not incoming + if incoming and outgoing: - raise ValueError('Can only set either incoming or outgoing') + self.incoming = self.outgoing = None # Same as no filter + elif all(x is not None and not x for x in (incoming, outgoing)): + raise ValueError("Don't create an event handler if you " + "don't want neither incoming or outgoing!") super().__init__(chats=chats, blacklist_chats=blacklist_chats) self.incoming = incoming