mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 09:38:21 +08:00
⚗️ add got receive overload #142
This commit is contained in:
parent
a211f09a99
commit
b6bf477551
@ -294,18 +294,27 @@ class Matcher(metaclass=MatcherMeta):
|
|||||||
* 无
|
* 无
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def _receive(bot: "Bot", event: "Event",
|
async def _receive(bot: "Bot", event: "Event") -> NoReturn:
|
||||||
state: T_State) -> NoReturn:
|
|
||||||
raise PausedException
|
raise PausedException
|
||||||
|
|
||||||
|
cls.process_handler(_receive)
|
||||||
|
|
||||||
if cls.handlers:
|
if cls.handlers:
|
||||||
# 已有前置handlers则接受一条新的消息,否则视为接收初始消息
|
# 已有前置handlers则接受一条新的消息,否则视为接收初始消息
|
||||||
cls.append_handler(_receive)
|
cls.append_handler(_receive)
|
||||||
|
|
||||||
def _decorator(func: T_Handler) -> T_Handler:
|
def _decorator(func: T_Handler) -> T_Handler:
|
||||||
|
cls.process_handler(func)
|
||||||
if not cls.handlers or cls.handlers[-1] is not func:
|
if not cls.handlers or cls.handlers[-1] is not func:
|
||||||
cls.append_handler(func)
|
cls.append_handler(func)
|
||||||
|
|
||||||
|
_receive.__params__.update({
|
||||||
|
"bot":
|
||||||
|
func.__params__["bot"],
|
||||||
|
"event":
|
||||||
|
func.__params__["event"] or _receive.__params__["event"]
|
||||||
|
})
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return _decorator
|
return _decorator
|
||||||
@ -368,6 +377,25 @@ class Matcher(metaclass=MatcherMeta):
|
|||||||
|
|
||||||
cls.append_handler(wrapper)
|
cls.append_handler(wrapper)
|
||||||
|
|
||||||
|
wrapper.__params__.update({
|
||||||
|
"bot":
|
||||||
|
func.__params__["bot"],
|
||||||
|
"event":
|
||||||
|
func.__params__["event"] or wrapper.__params__["event"]
|
||||||
|
})
|
||||||
|
_key_getter.__params__.update({
|
||||||
|
"bot":
|
||||||
|
func.__params__["bot"],
|
||||||
|
"event":
|
||||||
|
func.__params__["event"] or wrapper.__params__["event"]
|
||||||
|
})
|
||||||
|
_key_parser.__params__.update({
|
||||||
|
"bot":
|
||||||
|
func.__params__["bot"],
|
||||||
|
"event":
|
||||||
|
func.__params__["event"] or wrapper.__params__["event"]
|
||||||
|
})
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
|
||||||
return _decorator
|
return _decorator
|
||||||
|
19
tests/test_plugins/test_overload.py
Normal file
19
tests/test_plugins/test_overload.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from nonebot import on_command
|
||||||
|
from nonebot.adapters.cqhttp import Bot, PrivateMessageEvent, GroupMessageEvent
|
||||||
|
|
||||||
|
overload = on_command("overload")
|
||||||
|
|
||||||
|
|
||||||
|
@overload.handle()
|
||||||
|
async def handle_first_receive(bot: Bot):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@overload.got("message", prompt="群?")
|
||||||
|
async def handle_group(bot: Bot, event: GroupMessageEvent):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@overload.got("message", prompt="私?")
|
||||||
|
async def handle_private(bot: Bot, event: PrivateMessageEvent):
|
||||||
|
return
|
Loading…
Reference in New Issue
Block a user