コード例 #1
0
    def deco(func: Callable):
        @wraps(func)
        async def wrapped_function(session: NLPSession):
            cls = get_class_that_defined_method(func)
            if not cls:
                raise Exception('cannot resolve class from method')
            return await func(cls(session))

        return on_natural_language(**func_get_args)(wrapped_function)
コード例 #2
0
 def deco(func) -> Callable:
     @wraps(func)
     async def wrapper(session:nonebot.NLPSession):
         if self._check_all(session.ctx):
             try:
                 await func(session)
                 self.logger.info(f'Message {session.ctx["message_id"]} is handled as natural language by {func.__name__}.')
             except Exception as e:
                 self.logger.exception(e)
                 self.logger.error(f'{type(e)} occured when {func.__name__} handling message {session.ctx["message_id"]}.')
             return
     return nonebot.on_natural_language(keywords, **kwargs)(wrapper)