From 533a045622a59c1d651a710a103d5982df54d201 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Wed, 4 Nov 2020 13:27:49 +0800 Subject: [PATCH 1/2] :arrow_up: bump version and update dependency --- poetry.lock | 112 ++++++++++--------------------------------------- pyproject.toml | 6 +-- 2 files changed, 26 insertions(+), 92 deletions(-) diff --git a/poetry.lock b/poetry.lock index de144278..1f6dfab9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -418,49 +418,6 @@ type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" reference = "aliyun" -[[package]] -name = "h2" -version = "3.2.0" -description = "HTTP/2 State-Machine based protocol implementation" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -hpack = ">=3.0,<4" -hyperframe = ">=5.2.0,<6" - -[package.source] -type = "legacy" -url = "https://mirrors.aliyun.com/pypi/simple" -reference = "aliyun" - -[[package]] -name = "hpack" -version = "3.0.0" -description = "Pure-Python HPACK header compression" -category = "main" -optional = false -python-versions = "*" - -[package.source] -type = "legacy" -url = "https://mirrors.aliyun.com/pypi/simple" -reference = "aliyun" - -[[package]] -name = "hstspreload" -version = "2020.10.20" -description = "Chromium HSTS Preload list as a Python package and updated daily" -category = "main" -optional = false -python-versions = ">=3.6" - -[package.source] -type = "legacy" -url = "https://mirrors.aliyun.com/pypi/simple" -reference = "aliyun" - [[package]] name = "html2text" version = "2020.1.16" @@ -476,17 +433,19 @@ reference = "aliyun" [[package]] name = "httpcore" -version = "0.9.1" +version = "0.12.0" description = "A minimal low-level HTTP client." category = "main" optional = false python-versions = ">=3.6" [package.dependencies] -h11 = ">=0.8,<0.10" -h2 = ">=3.0.0,<4.0.0" +h11 = "<1.0.0" sniffio = ">=1.0.0,<2.0.0" +[package.extras] +http2 = ["h2 (>=3,<5)"] + [package.source] type = "legacy" url = "https://mirrors.aliyun.com/pypi/simple" @@ -510,7 +469,7 @@ reference = "aliyun" [[package]] name = "httpx" -version = "0.13.3" +version = "0.16.1" description = "The next generation HTTP client." category = "main" optional = false @@ -518,25 +477,13 @@ python-versions = ">=3.6" [package.dependencies] certifi = "*" -chardet = ">=3.0.0,<4.0.0" -hstspreload = "*" -httpcore = ">=0.9.0,<0.10.0" -idna = ">=2.0.0,<3.0.0" -rfc3986 = ">=1.3,<2" +httpcore = ">=0.12.0,<0.13.0" +rfc3986 = {version = ">=1.3,<2", extras = ["idna2008"]} sniffio = "*" -[package.source] -type = "legacy" -url = "https://mirrors.aliyun.com/pypi/simple" -reference = "aliyun" - -[[package]] -name = "hyperframe" -version = "5.2.0" -description = "HTTP/2 framing layer for Python" -category = "main" -optional = false -python-versions = "*" +[package.extras] +brotli = ["brotlipy (>=0.7.0,<0.8.0)"] +http2 = ["h2 (>=3.0.0,<4.0.0)"] [package.source] type = "legacy" @@ -1121,6 +1068,9 @@ category = "main" optional = false python-versions = "*" +[package.dependencies] +idna = {version = "*", optional = true, markers = "extra == \"idna2008\""} + [package.extras] idna2008 = ["idna"] @@ -1170,7 +1120,7 @@ reference = "aliyun" [[package]] name = "sphinx" -version = "3.2.1" +version = "3.3.0" description = "Python documentation generator" category = "dev" optional = false @@ -1196,7 +1146,7 @@ sphinxcontrib-serializinghtml = "*" [package.extras] docs = ["sphinxcontrib-websupport"] -lint = ["flake8 (>=3.5.0)", "flake8-import-order", "mypy (>=0.780)", "docutils-stubs"] +lint = ["flake8 (>=3.5.0)", "flake8-import-order", "mypy (>=0.790)", "docutils-stubs"] test = ["pytest", "pytest-cov", "html5lib", "typed-ast", "cython"] [package.source] @@ -1565,7 +1515,7 @@ test = ["nonebot-test"] [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "04acfd9bf32ebb7173922b1d0c28500d1a80ff22307856d61b04668e808c19be" +content-hash = "70521f44e1004cf7bc3863c5d249e18d31ff526bf4420f38cd1f81ae2cf561fb" [metadata.files] aiofiles = [ @@ -1721,25 +1671,13 @@ h11 = [ {file = "h11-0.9.0-py2.py3-none-any.whl", hash = "sha256:4bc6d6a1238b7615b266ada57e0618568066f57dd6fa967d1290ec9309b2f2f1"}, {file = "h11-0.9.0.tar.gz", hash = "sha256:33d4bca7be0fa039f4e84d50ab00531047e53d6ee8ffbc83501ea602c169cae1"}, ] -h2 = [ - {file = "h2-3.2.0-py2.py3-none-any.whl", hash = "sha256:61e0f6601fa709f35cdb730863b4e5ec7ad449792add80d1410d4174ed139af5"}, - {file = "h2-3.2.0.tar.gz", hash = "sha256:875f41ebd6f2c44781259005b157faed1a5031df3ae5aa7bcb4628a6c0782f14"}, -] -hpack = [ - {file = "hpack-3.0.0-py2.py3-none-any.whl", hash = "sha256:0edd79eda27a53ba5be2dfabf3b15780928a0dff6eb0c60a3d6767720e970c89"}, - {file = "hpack-3.0.0.tar.gz", hash = "sha256:8eec9c1f4bfae3408a3f30500261f7e6a65912dc138526ea054f9ad98892e9d2"}, -] -hstspreload = [ - {file = "hstspreload-2020.10.20-py3-none-any.whl", hash = "sha256:0cd540f86c2930fe466348bd984e5ae1c96a0041fb97df61431997523d9e719d"}, - {file = "hstspreload-2020.10.20.tar.gz", hash = "sha256:0a79313c2f52f18aa0ade1f27664ee39bee1cb4eb2ed1d610e2bd22e2e4050e1"}, -] html2text = [ {file = "html2text-2020.1.16-py3-none-any.whl", hash = "sha256:c7c629882da0cf377d66f073329ccf34a12ed2adf0169b9285ae4e63ef54c82b"}, {file = "html2text-2020.1.16.tar.gz", hash = "sha256:e296318e16b059ddb97f7a8a1d6a5c1d7af4544049a01e261731d2d5cc277bbb"}, ] httpcore = [ - {file = "httpcore-0.9.1-py3-none-any.whl", hash = "sha256:9850fe97a166a794d7e920590d5ec49a05488884c9fc8b5dba8561effab0c2a0"}, - {file = "httpcore-0.9.1.tar.gz", hash = "sha256:ecc5949310d9dae4de64648a4ce529f86df1f232ce23dcfefe737c24d21dfbe9"}, + {file = "httpcore-0.12.0-py3-none-any.whl", hash = "sha256:18c4afcbfe884b635e59739105aed1692e132bc5d31597109f3c1c97e4ec1cac"}, + {file = "httpcore-0.12.0.tar.gz", hash = "sha256:2526a38f31ac5967d38b7f593b5d8c4bd3fa82c21400402f866ba3312946acbf"}, ] httptools = [ {file = "httptools-0.1.1-cp35-cp35m-macosx_10_13_x86_64.whl", hash = "sha256:a2719e1d7a84bb131c4f1e0cb79705034b48de6ae486eb5297a139d6a3296dce"}, @@ -1756,12 +1694,8 @@ httptools = [ {file = "httptools-0.1.1.tar.gz", hash = "sha256:41b573cf33f64a8f8f3400d0a7faf48e1888582b6f6e02b82b9bd4f0bf7497ce"}, ] httpx = [ - {file = "httpx-0.13.3-py3-none-any.whl", hash = "sha256:32d930858eab677bc29a742aaa4f096de259f1c78c68a90ad11f5c3c04f08335"}, - {file = "httpx-0.13.3.tar.gz", hash = "sha256:3642bd13e90b80ba8a243a730275eb10a4c26ec96f5fc16b87e458d4ab21efae"}, -] -hyperframe = [ - {file = "hyperframe-5.2.0-py2.py3-none-any.whl", hash = "sha256:5187962cb16dcc078f23cb5a4b110098d546c3f41ff2d4038a9896893bbd0b40"}, - {file = "hyperframe-5.2.0.tar.gz", hash = "sha256:a9f5c17f2cc3c719b917c4f33ed1c61bd1f8dfac4b1bd23b7c80b3400971b41f"}, + {file = "httpx-0.16.1-py3-none-any.whl", hash = "sha256:9cffb8ba31fac6536f2c8cde30df859013f59e4bcc5b8d43901cb3654a8e0a5b"}, + {file = "httpx-0.16.1.tar.gz", hash = "sha256:126424c279c842738805974687e0518a94c7ae8d140cd65b9c4f77ac46ffa537"}, ] idna = [ {file = "idna-2.10-py2.py3-none-any.whl", hash = "sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"}, @@ -2024,8 +1958,8 @@ snowballstemmer = [ {file = "snowballstemmer-2.0.0.tar.gz", hash = "sha256:df3bac3df4c2c01363f3dd2cfa78cce2840a79b9f1c2d2de9ce8d31683992f52"}, ] sphinx = [ - {file = "Sphinx-3.2.1-py3-none-any.whl", hash = "sha256:ce6fd7ff5b215af39e2fcd44d4a321f6694b4530b6f2b2109b64d120773faea0"}, - {file = "Sphinx-3.2.1.tar.gz", hash = "sha256:321d6d9b16fa381a5306e5a0b76cd48ffbc588e6340059a729c6fdd66087e0e8"}, + {file = "Sphinx-3.3.0-py3-none-any.whl", hash = "sha256:3abdb2c57a65afaaa4f8573cbabd5465078eb6fd282c1e4f87f006875a7ec0c7"}, + {file = "Sphinx-3.3.0.tar.gz", hash = "sha256:1c21e7c5481a31b531e6cbf59c3292852ccde175b504b00ce2ff0b8f4adc3649"}, ] sphinx-markdown-builder = [] sphinxcontrib-applehelp = [ diff --git a/pyproject.toml b/pyproject.toml index a0e3944e..1b6e1bc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot2" -version = "2.0.0a3" +version = "2.0.0a4" description = "An asynchronous python bot framework." authors = ["yanyongyu "] license = "MIT" @@ -24,7 +24,7 @@ include = ["nonebot/py.typed"] [tool.poetry.dependencies] python = "^3.7" -httpx = "^0.13.3" +httpx = "^0.16.1" loguru = "^0.5.1" pygtrie = "^2.3.3" fastapi = "^0.58.1" @@ -32,7 +32,7 @@ uvicorn = "^0.11.5" pydantic = { extras = ["dotenv"], version = "^1.6.1" } apscheduler = { version = "^3.6.3", optional = true } nonebot-test = { version = "^0.1.0", optional = true } -nb-cli = { version="^0.1.0", optional = true } +nb-cli = { version="^0.2.0", optional = true } [tool.poetry.dev-dependencies] yapf = "^0.30.0" From 2a5cfe712f56067b06d51f6a70443d76871bf80d Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Wed, 4 Nov 2020 13:41:52 +0800 Subject: [PATCH 2/2] :memo: update doc version --- archive/2.0.0a3/api/drivers/README.md | 37 -- archive/2.0.0a3/api/drivers/fastapi.md | 16 - archive/{2.0.0a3 => 2.0.0a4}/README.md | 0 archive/{2.0.0a3 => 2.0.0a4}/api/README.md | 3 + .../api/adapters/README.md | 0 .../api/adapters/cqhttp.md | 4 + archive/{2.0.0a3 => 2.0.0a4}/api/config.md | 0 archive/2.0.0a4/api/drivers/README.md | 246 +++++++ archive/2.0.0a4/api/drivers/fastapi.md | 125 ++++ archive/{2.0.0a3 => 2.0.0a4}/api/exception.md | 0 archive/{2.0.0a3 => 2.0.0a4}/api/log.md | 0 archive/{2.0.0a3 => 2.0.0a4}/api/matcher.md | 20 +- archive/{2.0.0a3 => 2.0.0a4}/api/nonebot.md | 0 .../{2.0.0a3 => 2.0.0a4}/api/permission.md | 0 archive/2.0.0a4/api/plugin.md | 629 ++++++++++++++++++ archive/{2.0.0a3 => 2.0.0a4}/api/rule.md | 18 +- archive/{2.0.0a3 => 2.0.0a4}/api/sched.md | 0 archive/{2.0.0a3 => 2.0.0a4}/api/typing.md | 0 archive/{2.0.0a3 => 2.0.0a4}/api/utils.md | 0 archive/{2.0.0a3 => 2.0.0a4}/guide/README.md | 2 + .../guide/basic-configuration.md | 0 .../guide/creating-a-project.md | 0 .../guide/getting-started.md | 4 +- .../guide/installation.md | 3 + .../guide/writing-a-plugin.md | 0 .../{2.0.0a3 => 2.0.0a4}/sidebar.config.json | 9 + docs/.vuepress/versions.json | 2 +- 27 files changed, 1053 insertions(+), 65 deletions(-) delete mode 100644 archive/2.0.0a3/api/drivers/README.md delete mode 100644 archive/2.0.0a3/api/drivers/fastapi.md rename archive/{2.0.0a3 => 2.0.0a4}/README.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/README.md (94%) rename archive/{2.0.0a3 => 2.0.0a4}/api/adapters/README.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/adapters/cqhttp.md (97%) rename archive/{2.0.0a3 => 2.0.0a4}/api/config.md (100%) create mode 100644 archive/2.0.0a4/api/drivers/README.md create mode 100644 archive/2.0.0a4/api/drivers/fastapi.md rename archive/{2.0.0a3 => 2.0.0a4}/api/exception.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/log.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/matcher.md (90%) rename archive/{2.0.0a3 => 2.0.0a4}/api/nonebot.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/permission.md (100%) create mode 100644 archive/2.0.0a4/api/plugin.md rename archive/{2.0.0a3 => 2.0.0a4}/api/rule.md (79%) rename archive/{2.0.0a3 => 2.0.0a4}/api/sched.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/typing.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/api/utils.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/README.md (98%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/basic-configuration.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/creating-a-project.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/getting-started.md (97%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/installation.md (94%) rename archive/{2.0.0a3 => 2.0.0a4}/guide/writing-a-plugin.md (100%) rename archive/{2.0.0a3 => 2.0.0a4}/sidebar.config.json (92%) diff --git a/archive/2.0.0a3/api/drivers/README.md b/archive/2.0.0a3/api/drivers/README.md deleted file mode 100644 index f78812f0..00000000 --- a/archive/2.0.0a3/api/drivers/README.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -contentSidebar: true -sidebarDepth: 0 ---- - -# NoneBot.drivers 模块 - -## 后端驱动适配基类 - -各驱动请继承以下基类 - - -## _class_ `BaseDriver` - -基类:`abc.ABC` - -Driver 基类。将后端框架封装,以满足适配器使用。 - - -### `_adapters` - - -* **类型** - - `Dict[str, Type[Bot]]` - - - -* **说明** - - 已注册的适配器列表 - - - -### _abstract_ `__init__(env, config)` - -Initialize self. See help(type(self)) for accurate signature. diff --git a/archive/2.0.0a3/api/drivers/fastapi.md b/archive/2.0.0a3/api/drivers/fastapi.md deleted file mode 100644 index 029c9bc8..00000000 --- a/archive/2.0.0a3/api/drivers/fastapi.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -contentSidebar: true -sidebarDepth: 0 ---- - -# NoneBot.drivers.fastapi 模块 - - -## _class_ `Driver` - -基类:[`nonebot.drivers.BaseDriver`](#None) - - -### `__init__(env, config)` - -Initialize self. See help(type(self)) for accurate signature. diff --git a/archive/2.0.0a3/README.md b/archive/2.0.0a4/README.md similarity index 100% rename from archive/2.0.0a3/README.md rename to archive/2.0.0a4/README.md diff --git a/archive/2.0.0a3/api/README.md b/archive/2.0.0a4/api/README.md similarity index 94% rename from archive/2.0.0a3/api/README.md rename to archive/2.0.0a4/api/README.md index 52c6e9f6..dcfb548c 100644 --- a/archive/2.0.0a3/api/README.md +++ b/archive/2.0.0a4/api/README.md @@ -10,6 +10,9 @@ * [nonebot.config](config.html) + * [nonebot.plugin](plugin.html) + + * [nonebot.matcher](matcher.html) diff --git a/archive/2.0.0a3/api/adapters/README.md b/archive/2.0.0a4/api/adapters/README.md similarity index 100% rename from archive/2.0.0a3/api/adapters/README.md rename to archive/2.0.0a4/api/adapters/README.md diff --git a/archive/2.0.0a3/api/adapters/cqhttp.md b/archive/2.0.0a4/api/adapters/cqhttp.md similarity index 97% rename from archive/2.0.0a3/api/adapters/cqhttp.md rename to archive/2.0.0a4/api/adapters/cqhttp.md index aae78f86..73b4e044 100644 --- a/archive/2.0.0a3/api/adapters/cqhttp.md +++ b/archive/2.0.0a4/api/adapters/cqhttp.md @@ -405,7 +405,11 @@ CQHTTP 协议 Event 适配。继承属性参考 [BaseEvent](./#class-baseevent) 基类:[`nonebot.adapters.BaseMessageSegment`](#None) +CQHTTP 协议 MessageSegment 适配。具体方法参考协议消息段类型或源码。 + ## _class_ `Message` 基类:[`nonebot.adapters.BaseMessage`](#None) + +CQHTTP 协议 Message 适配。 diff --git a/archive/2.0.0a3/api/config.md b/archive/2.0.0a4/api/config.md similarity index 100% rename from archive/2.0.0a3/api/config.md rename to archive/2.0.0a4/api/config.md diff --git a/archive/2.0.0a4/api/drivers/README.md b/archive/2.0.0a4/api/drivers/README.md new file mode 100644 index 00000000..624220ba --- /dev/null +++ b/archive/2.0.0a4/api/drivers/README.md @@ -0,0 +1,246 @@ +--- +contentSidebar: true +sidebarDepth: 0 +--- + +# NoneBot.drivers 模块 + +## 后端驱动适配基类 + +各驱动请继承以下基类 + + +## _class_ `BaseDriver` + +基类:`abc.ABC` + +Driver 基类。将后端框架封装,以满足适配器使用。 + + +### `_adapters` + + +* **类型** + + `Dict[str, Type[Bot]]` + + + +* **说明** + + 已注册的适配器列表 + + + +### _abstract_ `__init__(env, config)` + + +* **参数** + + + * `env: Env`: 包含环境信息的 Env 对象 + + + * `config: Config`: 包含配置信息的 Config 对象 + + + +### `env` + + +* **类型** + + `str` + + + +* **说明** + + 环境名称 + + + +### `config` + + +* **类型** + + `Config` + + + +* **说明** + + 配置对象 + + + +### `_clients` + + +* **类型** + + `Dict[str, Bot]` + + + +* **说明** + + 已连接的 Bot + + + +### _classmethod_ `register_adapter(name, adapter)` + + +* **说明** + + 注册一个协议适配器 + + + +* **参数** + + + * `name: str`: 适配器名称,用于在连接时进行识别 + + + * `adapter: Type[Bot]`: 适配器 Class + + + +### _abstract property_ `type` + +驱动类型名称 + + +### _abstract property_ `server_app` + +驱动 APP 对象 + + +### _abstract property_ `asgi` + +驱动 ASGI 对象 + + +### _abstract property_ `logger` + +驱动专属 logger 日志记录器 + + +### _property_ `bots` + + +* **类型** + + `Dict[str, Bot]` + + + +* **说明** + + 获取当前所有已连接的 Bot + + + +### _abstract_ `on_startup(func)` + +注册一个在驱动启动时运行的函数 + + +### _abstract_ `on_shutdown(func)` + +注册一个在驱动停止时运行的函数 + + +### _abstract_ `run(host=None, port=None, *args, **kwargs)` + + +* **说明** + + 启动驱动框架 + + + +* **参数** + + + * `host: Optional[str]`: 驱动绑定 IP + + + * `post: Optional[int]`: 驱动绑定端口 + + + * `*args` + + + * `**kwargs` + + + +### _abstract async_ `_handle_http()` + +用于处理 HTTP 类型请求的函数 + + +### _abstract async_ `_handle_ws_reverse()` + +用于处理 WebSocket 类型请求的函数 + + +## _class_ `BaseWebSocket` + +基类:`object` + +WebSocket 连接封装,统一接口方便外部调用。 + + +### _abstract_ `__init__(websocket)` + + +* **参数** + + + * `websocket: Any`: WebSocket 连接对象 + + + +### _property_ `websocket` + +WebSocket 连接对象 + + +### _abstract property_ `closed` + + +* **类型** + + `bool` + + + +* **说明** + + 连接是否已经关闭 + + + +### _abstract async_ `accept()` + +接受 WebSocket 连接请求 + + +### _abstract async_ `close(code)` + +关闭 WebSocket 连接请求 + + +### _abstract async_ `receive()` + +接收一条 WebSocket 信息 + + +### _abstract async_ `send(data)` + +发送一条 WebSocket 信息 diff --git a/archive/2.0.0a4/api/drivers/fastapi.md b/archive/2.0.0a4/api/drivers/fastapi.md new file mode 100644 index 00000000..523b09b2 --- /dev/null +++ b/archive/2.0.0a4/api/drivers/fastapi.md @@ -0,0 +1,125 @@ +--- +contentSidebar: true +sidebarDepth: 0 +--- + +# NoneBot.drivers.fastapi 模块 + +## FastAPI 驱动适配 + +后端使用方法请参考: [FastAPI 文档](https://fastapi.tiangolo.com/) + + +## _class_ `Driver` + +基类:[`nonebot.drivers.BaseDriver`](#None) + +FastAPI 驱动框架 + + +### `__init__(env, config)` + + +* **参数** + + + +* `env: Env`: 包含环境信息的 Env 对象 + + +* `config: Config`: 包含配置信息的 Config 对象 + + +### _property_ `type` + +驱动名称: `fastapi` + + +### _property_ `server_app` + +`FastAPI APP` 对象 + + +### _property_ `asgi` + +`FastAPI APP` 对象 + + +### _property_ `logger` + +fastapi 使用的 logger + + +### `on_startup(func)` + +参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event) + + +### `on_shutdown(func)` + +参考文档: [Events](https://fastapi.tiangolo.com/advanced/events/#startup-event) + + +### `run(host=None, port=None, *, app=None, **kwargs)` + +使用 `uvicorn` 启动 FastAPI + + +### _async_ `_handle_http(adapter, data=Body(Ellipsis), x_self_id=Header(None), x_signature=Header(None), auth=Depends(get_auth_bearer))` + +用于处理 HTTP 类型请求的函数 + + +### _async_ `_handle_ws_reverse(adapter, websocket, x_self_id=Header(None), auth=Depends(get_auth_bearer))` + +用于处理 WebSocket 类型请求的函数 + + +## _class_ `WebSocket` + +基类:[`nonebot.drivers.BaseWebSocket`](#None) + + +### `__init__(websocket)` + + +* **参数** + + + +* `websocket: Any`: WebSocket 连接对象 + + +### _property_ `closed` + + +* **类型** + + `bool` + + + +* **说明** + + 连接是否已经关闭 + + + +### _async_ `accept()` + +接受 WebSocket 连接请求 + + +### _async_ `close(code=1000)` + +关闭 WebSocket 连接请求 + + +### _async_ `receive()` + +接收一条 WebSocket 信息 + + +### _async_ `send(data)` + +发送一条 WebSocket 信息 diff --git a/archive/2.0.0a3/api/exception.md b/archive/2.0.0a4/api/exception.md similarity index 100% rename from archive/2.0.0a3/api/exception.md rename to archive/2.0.0a4/api/exception.md diff --git a/archive/2.0.0a3/api/log.md b/archive/2.0.0a4/api/log.md similarity index 100% rename from archive/2.0.0a3/api/log.md rename to archive/2.0.0a4/api/log.md diff --git a/archive/2.0.0a3/api/matcher.md b/archive/2.0.0a4/api/matcher.md similarity index 90% rename from archive/2.0.0a3/api/matcher.md rename to archive/2.0.0a4/api/matcher.md index c1176030..b061cd64 100644 --- a/archive/2.0.0a3/api/matcher.md +++ b/archive/2.0.0a4/api/matcher.md @@ -377,7 +377,7 @@ sidebarDepth: 0 -### _async classmethod_ `send(message)` +### _async classmethod_ `send(message, **kwargs)` * **说明** @@ -392,8 +392,11 @@ sidebarDepth: 0 * `message: Union[str, Message, MessageSegment]`: 消息内容 + * `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api -### _async classmethod_ `finish(message=None)` + + +### _async classmethod_ `finish(message=None, **kwargs)` * **说明** @@ -408,8 +411,11 @@ sidebarDepth: 0 * `message: Union[str, Message, MessageSegment]`: 消息内容 + * `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api -### _async classmethod_ `pause(prompt=None)` + + +### _async classmethod_ `pause(prompt=None, **kwargs)` * **说明** @@ -424,8 +430,11 @@ sidebarDepth: 0 * `prompt: Union[str, Message, MessageSegment]`: 消息内容 + * `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api -### _async classmethod_ `reject(prompt=None)` + + +### _async classmethod_ `reject(prompt=None, **kwargs)` * **说明** @@ -440,6 +449,9 @@ sidebarDepth: 0 * `prompt: Union[str, Message, MessageSegment]`: 消息内容 + * `**kwargs`: 其他传递给 `bot.send` 的参数,请参考对应 adapter 的 bot 对象 api + + ## _class_ `MatcherGroup` diff --git a/archive/2.0.0a3/api/nonebot.md b/archive/2.0.0a4/api/nonebot.md similarity index 100% rename from archive/2.0.0a3/api/nonebot.md rename to archive/2.0.0a4/api/nonebot.md diff --git a/archive/2.0.0a3/api/permission.md b/archive/2.0.0a4/api/permission.md similarity index 100% rename from archive/2.0.0a3/api/permission.md rename to archive/2.0.0a4/api/permission.md diff --git a/archive/2.0.0a4/api/plugin.md b/archive/2.0.0a4/api/plugin.md new file mode 100644 index 00000000..42cdf84f --- /dev/null +++ b/archive/2.0.0a4/api/plugin.md @@ -0,0 +1,629 @@ +--- +contentSidebar: true +sidebarDepth: 0 +--- + +# NoneBot.plugin 模块 + +## 插件 + +为 NoneBot 插件开发提供便携的定义函数。 + + +## `plugins` + + +* **类型** + + `Dict[str, Plugin]` + + + +* **说明** + + 已加载的插件 + + + +## _class_ `Plugin` + +基类:`object` + +存储插件信息 + + +### `name` + + +* **类型**: `str` + + +* **说明**: 插件名称,使用 文件/文件夹 名称作为插件名 + + +### `module` + + +* **类型**: `ModuleType` + + +* **说明**: 插件模块对象 + + +### `matcher` + + +* **类型**: `Set[Type[Matcher]]` + + +* **说明**: 插件内定义的 `Matcher` + + +## `on(type='', rule=None, permission=None, *, handlers=None, temp=False, priority=1, block=False, state=None)` + + +* **说明** + + 注册一个基础事件响应器,可自定义类型。 + + + +* **参数** + + + * `type: str`: 事件响应器类型 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_metaevent(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)` + + +* **说明** + + 注册一个元事件响应器。 + + + +* **参数** + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_message(rule=None, permission=None, *, handlers=None, temp=False, priority=1, block=True, state=None)` + + +* **说明** + + 注册一个消息事件响应器。 + + + +* **参数** + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_notice(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)` + + +* **说明** + + 注册一个通知事件响应器。 + + + +* **参数** + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_request(rule=None, *, handlers=None, temp=False, priority=1, block=False, state=None)` + + +* **说明** + + 注册一个请求事件响应器。 + + + +* **参数** + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_startswith(msg, rule=None, **kwargs)` + + +* **说明** + + 注册一个消息事件响应器,并且当消息的\*\*文本部分\*\*以指定内容开头时响应。 + + + +* **参数** + + + * `msg: str`: 指定消息开头内容 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_endswith(msg, rule=None, **kwargs)` + + +* **说明** + + 注册一个消息事件响应器,并且当消息的\*\*文本部分\*\*以指定内容结尾时响应。 + + + +* **参数** + + + * `msg: str`: 指定消息结尾内容 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_keyword(keywords, rule=None, **kwargs)` + + +* **说明** + + 注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。 + + + +* **参数** + + + * `keywords: Set[str]`: 关键词列表 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_command(cmd, rule=None, aliases=None, **kwargs)` + + +* **说明** + + 注册一个消息事件响应器,并且当消息以指定命令开头时响应。 + + 命令匹配规则参考: [命令形式匹配](rule.html#command-command) + + + +* **参数** + + + * `cmd: Union[str, Tuple[str, ...]]`: 指定命令内容 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `aliases: Optional[Set[Union[str, Tuple[str, ...]]]]`: 命令别名 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## `on_regex(pattern, flags=0, rule=None, **kwargs)` + + +* **说明** + + 注册一个消息事件响应器,并且当消息匹配正则表达式时响应。 + + 命令匹配规则参考: [正则匹配](rule.html#regex-regex-flags-0) + + + +* **参数** + + + * `pattern: str`: 正则表达式 + + + * `flags: Union[int, re.RegexFlag]`: 正则匹配标志 + + + * `rule: Optional[Union[Rule, RuleChecker]]`: 事件响应规则 + + + * `permission: Optional[Permission]`: 事件响应权限 + + + * `handlers: Optional[List[Handler]]`: 事件处理函数列表 + + + * `temp: bool`: 是否为临时事件响应器(仅执行一次) + + + * `priority: int`: 事件响应器优先级 + + + * `block: bool`: 是否阻止事件向更低优先级传递 + + + * `state: Optional[dict]`: 默认的 state + + + +* **返回** + + + * `Type[Matcher]` + + + +## _class_ `CommandGroup` + +基类:`object` + +命令组,用于声明一组有相同名称前缀的命令。 + + +### `__init__(cmd, **kwargs)` + + +* **参数** + + + * `cmd: Union[str, Tuple[str, ...]]`: 命令前缀 + + + * `**kwargs`: 其他传递给 `on_command` 的参数默认值,参考 [on_command](#on-command-cmd-rule-none-aliases-none-kwargs) + + + +### `basecmd` + + +* **类型**: `Tuple[str, ...]` + + +* **说明**: 命令前缀 + + +### `base_kwargs` + + +* **类型**: `Dict[str, Any]` + + +* **说明**: 其他传递给 `on_command` 的参数默认值 + + +### `command(cmd, **kwargs)` + + +* **说明** + + 注册一个新的命令。 + + + +* **参数** + + + * `cmd: Union[str, Tuple[str, ...]]`: 命令前缀 + + + * `**kwargs`: 其他传递给 `on_command` 的参数,将会覆盖命令组默认值 + + + +* **返回** + + + * `Type[Matcher]` + + + +## `load_plugin(module_path)` + + +* **说明** + + 使用 `importlib` 加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。 + + + +* **参数** + + + * `module_path: str`: 插件名称 `path.to.your.plugin` + + + +* **返回** + + + * `Optional[Plugin]` + + + +## `load_plugins(*plugin_dir)` + + +* **说明** + + 导入目录下多个插件,以 `_` 开头的插件不会被导入! + + + +* **参数** + + + * `*plugin_dir: str`: 插件路径 + + + +* **返回** + + + * `Set[Plugin]` + + + +## `load_builtin_plugins()` + + +* **说明** + + 导入 NoneBot 内置插件 + + + +* **返回** + + + * `Plugin` + + + +## `get_loaded_plugins()` + + +* **说明** + + 获取当前已导入的插件。 + + + +* **返回** + + + * `Set[Plugin]` diff --git a/archive/2.0.0a3/api/rule.md b/archive/2.0.0a4/api/rule.md similarity index 79% rename from archive/2.0.0a3/api/rule.md rename to archive/2.0.0a4/api/rule.md index 2054d04b..dade2a5b 100644 --- a/archive/2.0.0a3/api/rule.md +++ b/archive/2.0.0a4/api/rule.md @@ -123,7 +123,7 @@ Rule(async_function, run_sync(sync_function)) -## `keyword(msg)` +## `keyword(*keywords)` * **说明** @@ -135,23 +135,25 @@ Rule(async_function, run_sync(sync_function)) * **参数** - * `msg: str`: 关键词 + * `*keywords: str`: 关键词 -## `command(command)` +## `command(*cmds)` * **说明** 命令形式匹配,根据配置里提供的 `command_start`, `command_sep` 判断消息是否为命令。 + 可以通过 `state["_prefix"]["command"]` 获取匹配成功的命令(例:`("test",)`),通过 `state["_prefix"]["raw_command"]` 获取匹配成功的原始命令文本(例:`"/test"`)。 + * **参数** - * `command: Tuples[str, ...]`: 命令内容 + * `*cmds: Union[str, Tuple[str, ...]]`: 命令内容 @@ -173,7 +175,9 @@ Rule(async_function, run_sync(sync_function)) * **说明** - 根据正则表达式进行匹配 + 根据正则表达式进行匹配。 + + 可以通过 `state["_matched"]` 获取正则表达式匹配成功的文本。 @@ -186,6 +190,10 @@ Rule(async_function, run_sync(sync_function)) * `flags: Union[int, re.RegexFlag]`: 正则标志 +:::tip 提示 +正则表达式匹配使用 search 而非 match,如需从头匹配请使用 `r"^xxx"` 来确保匹配开头 +::: + ## `to_me()` diff --git a/archive/2.0.0a3/api/sched.md b/archive/2.0.0a4/api/sched.md similarity index 100% rename from archive/2.0.0a3/api/sched.md rename to archive/2.0.0a4/api/sched.md diff --git a/archive/2.0.0a3/api/typing.md b/archive/2.0.0a4/api/typing.md similarity index 100% rename from archive/2.0.0a3/api/typing.md rename to archive/2.0.0a4/api/typing.md diff --git a/archive/2.0.0a3/api/utils.md b/archive/2.0.0a4/api/utils.md similarity index 100% rename from archive/2.0.0a3/api/utils.md rename to archive/2.0.0a4/api/utils.md diff --git a/archive/2.0.0a3/guide/README.md b/archive/2.0.0a4/guide/README.md similarity index 98% rename from archive/2.0.0a3/guide/README.md rename to archive/2.0.0a4/guide/README.md index 86397ee2..43b7f325 100644 --- a/archive/2.0.0a3/guide/README.md +++ b/archive/2.0.0a4/guide/README.md @@ -20,6 +20,8 @@ NoneBot2 是一个可扩展的 Python 异步机器人框架,它会对机器人 ## 它如何工作? + + ~~未填坑~~ ## 特色 diff --git a/archive/2.0.0a3/guide/basic-configuration.md b/archive/2.0.0a4/guide/basic-configuration.md similarity index 100% rename from archive/2.0.0a3/guide/basic-configuration.md rename to archive/2.0.0a4/guide/basic-configuration.md diff --git a/archive/2.0.0a3/guide/creating-a-project.md b/archive/2.0.0a4/guide/creating-a-project.md similarity index 100% rename from archive/2.0.0a3/guide/creating-a-project.md rename to archive/2.0.0a4/guide/creating-a-project.md diff --git a/archive/2.0.0a3/guide/getting-started.md b/archive/2.0.0a4/guide/getting-started.md similarity index 97% rename from archive/2.0.0a3/guide/getting-started.md rename to archive/2.0.0a4/guide/getting-started.md index d52a9396..9c358ead 100644 --- a/archive/2.0.0a3/guide/getting-started.md +++ b/archive/2.0.0a4/guide/getting-started.md @@ -136,11 +136,11 @@ QQ 协议端举例: 现在,尝试向你的 QQ 机器人账号发送如下内容: ```default -/say 你好,世界 +/echo 你好,世界 ``` 到这里如果一切 OK,你应该会收到机器人给你回复了 `你好,世界`。这一历史性的对话标志着你已经成功地运行了一个 NoneBot 的最小实例,开始了编写更强大的 QQ 机器人的创意之旅! - + diff --git a/archive/2.0.0a3/guide/installation.md b/archive/2.0.0a4/guide/installation.md similarity index 94% rename from archive/2.0.0a3/guide/installation.md rename to archive/2.0.0a4/guide/installation.md index 06a88598..4f6e68e1 100644 --- a/archive/2.0.0a3/guide/installation.md +++ b/archive/2.0.0a4/guide/installation.md @@ -6,7 +6,10 @@ 请确保你的 Python 版本 >= 3.7。 ::: +请在安装 nonebot2 之前卸载 nonebot 1.x + ```bash +pip uninstall nonebot pip install nonebot2 ``` diff --git a/archive/2.0.0a3/guide/writing-a-plugin.md b/archive/2.0.0a4/guide/writing-a-plugin.md similarity index 100% rename from archive/2.0.0a3/guide/writing-a-plugin.md rename to archive/2.0.0a4/guide/writing-a-plugin.md diff --git a/archive/2.0.0a3/sidebar.config.json b/archive/2.0.0a4/sidebar.config.json similarity index 92% rename from archive/2.0.0a3/sidebar.config.json rename to archive/2.0.0a4/sidebar.config.json index c68d09ef..54e78eaa 100644 --- a/archive/2.0.0a3/sidebar.config.json +++ b/archive/2.0.0a4/sidebar.config.json @@ -1,4 +1,5 @@ { + "sidebar": {}, "locales": { "/": { "label": "简体中文", @@ -17,6 +18,10 @@ { "text": "API", "link": "/api/" + }, + { + "text": "插件广场", + "link": "/plugin-store" } ], "sidebarDepth": 2, @@ -51,6 +56,10 @@ "title": "nonebot.config 模块", "path": "config" }, + { + "title": "nonebot.plugin 模块", + "path": "plugin" + }, { "title": "nonebot.matcher 模块", "path": "matcher" diff --git a/docs/.vuepress/versions.json b/docs/.vuepress/versions.json index 65abfcfd..56a1527a 100644 --- a/docs/.vuepress/versions.json +++ b/docs/.vuepress/versions.json @@ -1,3 +1,3 @@ [ - "2.0.0a3" + "2.0.0a4" ] \ No newline at end of file