add log and config docs

This commit is contained in:
yanyongyu
2020-08-20 15:07:05 +08:00
parent 1d982fc77b
commit 02ca49f6d0
20 changed files with 488 additions and 68 deletions

View File

@ -10,4 +10,7 @@
* [nonebot.typing](typing.html)
* [nonebot.log](log.html)
* [nonebot.config](config.html)

View File

@ -1,32 +1,92 @@
# NoneBot.config 模块
### _class_ `BaseConfig(_env_file='<objectobject>', _env_file_encoding=None)`
## _class_ `Env`
基类:`pydantic.env_settings.BaseSettings`
运行环境配置。大小写不敏感。
### _class_ `Env(_env_file='<objectobject>', _env_file_encoding=None, *, environment='prod')`
基类:`pydantic.env_settings.BaseSettings`
将会从 `nonebot.init 参数` > `环境变量` > `.env 环境配置文件` 的优先级读取配置。
### _class_ `Config(_env_file='<objectobject>', _env_file_encoding=None, *, driver='nonebot.drivers.fastapi', host=IPv4Address('127.0.0.1'), port=8080, secret=None, debug=False, api_root={}, api_timeout=60.0, access_token=None, superusers={}, nickname='', command_start={'/'}, command_sep={'.'}, session_expire_timeout=datetime.timedelta(seconds=120), **values)`
基类:[`nonebot.config.BaseConfig`](#nonebot.config.BaseConfig)
NoneBot Config Object
configs:
### driver
### `environment`
* 类型: str
* 类型: `str`
* 默认值: "nonebot.drivers.fastapi"
* 默认值: `"prod"`
* 说明:
nonebot 运行使用后端框架封装 Driver 。继承自 nonebot.driver.BaseDriver
当前环境名。 NoneBot 将从 `.env.{environment}` 文件中加载配置
## _class_ `Config`
基类:`nonebot.config.BaseConfig`
NoneBot 主要配置。大小写不敏感。
除了 NoneBot 的配置项外,还可以自行添加配置项到 `.env.{environment}` 文件中。这些配置将会一起带入 `Config` 类中。
### `driver`
* 类型: `str`
* 默认值: `"nonebot.drivers.fastapi"`
* 说明:
NoneBot 运行所使用的 `Driver` 。继承自 `nonebot.driver.BaseDriver`
### `host`
* 类型: `IPvAnyAddress`
* 默认值: `127.0.0.1`
* 说明:
NoneBot 的 HTTP 和 WebSocket 服务端监听的 IP主机名。
### `port`
* 类型: `int`
* 默认值: `8080`
* 说明:
NoneBot 的 HTTP 和 WebSocket 服务端监听的端口。
### `secret`
* 类型: `Optional[str]`
* 默认值: `None`
* 说明:
上报连接 NoneBot 所需的密钥。
* 示例:
```http
POST /cqhttp/ HTTP/1.1
Authorization: Bearer kSLuTF2GC2Q4q4ugm3
```

117
docs/api/exception.md Normal file
View File

@ -0,0 +1,117 @@
# NoneBot.exception 模块
## 异常
下列文档中的异常是所有 NoneBot 运行时可能会抛出的。
这些异常并非所有需要用户处理,在 NoneBot 内部运行时被捕获,并进行对应操作。
## _exception_ `IgnoredException`
基类:`Exception`
* **说明**
指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
* **参数**
* `reason`: 忽略事件的原因
## _exception_ `PausedException`
基类:`Exception`
* **说明**
指示 NoneBot 结束当前 Handler 并等待下一条消息后继续下一个 Handler。
可用于用户输入新信息。
* **用法**
可以在 Handler 中通过 Matcher.pause() 抛出。
## _exception_ `RejectedException`
基类:`Exception`
* **说明**
指示 NoneBot 结束当前 Handler 并等待下一条消息后重新运行当前 Handler。
可用于用户重新输入。
* **用法**
可以在 Handler 中通过 Matcher.reject() 抛出。
## _exception_ `FinishedException`
基类:`Exception`
* **说明**
指示 NoneBot 结束当前 Handler 且后续 Handler 不再被运行。
可用于结束用户会话。
* **用法**
可以在 Handler 中通过 Matcher.finish() 抛出。
## _exception_ `ApiNotAvailable`
基类:`Exception`
* **说明**
在 API 连接不可用时抛出。
## _exception_ `NetworkError`
基类:`Exception`
* **说明**
在网络出现问题时抛出,如: API 请求地址不正确, API 请求无返回或返回状态非正常等。
## _exception_ `ActionFailed`
基类:`Exception`
* **说明**
API 请求成功返回数据,但 API 操作失败。
* **参数**
* `retcode`: 错误代码

41
docs/api/log.md Normal file
View File

@ -0,0 +1,41 @@
# NoneBot.log 模块
## 日志
NoneBot 使用标准库 [logging](https://docs.python.org/3/library/logging.html) 来记录日志信息。
自定义 logger 请参考 [logging](https://docs.python.org/3/library/logging.html) 文档。
## `logger`
* **说明**
NoneBot 日志记录器对象。
* **默认信息**
* 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
* 等级: `DEBUG` / `INFO` ,根据 config 配置改变
* 输出: 输出至 stdout
* **用法**
```python
from nonebot.log import logger
# 也可以这样
import logging
logger = logging.getLogger("nonebot")
```

View File

@ -1,7 +1,7 @@
# NoneBot 模块
### `get_driver()`
## `get_driver()`
* **说明**
@ -32,7 +32,7 @@ driver = nonebot.get_driver()
```
### `get_app()`
## `get_app()`
* **说明**
@ -63,7 +63,7 @@ app = nonebot.get_app()
```
### `get_asgi()`
## `get_asgi()`
* **说明**
@ -94,7 +94,7 @@ asgi = nonebot.get_asgi()
```
### `get_bots()`
## `get_bots()`
* **说明**
@ -125,7 +125,7 @@ bots = nonebot.get_bots()
```
### `init(*, _env_file=None, **kwargs)`
## `init(*, _env_file=None, **kwargs)`
* **说明**
@ -163,7 +163,7 @@ nonebot.init(database=Database(...))
```
### `run(host=None, port=None, *args, **kwargs)`
## `run(host=None, port=None, *args, **kwargs)`
* **说明**

View File

@ -9,7 +9,7 @@
以下类型均可从 nonebot.typing 模块导入。
### `Driver`
## `Driver`
* **类型**
@ -25,7 +25,7 @@
### `WebSocket`
## `WebSocket`
* **类型**
@ -41,7 +41,7 @@
### `Bot`
## `Bot`
* **类型**
@ -57,7 +57,7 @@
### `Event`
## `Event`
* **类型**
@ -73,7 +73,7 @@
### `Message`
## `Message`
* **类型**
@ -89,7 +89,7 @@
### `MessageSegment`
## `MessageSegment`
* **类型**
@ -105,7 +105,7 @@
### `PreProcessor`
## `PreProcessor`
* **类型**
@ -121,7 +121,7 @@
### `Matcher`
## `Matcher`
* **类型**
@ -137,7 +137,7 @@
### `Rule`
## `Rule`
* **类型**
@ -153,7 +153,7 @@
### `RuleChecker`
## `RuleChecker`
* **类型**
@ -169,7 +169,7 @@
### `Permission`
## `Permission`
* **类型**
@ -185,7 +185,7 @@
### `PermissionChecker`
## `PermissionChecker`
* **类型**
@ -201,7 +201,7 @@
### `Handler`
## `Handler`
* **类型**
@ -217,7 +217,7 @@
### `ArgsParser`
## `ArgsParser`
* **类型**