From 1ec12184fe60def95cda8d2a2569d917ac1ccc9a Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Sun, 8 Apr 2018 15:42:31 +0300 Subject: [PATCH] Add await_event --- uniborg/telethon.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/uniborg/telethon.py b/uniborg/telethon.py index b31080a..9c8a88c 100644 --- a/uniborg/telethon.py +++ b/uniborg/telethon.py @@ -75,3 +75,16 @@ class Uniborg(TelegramClient): del self._plugins[shortname] self._logger.info(f"Removed plugin {shortname}") + + def await_event(self, event_matcher, filter=None): + fut = asyncio.Future() + + @self.on(event_matcher) + async def cb(event): + if filter is None or await filter(event): + fut.set_result(event) + + fut.add_done_callback(lambda _: + self.remove_event_handler(cb, event_matcher)) + + return fut