Add await_event

This commit is contained in:
Dan Elkouby 2018-04-08 15:42:31 +03:00
parent 3f39e88394
commit 1ec12184fe
1 changed files with 13 additions and 0 deletions

View File

@ -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