forked from kate/uniborg
Add await_event
This commit is contained in:
parent
3f39e88394
commit
1ec12184fe
|
@ -75,3 +75,16 @@ class Uniborg(TelegramClient):
|
||||||
|
|
||||||
del self._plugins[shortname]
|
del self._plugins[shortname]
|
||||||
self._logger.info(f"Removed plugin {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
|
||||||
|
|
Loading…
Reference in New Issue