mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-02-17 16:20:05 +08:00
粗略过一遍,修复一眼可见的问题
This commit is contained in:
parent
ec06010298
commit
98deadb4d6
@ -1,16 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
## 配置
|
## 配置
|
||||||
|
|
||||||
NoneBot 使用 `pydantic`_ 以及 `python-dotenv`_ 来读取配置。
|
NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及 [`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。
|
||||||
|
|
||||||
配置项需符合特殊格式或 json 序列化格式。详情见 `pydantic Field Type`_ 文档。
|
配置项需符合特殊格式或 json 序列化格式。详情见 [`pydantic Field Type`](https://pydantic-docs.helpmanual.io/usage/types/) 文档。
|
||||||
|
|
||||||
.. _pydantic:
|
|
||||||
https://pydantic-docs.helpmanual.io/
|
|
||||||
.. _python-dotenv:
|
|
||||||
https://saurabh-kumar.com/python-dotenv/
|
|
||||||
.. _pydantic Field Type:
|
|
||||||
https://pydantic-docs.helpmanual.io/usage/types/
|
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -160,9 +153,9 @@ class Config(BaseConfig):
|
|||||||
"""
|
"""
|
||||||
NoneBot 运行所使用的 `Driver` 。继承自 `nonebot.drivers.Driver` 。
|
NoneBot 运行所使用的 `Driver` 。继承自 `nonebot.drivers.Driver` 。
|
||||||
|
|
||||||
配置格式为 `<module>[:<Driver>][+<module>[:<Mixin>]]*`。
|
配置格式为 `<module>[:<Driver>][+<module>[:<Mixin>]]*`。
|
||||||
|
|
||||||
`~` 为 `nonebot.drivers.` 的缩写。
|
`~` 为 `nonebot.drivers.` 的缩写。
|
||||||
"""
|
"""
|
||||||
host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore
|
host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore
|
||||||
"""
|
"""
|
||||||
@ -174,16 +167,13 @@ class Config(BaseConfig):
|
|||||||
"""
|
"""
|
||||||
log_level: Union[int, str] = "INFO"
|
log_level: Union[int, str] = "INFO"
|
||||||
"""
|
"""
|
||||||
配置 NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称,参考 `loguru 日志等级`_。
|
配置 NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称,参考 [`loguru 日志等级`](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
```conf
|
```conf
|
||||||
LOG_LEVEL=25
|
LOG_LEVEL=25
|
||||||
LOG_LEVEL=INFO
|
LOG_LEVEL=INFO
|
||||||
```
|
```
|
||||||
|
|
||||||
.. _loguru 日志等级:
|
|
||||||
https://loguru.readthedocs.io/en/stable/api/logger.html#levels
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bot connection configs
|
# bot connection configs
|
||||||
|
@ -113,9 +113,6 @@ class Driver(abc.ABC):
|
|||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
启动驱动框架
|
启动驱动框架
|
||||||
|
|
||||||
参数: *args
|
|
||||||
**kwargs
|
|
||||||
"""
|
"""
|
||||||
logger.opt(colors=True).debug(
|
logger.opt(colors=True).debug(
|
||||||
f"<g>Loaded adapters: {escape_tag(', '.join(self._adapters))}</g>"
|
f"<g>Loaded adapters: {escape_tag(', '.join(self._adapters))}</g>"
|
||||||
@ -135,9 +132,8 @@ class Driver(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
|
装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。
|
||||||
|
|
||||||
:函数参数:
|
参数:
|
||||||
|
bot: 当前连接上的 Bot 对象
|
||||||
bot: 当前连接上的 Bot 对象
|
|
||||||
"""
|
"""
|
||||||
self._bot_connection_hook.add(func)
|
self._bot_connection_hook.add(func)
|
||||||
return func
|
return func
|
||||||
@ -146,9 +142,8 @@ class Driver(abc.ABC):
|
|||||||
"""
|
"""
|
||||||
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
|
装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。
|
||||||
|
|
||||||
:函数参数:
|
参数:
|
||||||
|
bot: 当前连接上的 Bot 对象
|
||||||
bot: 当前连接上的 Bot 对象
|
|
||||||
"""
|
"""
|
||||||
self._bot_disconnection_hook.add(func)
|
self._bot_disconnection_hook.add(func)
|
||||||
return func
|
return func
|
||||||
|
@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
本驱动同时支持服务端以及客户端连接
|
本驱动同时支持服务端以及客户端连接
|
||||||
|
|
||||||
后端使用方法请参考: `FastAPI 文档`_
|
后端使用方法请参考: [`FastAPI 文档`](https://fastapi.tiangolo.com/)
|
||||||
|
|
||||||
.. _FastAPI 文档:
|
|
||||||
https://fastapi.tiangolo.com/
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
## Quart 驱动适配
|
## Quart 驱动适配
|
||||||
|
|
||||||
后端使用方法请参考: `Quart 文档`_
|
后端使用方法请参考: [`Quart 文档`](https://pgjones.gitlab.io/quart/index.html)
|
||||||
|
|
||||||
.. _Quart 文档:
|
|
||||||
https://pgjones.gitlab.io/quart/index.html
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -139,16 +136,12 @@ class Driver(ReverseDriver):
|
|||||||
|
|
||||||
@overrides(ReverseDriver)
|
@overrides(ReverseDriver)
|
||||||
def on_startup(self, func: _AsyncCallable) -> _AsyncCallable:
|
def on_startup(self, func: _AsyncCallable) -> _AsyncCallable:
|
||||||
"""参考文档: `Startup and Shutdown`_
|
"""参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)"""
|
||||||
|
|
||||||
.. _Startup and Shutdown:
|
|
||||||
https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html
|
|
||||||
"""
|
|
||||||
return self.server_app.before_serving(func) # type: ignore
|
return self.server_app.before_serving(func) # type: ignore
|
||||||
|
|
||||||
@overrides(ReverseDriver)
|
@overrides(ReverseDriver)
|
||||||
def on_shutdown(self, func: _AsyncCallable) -> _AsyncCallable:
|
def on_shutdown(self, func: _AsyncCallable) -> _AsyncCallable:
|
||||||
"""参考文档: `Startup and Shutdown`_"""
|
"""参考文档: [`Startup and Shutdown`](https://pgjones.gitlab.io/quart/how_to_guides/startup_shutdown.html)"""
|
||||||
return self.server_app.after_serving(func) # type: ignore
|
return self.server_app.after_serving(func) # type: ignore
|
||||||
|
|
||||||
@overrides(ReverseDriver)
|
@overrides(ReverseDriver)
|
||||||
|
@ -97,7 +97,7 @@ class SkippedException(MatcherException):
|
|||||||
指示 NoneBot 立即结束当前 `Handler` 的处理,继续处理下一个 `Handler`。
|
指示 NoneBot 立即结束当前 `Handler` 的处理,继续处理下一个 `Handler`。
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
可以在 `Handler` 中通过 `Matcher.skip()` 抛出。
|
可以在 `Handler` 中通过 `Matcher.skip()` 抛出。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ class PausedException(MatcherException):
|
|||||||
可用于用户输入新信息。
|
可用于用户输入新信息。
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
可以在 `Handler` 中通过 `Matcher.pause()` 抛出。
|
可以在 `Handler` 中通过 `Matcher.pause()` 抛出。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ class RejectedException(MatcherException):
|
|||||||
可用于用户重新输入。
|
可用于用户重新输入。
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
可以在 `Handler` 中通过 `Matcher.reject()` 抛出。
|
可以在 `Handler` 中通过 `Matcher.reject()` 抛出。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ class FinishedException(MatcherException):
|
|||||||
可用于结束用户会话。
|
可用于结束用户会话。
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
可以在 `Handler` 中通过 `Matcher.finish()` 抛出。
|
可以在 `Handler` 中通过 `Matcher.finish()` 抛出。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
## 日志
|
## 日志
|
||||||
|
|
||||||
NoneBot 使用 `loguru`_ 来记录日志信息。
|
NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||||
|
|
||||||
自定义 logger 请参考 `loguru`_ 文档。
|
自定义 logger 请参考 [`loguru`][loguru] 文档。
|
||||||
|
|
||||||
.. _loguru:
|
[loguru]: https://github.com/Delgan/loguru
|
||||||
https://github.com/Delgan/loguru
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -25,11 +24,11 @@ logger: "Logger" = loguru.logger
|
|||||||
"""
|
"""
|
||||||
NoneBot 日志记录器对象。
|
NoneBot 日志记录器对象。
|
||||||
|
|
||||||
:默认信息:
|
默认信息:
|
||||||
|
|
||||||
* 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
|
- 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
|
||||||
* 等级: `INFO` ,根据 `config.log_level` 配置改变
|
- 等级: `INFO` ,根据 `config.log_level` 配置改变
|
||||||
* 输出: 输出至 stdout
|
- 输出: 输出至 stdout
|
||||||
|
|
||||||
用法:
|
用法:
|
||||||
```python
|
```python
|
||||||
|
@ -480,9 +480,6 @@ class ToMeRule:
|
|||||||
def to_me() -> Rule:
|
def to_me() -> Rule:
|
||||||
"""
|
"""
|
||||||
通过 `event.is_tome()` 判断事件是否与机器人有关
|
通过 `event.is_tome()` 判断事件是否与机器人有关
|
||||||
|
|
||||||
参数:
|
|
||||||
* 无
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return Rule(ToMeRule())
|
return Rule(ToMeRule())
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
## 类型
|
## 类型
|
||||||
|
|
||||||
下面的文档中,「类型」部分使用 Python 的 Type Hint 语法,见 `PEP 484`_、`PEP 526`_ 和 `typing`_。
|
下面的文档中,「类型」部分使用 Python 的 Type Hint 语法,见 [`PEP 484`](https://www.python.org/dev/peps/pep-0484/)、[`PEP 526`](https://www.python.org/dev/peps/pep-0526/) 和 [`typing`](https://docs.python.org/3/library/typing.html)。
|
||||||
|
|
||||||
除了 Python 内置的类型,下面还出现了如下 NoneBot 自定类型,实际上它们是 Python 内置类型的别名。
|
除了 Python 内置的类型,下面还出现了如下 NoneBot 自定类型,实际上它们是 Python 内置类型的别名。
|
||||||
|
|
||||||
以下类型均可从 nonebot.typing 模块导入。
|
以下类型均可从 nonebot.typing 模块导入。
|
||||||
|
|
||||||
.. _PEP 484:
|
|
||||||
https://www.python.org/dev/peps/pep-0484/
|
|
||||||
|
|
||||||
.. _PEP 526:
|
|
||||||
https://www.python.org/dev/peps/pep-0526/
|
|
||||||
|
|
||||||
.. _typing:
|
|
||||||
https://docs.python.org/3/library/typing.html
|
|
||||||
"""
|
"""
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
|
@ -133,13 +133,12 @@ class DataclassEncoder(json.JSONEncoder):
|
|||||||
|
|
||||||
def logger_wrapper(logger_name: str):
|
def logger_wrapper(logger_name: str):
|
||||||
"""
|
"""
|
||||||
用于打印 adapter 的日志。
|
用于打印 adapter 的日志。
|
||||||
|
|
||||||
:log 参数:
|
参数:
|
||||||
|
level: 日志等级
|
||||||
level: 日志等级
|
message: 日志信息
|
||||||
message: 日志信息
|
exception: 异常信息
|
||||||
exception: 异常信息
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def log(level: str, message: str, exception: Optional[Exception] = None):
|
def log(level: str, message: str, exception: Optional[Exception] = None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user