diff --git a/nonebot/config.py b/nonebot/config.py index 9dab8f51..5fad11be 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -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`_ 文档。 - -.. _pydantic: - https://pydantic-docs.helpmanual.io/ -.. _python-dotenv: - https://saurabh-kumar.com/python-dotenv/ -.. _pydantic Field Type: - https://pydantic-docs.helpmanual.io/usage/types/ +配置项需符合特殊格式或 json 序列化格式。详情见 [`pydantic Field Type`](https://pydantic-docs.helpmanual.io/usage/types/) 文档。 """ import os from pathlib import Path @@ -160,9 +153,9 @@ class Config(BaseConfig): """ NoneBot 运行所使用的 `Driver` 。继承自 `nonebot.drivers.Driver` 。 - 配置格式为 `[:][+[:]]*`。 + 配置格式为 `[:][+[:]]*`。 - `~` 为 `nonebot.drivers.` 的缩写。 + `~` 为 `nonebot.drivers.` 的缩写。 """ host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore """ @@ -174,16 +167,13 @@ class Config(BaseConfig): """ log_level: Union[int, str] = "INFO" """ - 配置 NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称,参考 `loguru 日志等级`_。 + 配置 NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称,参考 [`loguru 日志等级`](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。 用法: ```conf LOG_LEVEL=25 LOG_LEVEL=INFO ``` - - .. _loguru 日志等级: - https://loguru.readthedocs.io/en/stable/api/logger.html#levels """ # bot connection configs diff --git a/nonebot/drivers/__init__.py b/nonebot/drivers/__init__.py index c620f766..a32fdde5 100644 --- a/nonebot/drivers/__init__.py +++ b/nonebot/drivers/__init__.py @@ -113,9 +113,6 @@ class Driver(abc.ABC): def run(self, *args, **kwargs): """ 启动驱动框架 - - 参数: *args - **kwargs """ logger.opt(colors=True).debug( f"Loaded adapters: {escape_tag(', '.join(self._adapters))}" @@ -135,9 +132,8 @@ class Driver(abc.ABC): """ 装饰一个函数使他在 bot 通过 WebSocket 连接成功时执行。 - :函数参数: - - bot: 当前连接上的 Bot 对象 + 参数: + bot: 当前连接上的 Bot 对象 """ self._bot_connection_hook.add(func) return func @@ -146,9 +142,8 @@ class Driver(abc.ABC): """ 装饰一个函数使他在 bot 通过 WebSocket 连接断开时执行。 - :函数参数: - - bot: 当前连接上的 Bot 对象 + 参数: + bot: 当前连接上的 Bot 对象 """ self._bot_disconnection_hook.add(func) return func diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index 3a0a58d2..99f374f5 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -3,10 +3,7 @@ 本驱动同时支持服务端以及客户端连接 -后端使用方法请参考: `FastAPI 文档`_ - -.. _FastAPI 文档: - https://fastapi.tiangolo.com/ +后端使用方法请参考: [`FastAPI 文档`](https://fastapi.tiangolo.com/) """ import logging diff --git a/nonebot/drivers/quart.py b/nonebot/drivers/quart.py index f1f22da0..d6ebbeab 100644 --- a/nonebot/drivers/quart.py +++ b/nonebot/drivers/quart.py @@ -1,10 +1,7 @@ """ ## Quart 驱动适配 -后端使用方法请参考: `Quart 文档`_ - -.. _Quart 文档: - https://pgjones.gitlab.io/quart/index.html +后端使用方法请参考: [`Quart 文档`](https://pgjones.gitlab.io/quart/index.html) """ import asyncio @@ -139,16 +136,12 @@ class Driver(ReverseDriver): @overrides(ReverseDriver) 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 @overrides(ReverseDriver) 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 @overrides(ReverseDriver) diff --git a/nonebot/exception.py b/nonebot/exception.py index 9ea7cdd1..eb489a73 100644 --- a/nonebot/exception.py +++ b/nonebot/exception.py @@ -97,7 +97,7 @@ class SkippedException(MatcherException): 指示 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()` 抛出。 """ diff --git a/nonebot/log.py b/nonebot/log.py index 4c86af27..a1bf7f26 100644 --- a/nonebot/log.py +++ b/nonebot/log.py @@ -1,12 +1,11 @@ """ ## 日志 -NoneBot 使用 `loguru`_ 来记录日志信息。 +NoneBot 使用 [`loguru`][loguru] 来记录日志信息。 -自定义 logger 请参考 `loguru`_ 文档。 +自定义 logger 请参考 [`loguru`][loguru] 文档。 -.. _loguru: - https://github.com/Delgan/loguru +[loguru]: https://github.com/Delgan/loguru """ import sys @@ -25,11 +24,11 @@ logger: "Logger" = loguru.logger """ NoneBot 日志记录器对象。 -:默认信息: +默认信息: - * 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s` - * 等级: `INFO` ,根据 `config.log_level` 配置改变 - * 输出: 输出至 stdout + - 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s` + - 等级: `INFO` ,根据 `config.log_level` 配置改变 + - 输出: 输出至 stdout 用法: ```python diff --git a/nonebot/rule.py b/nonebot/rule.py index a103e703..d0d0e7b8 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -480,9 +480,6 @@ class ToMeRule: def to_me() -> Rule: """ 通过 `event.is_tome()` 判断事件是否与机器人有关 - - 参数: - * 无 """ return Rule(ToMeRule()) diff --git a/nonebot/typing.py b/nonebot/typing.py index f43ab359..938e92ba 100644 --- a/nonebot/typing.py +++ b/nonebot/typing.py @@ -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 内置类型的别名。 以下类型均可从 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 ( TYPE_CHECKING, diff --git a/nonebot/utils.py b/nonebot/utils.py index ced56782..8c621df6 100644 --- a/nonebot/utils.py +++ b/nonebot/utils.py @@ -133,13 +133,12 @@ class DataclassEncoder(json.JSONEncoder): def logger_wrapper(logger_name: str): """ - 用于打印 adapter 的日志。 + 用于打印 adapter 的日志。 - :log 参数: - - level: 日志等级 - message: 日志信息 - exception: 异常信息 + 参数: + level: 日志等级 + message: 日志信息 + exception: 异常信息 """ def log(level: str, message: str, exception: Optional[Exception] = None):