diff --git a/nonebot/__init__.py b/nonebot/__init__.py index 7522f270..a28d9e81 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -215,7 +215,7 @@ def run(host: Optional[str] = None, get_driver().run(host, port, *args, **kwargs) -from nonebot.plugin import on_message, on_notice, on_request, on_metaevent, CommandGroup +from nonebot.plugin import on_message, on_notice, on_request, on_metaevent, CommandGroup, MatcherGroup from nonebot.plugin import on_startswith, on_endswith, on_keyword, on_command, on_regex from nonebot.plugin import load_plugin, load_plugins, load_builtin_plugins from nonebot.plugin import export, require, get_plugin, get_loaded_plugins diff --git a/nonebot/plugin.py b/nonebot/plugin.py index 1f876534..57410566 100644 --- a/nonebot/plugin.py +++ b/nonebot/plugin.py @@ -555,8 +555,8 @@ class MatcherGroup: """ final_kwargs = self.base_kwargs.copy() final_kwargs.update(kwargs) - final_kwargs["type"] = "meta_event" - matcher = Matcher.new(**final_kwargs) + final_kwargs.pop("type", None) + matcher = Matcher.new("meta_event", **final_kwargs) self.matchers.append(matcher) _tmp_matchers.get().add(matcher) return matcher @@ -583,8 +583,8 @@ class MatcherGroup: """ final_kwargs = self.base_kwargs.copy() final_kwargs.update(kwargs) - final_kwargs["type"] = "message" - matcher = Matcher.new(**final_kwargs) + final_kwargs.pop("type", None) + matcher = Matcher.new("message", **final_kwargs) self.matchers.append(matcher) _tmp_matchers.get().add(matcher) return matcher @@ -610,8 +610,8 @@ class MatcherGroup: """ final_kwargs = self.base_kwargs.copy() final_kwargs.update(kwargs) - final_kwargs["type"] = "notice" - matcher = Matcher.new(**final_kwargs) + final_kwargs.pop("type", None) + matcher = Matcher.new("notice", **final_kwargs) self.matchers.append(matcher) _tmp_matchers.get().add(matcher) return matcher @@ -637,8 +637,8 @@ class MatcherGroup: """ final_kwargs = self.base_kwargs.copy() final_kwargs.update(kwargs) - final_kwargs["type"] = "request" - matcher = Matcher.new(**final_kwargs) + final_kwargs.pop("type", None) + matcher = Matcher.new("request", **final_kwargs) self.matchers.append(matcher) _tmp_matchers.get().add(matcher) return matcher diff --git a/tests/test_plugins/test_group/__init__.py b/tests/test_plugins/test_group/__init__.py index 1f47bd5c..9d1d04a7 100644 --- a/tests/test_plugins/test_group/__init__.py +++ b/tests/test_plugins/test_group/__init__.py @@ -1,6 +1,7 @@ from nonebot.rule import to_me -from nonebot import CommandGroup +from nonebot import CommandGroup, MatcherGroup -test = CommandGroup("test", rule=to_me()) +cmd = CommandGroup("test", rule=to_me()) +match = MatcherGroup(priority=2) -from . import commands +from . import commands, matches diff --git a/tests/test_plugins/test_group/commands.py b/tests/test_plugins/test_group/commands.py index e825329d..52242d32 100644 --- a/tests/test_plugins/test_group/commands.py +++ b/tests/test_plugins/test_group/commands.py @@ -1,9 +1,9 @@ from nonebot.typing import Bot, Event from nonebot.permission import GROUP_OWNER -from . import test +from . import cmd -test_1 = test.command("1", aliases={"test"}, permission=GROUP_OWNER) +test_1 = cmd.command("1", aliases={"test"}, permission=GROUP_OWNER) @test_1.handle() diff --git a/tests/test_plugins/test_group/matches.py b/tests/test_plugins/test_group/matches.py new file mode 100644 index 00000000..8c3c786b --- /dev/null +++ b/tests/test_plugins/test_group/matches.py @@ -0,0 +1,15 @@ +from nonebot.typing import Bot, Event + +from . import match + + +async def heartbeat(bot: Bot, event: Event, state: dict) -> bool: + return event.detail_type == "heartbeat" + + +test = match.on_metaevent(rule=heartbeat) + + +@test.receive() +async def handle_heartbeat(bot: Bot, event: Event, state: dict): + print("[i] Heartbeat")