📝 update changelog

This commit is contained in:
yanyongyu 2021-03-31 21:20:07 +08:00
parent ca08c56df7
commit 59ec5bacde
7 changed files with 27 additions and 6 deletions

View File

@ -19,7 +19,7 @@ from nonebot import get_driver
driver=get_driver()
```
共分为种函数:
共分为种函数:
### 启动准备
@ -61,6 +61,18 @@ async def do_something(bot: Bot):
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` 进行 `事件处理` 的函数。

View File

@ -156,7 +156,7 @@ class Bot(abc.ABC):
await bot.call_api("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:
try:
logger.debug("Running CallingAPI hooks...")

View File

@ -71,7 +71,7 @@ T_WebSocketDisconnectionHook = Callable[["Bot"], Awaitable[None]]
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]]
"""

View File

@ -396,7 +396,7 @@ class Bot(BaseBot):
- ``NetworkError``: 网络错误
- ``ActionFailed``: API 调用失败
"""
return super().call_api(api, **data)
return await super().call_api(api, **data)
@overrides(BaseBot)
async def send(self,

View File

@ -193,7 +193,7 @@ class Bot(BaseBot):
- ``NetworkError``: 网络错误
- ``ActionFailed``: API 调用失败
"""
return super().call_api(api, event=event, **data)
return await super().call_api(api, event=event, **data)
@overrides(BaseBot)
async def send(self,

View File

@ -11,6 +11,9 @@ sidebar: auto
- 修复 `pydantic 1.8` 导致的 `alias` 问题
- 修改 `cqhttp` `ding` `session id`,不再允许跨群
- 修改 `shell_command` 存储 message
- 修复 `cqhttp` 检查 reply 失败退出
- 新增 `call_api` hook 接口
- 优化 `import hook`
## v2.0.0a11

View 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)