test matchergroup

This commit is contained in:
yanyongyu 2020-12-04 01:55:03 +08:00
parent 5b42454a55
commit f6806c1d55
5 changed files with 30 additions and 14 deletions

View File

@ -215,7 +215,7 @@ def run(host: Optional[str] = None,
get_driver().run(host, port, *args, **kwargs) 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 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 load_plugin, load_plugins, load_builtin_plugins
from nonebot.plugin import export, require, get_plugin, get_loaded_plugins from nonebot.plugin import export, require, get_plugin, get_loaded_plugins

View File

@ -555,8 +555,8 @@ class MatcherGroup:
""" """
final_kwargs = self.base_kwargs.copy() final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs) final_kwargs.update(kwargs)
final_kwargs["type"] = "meta_event" final_kwargs.pop("type", None)
matcher = Matcher.new(**final_kwargs) matcher = Matcher.new("meta_event", **final_kwargs)
self.matchers.append(matcher) self.matchers.append(matcher)
_tmp_matchers.get().add(matcher) _tmp_matchers.get().add(matcher)
return matcher return matcher
@ -583,8 +583,8 @@ class MatcherGroup:
""" """
final_kwargs = self.base_kwargs.copy() final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs) final_kwargs.update(kwargs)
final_kwargs["type"] = "message" final_kwargs.pop("type", None)
matcher = Matcher.new(**final_kwargs) matcher = Matcher.new("message", **final_kwargs)
self.matchers.append(matcher) self.matchers.append(matcher)
_tmp_matchers.get().add(matcher) _tmp_matchers.get().add(matcher)
return matcher return matcher
@ -610,8 +610,8 @@ class MatcherGroup:
""" """
final_kwargs = self.base_kwargs.copy() final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs) final_kwargs.update(kwargs)
final_kwargs["type"] = "notice" final_kwargs.pop("type", None)
matcher = Matcher.new(**final_kwargs) matcher = Matcher.new("notice", **final_kwargs)
self.matchers.append(matcher) self.matchers.append(matcher)
_tmp_matchers.get().add(matcher) _tmp_matchers.get().add(matcher)
return matcher return matcher
@ -637,8 +637,8 @@ class MatcherGroup:
""" """
final_kwargs = self.base_kwargs.copy() final_kwargs = self.base_kwargs.copy()
final_kwargs.update(kwargs) final_kwargs.update(kwargs)
final_kwargs["type"] = "request" final_kwargs.pop("type", None)
matcher = Matcher.new(**final_kwargs) matcher = Matcher.new("request", **final_kwargs)
self.matchers.append(matcher) self.matchers.append(matcher)
_tmp_matchers.get().add(matcher) _tmp_matchers.get().add(matcher)
return matcher return matcher

View File

@ -1,6 +1,7 @@
from nonebot.rule import to_me 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

View File

@ -1,9 +1,9 @@
from nonebot.typing import Bot, Event from nonebot.typing import Bot, Event
from nonebot.permission import GROUP_OWNER 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() @test_1.handle()

View File

@ -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")