diff --git a/nonebot/handler.py b/nonebot/handler.py index 366e0bfc..acc35165 100644 --- a/nonebot/handler.py +++ b/nonebot/handler.py @@ -32,7 +32,7 @@ class HandlerMeta(type): f"matcher: {self.matcher_type})>") def __str__(self) -> str: - return self.__repr__() + return repr(self) class Handler(metaclass=HandlerMeta): @@ -57,25 +57,20 @@ class Handler(metaclass=HandlerMeta): f"matcher: {self.matcher_type})>") def __str__(self) -> str: - return self.__repr__() + return repr(self) async def __call__(self, matcher: "Matcher", bot: "Bot", event: "Event", state: T_State): - params = { - param.name: param.annotation - for param in self.signature.parameters.values() - } - - BotType = ((params["bot"] is not inspect.Parameter.empty) and - inspect.isclass(params["bot"]) and params["bot"]) + BotType = ((self.bot_type is not inspect.Parameter.empty) and + inspect.isclass(self.bot_type) and self.bot_type) if BotType and not isinstance(bot, BotType): logger.debug( f"Matcher {matcher} bot type {type(bot)} not match annotation {BotType}, ignored" ) return - EventType = ((params["event"] is not inspect.Parameter.empty) and - inspect.isclass(params["event"]) and params["event"]) + EventType = ((self.event_type is not inspect.Parameter.empty) and + inspect.isclass(self.event_type) and self.event_type) if EventType and not isinstance(event, EventType): logger.debug( f"Matcher {matcher} event type {type(event)} not match annotation {EventType}, ignored" @@ -84,7 +79,11 @@ class Handler(metaclass=HandlerMeta): args = {"bot": bot, "event": event, "state": state, "matcher": matcher} await self.func( - **{k: v for k, v in args.items() if params[k] is not None}) + **{ + k: v + for k, v in args.items() + if self.signature.parameters.get(k, None) is not None + }) @property def bot_type(self) -> Union[Type["Bot"], inspect.Parameter.empty]: diff --git a/nonebot/matcher.py b/nonebot/matcher.py index 61ab40ae..771fcc65 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -51,7 +51,7 @@ class MatcherMeta(type): f"temp={self.temp}>") def __str__(self) -> str: - return self.__repr__() + return repr(self) class Matcher(metaclass=MatcherMeta): @@ -140,7 +140,7 @@ class Matcher(metaclass=MatcherMeta): f"priority={self.priority}, temp={self.temp}>") def __str__(self) -> str: - return self.__repr__() + return repr(self) @classmethod def new(cls, diff --git a/nonebot/rule.py b/nonebot/rule.py index 75022335..9d5d7051 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -287,7 +287,11 @@ class ArgumentParser(ArgParser): """ def _print_message(self, message, file=None): - pass + old_message: str = getattr(self, "message", "") + if old_message: + old_message += "\n" + old_message += message + setattr(self, "message", old_message) def exit(self, status=0, message=None): raise ParserExit(status=status, message=message) @@ -365,7 +369,7 @@ def shell_command(*cmds: Union[str, Tuple[str, ...]], args = parser.parse_args(state["argv"]) state["args"] = args except ParserExit as e: - state["args"] = e + state["args"] = getattr(parser, "message", None) or e return True else: return False diff --git a/tests/test_plugins/test_delete.py b/tests/test_plugins/test_delete.py index 2c3265d8..4530771d 100644 --- a/tests/test_plugins/test_delete.py +++ b/tests/test_plugins/test_delete.py @@ -24,7 +24,7 @@ async def test_b(bot: Bot, event: Event, state: T_State): print("======== B Running Completed ========") -c = on_message(priority=0, permission=USER(1111111111)) +c = on_message(priority=0, permission=USER("1111111111")) @c.handle()