Allow event's func to be async (#1461)

Fixes #1344.
This commit is contained in:
JuniorJPDJ
2020-05-16 09:58:37 +02:00
committed by GitHub
parent c45f2e7c39
commit 634bc3a8bd
5 changed files with 33 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
import asyncio
import functools
import inspect
import itertools
import time
@@ -312,9 +313,15 @@ class Conversation(ChatGetter):
for key, (ev, fut) in list(self._custom.items()):
ev_type = type(ev)
inst = built[ev_type]
if inst and ev.filter(inst):
fut.set_result(inst)
del self._custom[key]
if inst:
filter = ev.filter(inst)
if inspect.isawaitable(filter):
filter = await filter
if filter:
fut.set_result(inst)
del self._custom[key]
def _on_new_message(self, response):
response = response.message