Skip to content

Commit

Permalink
add: support for non-awaitable function
Browse files Browse the repository at this point in the history
  • Loading branch information
Chenwe_i_lin committed Mar 3, 2020
1 parent 0300725 commit 165e7a2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mirai/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,15 @@ async def main_entrance(self, run_body, event_context, queue):
for normal_middleware in normal_middlewares:
SessionLogger.debug(f"a event called {event_context.name}, enter a currect context.")
normal_stack.enter_context(normal_middleware)
return await callable_target(**translated_mapping)
if inspect.iscoroutinefunction(callable_target):
return await callable_target(**translated_mapping)
else:
return callable_target(**translated_mapping)

return await callable_target(**translated_mapping)
if inspect.iscoroutinefunction(callable_target):
return await callable_target(**translated_mapping)
else:
return callable_target(**translated_mapping)
except (NameError, TypeError) as e:
EventLogger.error(f"threw a exception by {event_context.name}, it's about Annotations Checker, please report to developer.")
traceback.print_exc()
Expand Down

0 comments on commit 165e7a2

Please sign in to comment.