mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-09-21 05:12:34 +00:00
📝 update changelog
This commit is contained in:
parent
ca08c56df7
commit
59ec5bacde
@ -19,7 +19,7 @@ from nonebot import get_driver
|
|||||||
driver=get_driver()
|
driver=get_driver()
|
||||||
```
|
```
|
||||||
|
|
||||||
共分为四种函数:
|
共分为五种函数:
|
||||||
|
|
||||||
### 启动准备
|
### 启动准备
|
||||||
|
|
||||||
@ -61,6 +61,18 @@ async def do_something(bot: Bot):
|
|||||||
pass
|
pass
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### bot api 调用钩子
|
||||||
|
|
||||||
|
这个钩子函数会在 `Bot` 调用 API 时运行。
|
||||||
|
|
||||||
|
```python
|
||||||
|
from nonebot.adapters import Bot
|
||||||
|
|
||||||
|
@Bot.on_calling_api
|
||||||
|
async def handle_api_call(bot: Bot, api: str, data: Dict[str, Any]):
|
||||||
|
pass
|
||||||
|
```
|
||||||
|
|
||||||
## 事件处理钩子
|
## 事件处理钩子
|
||||||
|
|
||||||
这些钩子函数指的是影响 `nonebot2` 进行 `事件处理` 的函数。
|
这些钩子函数指的是影响 `nonebot2` 进行 `事件处理` 的函数。
|
||||||
@ -71,7 +83,7 @@ async def do_something(bot: Bot):
|
|||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
:::warning 注意
|
:::warning 注意
|
||||||
|
|
||||||
1.在事件处理钩子函数中,与 `matcher` 运行状态相关的函数将不可用,如 `matcher.finish()`
|
1.在事件处理钩子函数中,与 `matcher` 运行状态相关的函数将不可用,如 `matcher.finish()`
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class Bot(abc.ABC):
|
|||||||
await bot.call_api("send_msg", message="hello world")
|
await bot.call_api("send_msg", message="hello world")
|
||||||
await bot.send_msg(message="hello world")
|
await bot.send_msg(message="hello world")
|
||||||
"""
|
"""
|
||||||
coros = list(map(lambda x: x(api, data), self._call_api_hook))
|
coros = list(map(lambda x: x(self, api, data), self._call_api_hook))
|
||||||
if coros:
|
if coros:
|
||||||
try:
|
try:
|
||||||
logger.debug("Running CallingAPI hooks...")
|
logger.debug("Running CallingAPI hooks...")
|
||||||
|
@ -71,7 +71,7 @@ T_WebSocketDisconnectionHook = Callable[["Bot"], Awaitable[None]]
|
|||||||
|
|
||||||
WebSocket 连接断开时执行的函数
|
WebSocket 连接断开时执行的函数
|
||||||
"""
|
"""
|
||||||
T_CallingAPIHook = Callable[[str, Dict[str, Any]], Awaitable[None]]
|
T_CallingAPIHook = Callable[["Bot", str, Dict[str, Any]], Awaitable[None]]
|
||||||
|
|
||||||
T_EventPreProcessor = Callable[["Bot", "Event", T_State], Awaitable[None]]
|
T_EventPreProcessor = Callable[["Bot", "Event", T_State], Awaitable[None]]
|
||||||
"""
|
"""
|
||||||
|
@ -396,7 +396,7 @@ class Bot(BaseBot):
|
|||||||
- ``NetworkError``: 网络错误
|
- ``NetworkError``: 网络错误
|
||||||
- ``ActionFailed``: API 调用失败
|
- ``ActionFailed``: API 调用失败
|
||||||
"""
|
"""
|
||||||
return super().call_api(api, **data)
|
return await super().call_api(api, **data)
|
||||||
|
|
||||||
@overrides(BaseBot)
|
@overrides(BaseBot)
|
||||||
async def send(self,
|
async def send(self,
|
||||||
|
@ -193,7 +193,7 @@ class Bot(BaseBot):
|
|||||||
- ``NetworkError``: 网络错误
|
- ``NetworkError``: 网络错误
|
||||||
- ``ActionFailed``: API 调用失败
|
- ``ActionFailed``: API 调用失败
|
||||||
"""
|
"""
|
||||||
return super().call_api(api, event=event, **data)
|
return await super().call_api(api, event=event, **data)
|
||||||
|
|
||||||
@overrides(BaseBot)
|
@overrides(BaseBot)
|
||||||
async def send(self,
|
async def send(self,
|
||||||
|
@ -11,6 +11,9 @@ sidebar: auto
|
|||||||
- 修复 `pydantic 1.8` 导致的 `alias` 问题
|
- 修复 `pydantic 1.8` 导致的 `alias` 问题
|
||||||
- 修改 `cqhttp` `ding` `session id`,不再允许跨群
|
- 修改 `cqhttp` `ding` `session id`,不再允许跨群
|
||||||
- 修改 `shell_command` 存储 message
|
- 修改 `shell_command` 存储 message
|
||||||
|
- 修复 `cqhttp` 检查 reply 失败退出
|
||||||
|
- 新增 `call_api` hook 接口
|
||||||
|
- 优化 `import hook`
|
||||||
|
|
||||||
## v2.0.0a11
|
## v2.0.0a11
|
||||||
|
|
||||||
|
6
tests/test_plugins/test_api_hook.py
Normal file
6
tests/test_plugins/test_api_hook.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from nonebot.adapters import Bot
|
||||||
|
|
||||||
|
|
||||||
|
@Bot.on_calling_api
|
||||||
|
async def call(bot: Bot, api: str, data: dict):
|
||||||
|
print(type(bot), api, data)
|
Loading…
Reference in New Issue
Block a user