mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-12-27 23:17:02 +00:00
Compare commits
109 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62add13137 | ||
|
|
6eb8f92e5a | ||
|
|
8c4f41f85d | ||
|
|
16ee6faa8d | ||
|
|
9a484ada90 | ||
|
|
945496f9ba | ||
|
|
f7902bb7c7 | ||
|
|
34d3f66c72 | ||
|
|
b776f7a06e | ||
|
|
dbc5f8aba1 | ||
|
|
efa3ac3f4c | ||
|
|
ae3cf2a72f | ||
|
|
ba0b5781c9 | ||
|
|
07f0cc16a1 | ||
|
|
ca9bb2ceef | ||
|
|
c73da124a9 | ||
|
|
c7a9f96368 | ||
|
|
2b18815576 | ||
|
|
dc25f94e49 | ||
|
|
686f045d83 | ||
|
|
a862d6f231 | ||
|
|
4ccda1d43a | ||
|
|
5d6d2d2b12 | ||
|
|
cfc1c1b29b | ||
|
|
fc68a5e4c5 | ||
|
|
84f16fbc43 | ||
|
|
76a38ced81 | ||
|
|
6c130cb45f | ||
|
|
f0bc69bd36 | ||
|
|
f1d867e588 | ||
|
|
fa0bfa7346 | ||
|
|
29720bada8 | ||
|
|
67e5126f6a | ||
|
|
0212247694 | ||
|
|
34aef36bac | ||
|
|
8ea2d4b81f | ||
|
|
c9c50fa0eb | ||
|
|
9dcb734547 | ||
|
|
577d27ef5f | ||
|
|
a6687dc887 | ||
|
|
a27e9b078c | ||
|
|
d75d29b954 | ||
|
|
6ad289274f | ||
|
|
7d87244b3e | ||
|
|
fd0ca2d883 | ||
|
|
45c96cad1a | ||
|
|
8d4822ed21 | ||
|
|
e5194c715b | ||
|
|
f532573458 | ||
|
|
c9c8e4d106 | ||
|
|
58f3325b2c | ||
|
|
456f923cd2 | ||
|
|
66d70b5675 | ||
|
|
c7e57a070a | ||
|
|
948f96d0f2 | ||
|
|
d67238194f | ||
|
|
3c53260f07 | ||
|
|
581ba52fcb | ||
|
|
f7d385be93 | ||
|
|
f4a31a6404 | ||
|
|
e7f0a2466a | ||
|
|
d228c3665c | ||
|
|
fc6aca5394 | ||
|
|
8f62306086 | ||
|
|
10048d401a | ||
|
|
3043b1e2f2 | ||
|
|
debdb55955 | ||
|
|
da7e914c74 | ||
|
|
e854d0ddf8 | ||
|
|
04465ea688 | ||
|
|
24c862843a | ||
|
|
c85b4bcee3 | ||
|
|
34c99bd2c0 | ||
|
|
ddc99eedda | ||
|
|
4c71b8a2a0 | ||
|
|
7cb39acab6 | ||
|
|
933a105348 | ||
|
|
b52905b8ee | ||
|
|
9e9c1a27e5 | ||
|
|
e2463e9e39 | ||
|
|
9681c92bfc | ||
|
|
def8c34918 | ||
|
|
6dc52c9d6b | ||
|
|
a22b8213ef | ||
|
|
e2901debfb | ||
|
|
7e16b034b8 | ||
|
|
a30bfb76ff | ||
|
|
9d6ca5c7eb | ||
|
|
2ac102ea53 | ||
|
|
9fe86f61d6 | ||
|
|
47be1aea18 | ||
|
|
180de00d0b | ||
|
|
fbec37d089 | ||
|
|
9b83cf4945 | ||
|
|
790461d8b7 | ||
|
|
22b848dfcc | ||
|
|
9915e89ceb | ||
|
|
3adc2cc761 | ||
|
|
38d8701d45 | ||
|
|
6633d4d2c9 | ||
|
|
1864269be5 | ||
|
|
df5b21cb9f | ||
|
|
460fb59322 | ||
|
|
0b63ff6e73 | ||
|
|
d1b9dad8f4 | ||
|
|
42e4206916 | ||
|
|
384f99eae6 | ||
|
|
152af6b458 | ||
|
|
e9bf5d6931 |
6
.github/actions/setup-node/action.yml
vendored
6
.github/actions/setup-node/action.yml
vendored
@@ -4,10 +4,10 @@ description: Setup Node
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: "18"
|
||||
cache: "yarn"
|
||||
node-version: lts/*
|
||||
cache: yarn
|
||||
|
||||
- run: yarn install --frozen-lockfile
|
||||
shell: bash
|
||||
|
||||
2
.github/actions/setup-python/action.yml
vendored
2
.github/actions/setup-python/action.yml
vendored
@@ -14,7 +14,7 @@ inputs:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- uses: astral-sh/setup-uv@v6
|
||||
- uses: astral-sh/setup-uv@v7
|
||||
with:
|
||||
python-version: ${{ inputs.python-version }}
|
||||
cache-suffix: ${{ inputs.env-group }}
|
||||
|
||||
4
.github/workflows/codecov.yml
vendored
4
.github/workflows/codecov.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
||||
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
env: [pydantic-v1, pydantic-v2]
|
||||
env:
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
PYDANTIC_VERSION: ${{ matrix.env }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Python environment
|
||||
uses: ./.github/actions/setup-python
|
||||
|
||||
4
.github/workflows/noneflow.yml
vendored
4
.github/workflows/noneflow.yml
vendored
@@ -45,7 +45,7 @@ jobs:
|
||||
private_key: ${{ secrets.APP_KEY }}
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
|
||||
@@ -66,7 +66,7 @@ jobs:
|
||||
PRIVATE_KEY: ${{ secrets.APP_KEY }}
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: noneflow
|
||||
path: artifact/*
|
||||
|
||||
2
.github/workflows/pyright.yml
vendored
2
.github/workflows/pyright.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
fail-fast: false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Python environment
|
||||
uses: ./.github/actions/setup-python
|
||||
|
||||
4
.github/workflows/release-drafter.yml
vendored
4
.github/workflows/release-drafter.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
app_id: ${{ secrets.APP_ID }}
|
||||
private_key: ${{ secrets.APP_KEY }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
|
||||
@@ -70,7 +70,7 @@ jobs:
|
||||
app_id: ${{ secrets.APP_ID }}
|
||||
private_key: ${{ secrets.APP_KEY }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Python Environment
|
||||
uses: ./.github/actions/setup-python
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
app_id: ${{ secrets.APP_ID }}
|
||||
private_key: ${{ secrets.APP_KEY }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
token: ${{ steps.generate-token.outputs.token }}
|
||||
|
||||
|
||||
2
.github/workflows/ruff.yml
vendored
2
.github/workflows/ruff.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
||||
cancel-in-progress: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Run Ruff Lint
|
||||
uses: astral-sh/ruff-action@v3
|
||||
|
||||
2
.github/workflows/website-deploy.yml
vendored
2
.github/workflows/website-deploy.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
cancel-in-progress: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
|
||||
6
.github/workflows/website-preview-cd.yml
vendored
6
.github/workflows/website-preview-cd.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Set Commit Status
|
||||
uses: actions/github-script@v7
|
||||
uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
github.rest.repos.createCommitStatus({
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
})
|
||||
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@v5
|
||||
uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: website-preview
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -78,7 +78,7 @@ jobs:
|
||||
:rocket: Deployed to ${{ steps.deploy.outputs.deploy-url }}
|
||||
|
||||
- name: Set Commit Status
|
||||
uses: actions/github-script@v7
|
||||
uses: actions/github-script@v8
|
||||
if: always()
|
||||
with:
|
||||
script: |
|
||||
|
||||
4
.github/workflows/website-preview-ci.yml
vendored
4
.github/workflows/website-preview-ci.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
cancel-in-progress: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
echo "${{ github.event.pull_request.number }}" > ./pr-number
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v5
|
||||
with:
|
||||
name: website-preview
|
||||
path: |
|
||||
|
||||
@@ -7,7 +7,7 @@ ci:
|
||||
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
|
||||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.12.7
|
||||
rev: v0.14.0
|
||||
hooks:
|
||||
- id: ruff-check
|
||||
args: [--fix]
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
.github/**/*.md
|
||||
website/docs/tutorial/application.mdx
|
||||
|
||||
@@ -129,7 +129,6 @@ NoneBot2 是一个现代、跨平台、可扩展的 Python 聊天机器人框架
|
||||
| 开黑啦([仓库](https://github.com/Tian-que/nonebot-adapter-kaiheila),[协议](https://developer.kookapp.cn/)) | ↗️ | 由社区贡献 |
|
||||
| Ntchat([仓库](https://github.com/JustUndertaker/adapter-ntchat)) | ↗️ | 微信协议,由社区贡献 |
|
||||
| MineCraft([仓库](https://github.com/17TheWord/nonebot-adapter-minecraft)) | ↗️ | 由社区贡献 |
|
||||
| BiliBili Live([仓库](https://github.com/wwweww/adapter-bilibili)) | ↗️ | 由社区贡献 |
|
||||
| Walle-Q([仓库](https://github.com/onebot-walle/nonebot_adapter_walleq)) | ↗️ | QQ 协议,由社区贡献 |
|
||||
| Villa([仓库](https://github.com/CMHopeSunshine/nonebot-adapter-villa)) | ❌ | 米游社大别野 Bot 协议,官方已下线 |
|
||||
| Rocket.Chat([仓库](https://github.com/IUnlimit/nonebot-adapter-rocketchat),[协议](https://developer.rocket.chat/)) | ↗️ | Rocket.Chat Bot 协议,由社区贡献 |
|
||||
@@ -139,6 +138,8 @@ NoneBot2 是一个现代、跨平台、可扩展的 Python 聊天机器人框架
|
||||
| 微信公众平台([仓库](https://github.com/YangRucheng/nonebot-adapter-wxmp),[协议](https://developers.weixin.qq.com/doc/))| ↗️ | 微信公众平台协议,由社区贡献 |
|
||||
| Gewechat([仓库](https://github.com/Shine-Light/nonebot-adapter-gewechat),[协议](https://github.com/Devo919/Gewechat))| ❌ | Gewechat 微信协议,Gewechat不再维护及可用 |
|
||||
| EFChat([仓库](https://github.com/molanp/nonebot_adapter_efchat),[协议](https://irinu-live.melon.fish/efc-help/)) | ↗️ | 恒五聊平台协议,由社区贡献 |
|
||||
| VoceChat ([仓库](https://github.com/5656565566/nonebot-adapter-vocechat),[协议](https://doc.voce.chat/zh-cn/bot/bot-and-webhook)) | ↗️ | VoceChat 平台协议,由社区贡献 |
|
||||
| B站直播间([仓库](https://github.com/MingxuanGame/nonebot-adapter-bilibili-live),[Web API 协议](https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/live),[开放平台协议](https://open-live.bilibili.com/document)) | ↗️ | B站直播间(Web API/开放平台)协议,由社区贡献 |
|
||||
|
||||
- 坚实后盾:支持多种 web 框架,可自定义替换、组合
|
||||
|
||||
|
||||
@@ -313,4 +313,29 @@
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot.adapters.vocechat",
|
||||
"project_link": "nonebot-adapter-vocechat",
|
||||
"name": "nonebot-adapter-vocechat",
|
||||
"desc": "Vocechat 协议适配器",
|
||||
"author_id": 56059687,
|
||||
"homepage": "https://github.com/5656565566/nonebot-adapter-vocechat",
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot.adapters.bilibili_live",
|
||||
"project_link": "nonebot-adapter-bilibili-live",
|
||||
"name": "B站直播间",
|
||||
"desc": "B 站直播间协议(Web API/开放平台)支持",
|
||||
"author_id": 68982190,
|
||||
"homepage": "https://github.com/MingxuanGame/nonebot-adapter-bilibili-live",
|
||||
"tags": [
|
||||
{
|
||||
"label": "bilibili",
|
||||
"color": "#ff6699"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
]
|
||||
|
||||
@@ -743,4 +743,25 @@
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"name": "Amrita",
|
||||
"desc": "LLM聊天机器人框架",
|
||||
"author_id": 67693593,
|
||||
"homepage": "https://github.com/LiteSuggarDEV/Amrita",
|
||||
"tags": [
|
||||
{
|
||||
"label": "聊天",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "LLM",
|
||||
"color": "#5c86db"
|
||||
},
|
||||
{
|
||||
"label": "快捷部署",
|
||||
"color": "#eebe0b"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
]
|
||||
|
||||
@@ -5148,13 +5148,6 @@
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_cnrail",
|
||||
"project_link": "nonebot-plugin-cnrail",
|
||||
"author_id": 59048777,
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_longtu",
|
||||
"project_link": "nonebot-plugin-longtu",
|
||||
@@ -5251,13 +5244,6 @@
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_pingti",
|
||||
"project_link": "nonebot-plugin-pingti",
|
||||
"author_id": 59048777,
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_wx4",
|
||||
"project_link": "nonebot-plugin-wx4",
|
||||
@@ -9444,4 +9430,461 @@
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_value",
|
||||
"project_link": "nonebot-plugin-value",
|
||||
"author_id": 67693593,
|
||||
"tags": [
|
||||
{
|
||||
"label": "value",
|
||||
"color": "#d10a0a"
|
||||
},
|
||||
{
|
||||
"label": "货币",
|
||||
"color": "#3c0eff"
|
||||
},
|
||||
{
|
||||
"label": "经济",
|
||||
"color": "#1b9f1d"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_mcplayer_render",
|
||||
"project_link": "nonebot-plugin-mcplayer-render",
|
||||
"author_id": 49135577,
|
||||
"tags": [
|
||||
{
|
||||
"label": "Minecraft",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_alisten",
|
||||
"project_link": "nonebot-plugin-alisten",
|
||||
"author_id": 5219550,
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_simple_setu",
|
||||
"project_link": "nonebot-plugin-simple-setu",
|
||||
"author_id": 178264759,
|
||||
"tags": [
|
||||
{
|
||||
"label": "pixiv",
|
||||
"color": "#00f5ed"
|
||||
},
|
||||
{
|
||||
"label": "色图",
|
||||
"color": "#ed0823"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot-plugin-anipusher",
|
||||
"project_link": "nonebot-plugin-anipusher",
|
||||
"author_id": 32594985,
|
||||
"tags": [
|
||||
{
|
||||
"label": "Emby",
|
||||
"color": "#0b8a31"
|
||||
},
|
||||
{
|
||||
"label": "AniRss",
|
||||
"color": "#0b8a31"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_huaer_bot",
|
||||
"project_link": "nonebot-plugin-huaer-bot",
|
||||
"author_id": 216365707,
|
||||
"tags": [
|
||||
{
|
||||
"label": "LLM",
|
||||
"color": "#0583b3"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_sell_poor",
|
||||
"project_link": "nonebot-plugin-sell-poor",
|
||||
"author_id": 96647974,
|
||||
"tags": [
|
||||
{
|
||||
"label": "卖弱",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "😭😭😭",
|
||||
"color": "#52eaba"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_abs",
|
||||
"project_link": "nonebot-plugin-abs",
|
||||
"author_id": 64878354,
|
||||
"tags": [
|
||||
{
|
||||
"label": "abstract",
|
||||
"color": "#edf119"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_ImageLibrary",
|
||||
"project_link": "nonebot-plugin-imagelibrary",
|
||||
"author_id": 126797731,
|
||||
"tags": [
|
||||
{
|
||||
"label": "image",
|
||||
"color": "#7629c4"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_exhibitionism",
|
||||
"project_link": "nonebot_plugin_exhibitionism",
|
||||
"author_id": 78413699,
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_akashgen",
|
||||
"project_link": "nonebot-plugin-akashgen",
|
||||
"author_id": 144674902,
|
||||
"tags": [
|
||||
{
|
||||
"label": "绘画",
|
||||
"color": "#98f698"
|
||||
},
|
||||
{
|
||||
"label": "Akash",
|
||||
"color": "#a1eecf"
|
||||
},
|
||||
{
|
||||
"label": "AI",
|
||||
"color": "#78bbf0"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_figurine",
|
||||
"project_link": "nonebot-plugin-figurine",
|
||||
"author_id": 99017826,
|
||||
"tags": [
|
||||
{
|
||||
"label": "figurine",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "手办",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_distributed_blacklist",
|
||||
"project_link": "nonebot-plugin-distributed-blacklist",
|
||||
"author_id": 65720409,
|
||||
"tags": [
|
||||
{
|
||||
"label": "blacklist",
|
||||
"color": "#000000"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_bafortune",
|
||||
"project_link": "nonebot-plugin-bafortune",
|
||||
"author_id": 98072207,
|
||||
"tags": [
|
||||
{
|
||||
"label": "碧蓝档案",
|
||||
"color": "#2b8dce"
|
||||
},
|
||||
{
|
||||
"label": "今日运势",
|
||||
"color": "#ce2b2b"
|
||||
},
|
||||
{
|
||||
"label": "多平台适配",
|
||||
"color": "#c2ce2b"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_repeat_checker",
|
||||
"project_link": "nonebot-plugin-repeat-checker",
|
||||
"author_id": 56631400,
|
||||
"tags": [
|
||||
{
|
||||
"label": "复读",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_quark_autosave",
|
||||
"project_link": "nonebot-plugin-quark-autosave",
|
||||
"author_id": 64878354,
|
||||
"tags": [
|
||||
{
|
||||
"label": "quark",
|
||||
"color": "#593dc3"
|
||||
},
|
||||
{
|
||||
"label": "夸克",
|
||||
"color": "#6542eb"
|
||||
},
|
||||
{
|
||||
"label": "网盘",
|
||||
"color": "#235c84"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_who_is_spy",
|
||||
"project_link": "nonebot-plugin-who-is-spy",
|
||||
"author_id": 144591143,
|
||||
"tags": [
|
||||
{
|
||||
"label": "game",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "游戏",
|
||||
"color": "#ea52cd"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_dst_qq",
|
||||
"project_link": "nonebot-plugin-dst-qq",
|
||||
"author_id": 145603392,
|
||||
"tags": [
|
||||
{
|
||||
"label": "server",
|
||||
"color": "#52ea9d"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_fupan",
|
||||
"project_link": "nonebot-plugin-fupan",
|
||||
"author_id": 867749,
|
||||
"tags": [
|
||||
{
|
||||
"label": "股票",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "打卡",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_algo",
|
||||
"project_link": "nonebot-plugin-algo",
|
||||
"author_id": 188494207,
|
||||
"tags": [
|
||||
{
|
||||
"label": "算法竞赛",
|
||||
"color": "#52c5ea"
|
||||
},
|
||||
{
|
||||
"label": "ACM",
|
||||
"color": "#eb0e31"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_llm_extension",
|
||||
"project_link": "nonebot-plugin-llm-extension",
|
||||
"author_id": 110453675,
|
||||
"tags": [
|
||||
{
|
||||
"label": "🇦🇮",
|
||||
"color": "#f0f0f0"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_htmlkit",
|
||||
"project_link": "nonebot-plugin-htmlkit",
|
||||
"author_id": 50769752,
|
||||
"tags": [
|
||||
{
|
||||
"label": "模板渲染",
|
||||
"color": "#a57021"
|
||||
},
|
||||
{
|
||||
"label": "图片生成",
|
||||
"color": "#74c817"
|
||||
},
|
||||
{
|
||||
"label": "HTML渲染",
|
||||
"color": "#199579"
|
||||
}
|
||||
],
|
||||
"is_official": true
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_mhcodes",
|
||||
"project_link": "nonebot-plugin-mhcodes",
|
||||
"author_id": 99017826,
|
||||
"tags": [
|
||||
{
|
||||
"label": "怪物猎人",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_parser",
|
||||
"project_link": "nonebot-plugin-parser",
|
||||
"author_id": 64878354,
|
||||
"tags": [
|
||||
{
|
||||
"label": "图集",
|
||||
"color": "#263bd5"
|
||||
},
|
||||
{
|
||||
"label": "视频",
|
||||
"color": "#152ac0"
|
||||
},
|
||||
{
|
||||
"label": "解析",
|
||||
"color": "#152ac0"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_kookcardmessage",
|
||||
"project_link": "nonebot-plugin-kookcardmessage",
|
||||
"author_id": 174641131,
|
||||
"tags": [
|
||||
{
|
||||
"label": "kook",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_mcnews",
|
||||
"project_link": "nonebot-plugin-mcnews",
|
||||
"author_id": 110646806,
|
||||
"tags": [
|
||||
{
|
||||
"label": "MC",
|
||||
"color": "#52e7ea"
|
||||
},
|
||||
{
|
||||
"label": "新闻",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_open_file",
|
||||
"project_link": "nonebot-plugin-open-file",
|
||||
"author_id": 131272574,
|
||||
"tags": [
|
||||
{
|
||||
"label": "file",
|
||||
"color": "#a50a0a"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_memory",
|
||||
"project_link": "nonebot-plugin-memory",
|
||||
"author_id": 175703143,
|
||||
"tags": [
|
||||
{
|
||||
"label": "log",
|
||||
"color": "#336daf"
|
||||
},
|
||||
{
|
||||
"label": "func",
|
||||
"color": "#5bd0a2"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_pxchat",
|
||||
"project_link": "nonebot-plugin-pxchat",
|
||||
"author_id": 112293881,
|
||||
"tags": [
|
||||
{
|
||||
"label": "chat",
|
||||
"color": "#52eab7"
|
||||
},
|
||||
{
|
||||
"label": "deepseek",
|
||||
"color": "#52ddea"
|
||||
},
|
||||
{
|
||||
"label": "mcp",
|
||||
"color": "#5292ea"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_daily_bing",
|
||||
"project_link": "nonebot-plugin-daily-bing",
|
||||
"author_id": 122811297,
|
||||
"tags": [],
|
||||
"is_official": false
|
||||
},
|
||||
{
|
||||
"module_name": "nonebot_plugin_ai_turtle_soup",
|
||||
"project_link": "nonebot-plugin-ai-turtle-soup",
|
||||
"author_id": 68174188,
|
||||
"tags": [
|
||||
{
|
||||
"label": "群聊小游戏",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "海龟汤",
|
||||
"color": "#ea5252"
|
||||
},
|
||||
{
|
||||
"label": "AI",
|
||||
"color": "#ea5252"
|
||||
}
|
||||
],
|
||||
"is_official": false
|
||||
},
|
||||
]
|
||||
|
||||
@@ -11,7 +11,7 @@ FrontMatter:
|
||||
|
||||
from collections.abc import Generator
|
||||
from dataclasses import dataclass, is_dataclass
|
||||
from functools import cached_property
|
||||
from functools import cached_property, wraps
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Annotated,
|
||||
@@ -25,13 +25,14 @@ from typing import (
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Self, get_args, get_origin, is_typeddict
|
||||
from typing_extensions import ParamSpec, Self, get_args, get_origin, is_typeddict
|
||||
|
||||
from pydantic import VERSION, BaseModel
|
||||
|
||||
from nonebot.typing import origin_is_annotated
|
||||
|
||||
T = TypeVar("T")
|
||||
P = ParamSpec("P")
|
||||
|
||||
PYDANTIC_V2 = int(VERSION.split(".", 1)[0]) == 2
|
||||
|
||||
@@ -49,13 +50,13 @@ __all__ = (
|
||||
"PYDANTIC_V2",
|
||||
"ConfigDict",
|
||||
"FieldInfo",
|
||||
"LegacyUnionField",
|
||||
"ModelField",
|
||||
"PydanticUndefined",
|
||||
"PydanticUndefinedType",
|
||||
"Required",
|
||||
"TypeAdapter",
|
||||
"custom_validation",
|
||||
"extract_field_info",
|
||||
"field_validator",
|
||||
"model_config",
|
||||
"model_dump",
|
||||
@@ -72,7 +73,7 @@ __autodoc__ = {
|
||||
|
||||
|
||||
if PYDANTIC_V2: # pragma: pydantic-v2
|
||||
from pydantic import GetCoreSchemaHandler
|
||||
from pydantic import Field, GetCoreSchemaHandler
|
||||
from pydantic import TypeAdapter as TypeAdapter
|
||||
from pydantic import field_validator as field_validator
|
||||
from pydantic import model_validator as model_validator
|
||||
@@ -95,7 +96,18 @@ if PYDANTIC_V2: # pragma: pydantic-v2
|
||||
DEFAULT_CONFIG = ConfigDict(extra="allow", arbitrary_types_allowed=True)
|
||||
"""Default config for validations"""
|
||||
|
||||
class FieldInfo(BaseFieldInfo):
|
||||
def _get_legacy_union_field(func: Callable[P, T]) -> Callable[P, T]:
|
||||
@wraps(func)
|
||||
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
|
||||
kwargs["union_mode"] = "left_to_right"
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
LegacyUnionField = _get_legacy_union_field(Field)
|
||||
LegacyUnionField.__doc__ = "Mark field to use legacy left to right union mode"
|
||||
|
||||
class FieldInfo(BaseFieldInfo): # pyright: ignore[reportGeneralTypeIssues]
|
||||
"""FieldInfo class with extra property for compatibility with pydantic v1"""
|
||||
|
||||
# make default can be positional argument
|
||||
@@ -115,6 +127,20 @@ if PYDANTIC_V2: # pragma: pydantic-v2
|
||||
slots = super().__slots__
|
||||
return {k: v for k, v in self._attributes_set.items() if k not in slots}
|
||||
|
||||
@classmethod
|
||||
def _inherit_construct(
|
||||
cls, field_info: Optional[BaseFieldInfo] = None, **kwargs: Any
|
||||
) -> Self:
|
||||
init_kwargs = {}
|
||||
if field_info:
|
||||
init_kwargs.update(field_info._attributes_set)
|
||||
init_kwargs.update(kwargs)
|
||||
|
||||
instance = cls(**init_kwargs)
|
||||
if field_info:
|
||||
instance.metadata = field_info.metadata
|
||||
return instance
|
||||
|
||||
@dataclass
|
||||
class ModelField:
|
||||
"""ModelField class for compatibility with pydantic v1"""
|
||||
@@ -187,13 +213,6 @@ if PYDANTIC_V2: # pragma: pydantic-v2
|
||||
"""Validate the value pass to the field."""
|
||||
return self.type_adapter.validate_python(value)
|
||||
|
||||
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
|
||||
"""Get FieldInfo init kwargs from a FieldInfo instance."""
|
||||
|
||||
kwargs = field_info._attributes_set.copy()
|
||||
kwargs["annotation"] = field_info.rebuild_annotation()
|
||||
return kwargs
|
||||
|
||||
def model_fields(model: type[BaseModel]) -> list[ModelField]:
|
||||
"""Get field list of a model."""
|
||||
|
||||
@@ -201,7 +220,7 @@ if PYDANTIC_V2: # pragma: pydantic-v2
|
||||
ModelField._construct(
|
||||
name=name,
|
||||
annotation=field_info.rebuild_annotation(),
|
||||
field_info=FieldInfo(**extract_field_info(field_info)),
|
||||
field_info=FieldInfo._inherit_construct(field_info),
|
||||
)
|
||||
for name, field_info in model.model_fields.items()
|
||||
]
|
||||
@@ -286,6 +305,8 @@ else: # pragma: pydantic-v1
|
||||
extra = Extra.allow
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
from pydantic.fields import Field as LegacyUnionField
|
||||
|
||||
class FieldInfo(BaseFieldInfo):
|
||||
def __init__(self, default: Any = PydanticUndefined, **kwargs: Any):
|
||||
# preprocess default value to make it compatible with pydantic v2
|
||||
@@ -294,6 +315,22 @@ else: # pragma: pydantic-v1
|
||||
default = PydanticUndefined
|
||||
super().__init__(default, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def _inherit_construct(
|
||||
cls, field_info: Optional[BaseFieldInfo] = None, **kwargs: Any
|
||||
):
|
||||
if field_info:
|
||||
init_kwargs = {
|
||||
s: getattr(field_info, s)
|
||||
for s in field_info.__slots__
|
||||
if s != "extra"
|
||||
}
|
||||
init_kwargs.update(field_info.extra)
|
||||
else:
|
||||
init_kwargs = {}
|
||||
init_kwargs.update(kwargs)
|
||||
return cls(**init_kwargs)
|
||||
|
||||
class ModelField(BaseModelField):
|
||||
@classmethod
|
||||
def _construct(cls, name: str, annotation: Any, field_info: FieldInfo) -> Self:
|
||||
@@ -364,15 +401,6 @@ else: # pragma: pydantic-v1
|
||||
def validate_json(self, value: Union[str, bytes]) -> T:
|
||||
return type_validate_json(self.type, value)
|
||||
|
||||
def extract_field_info(field_info: BaseFieldInfo) -> dict[str, Any]:
|
||||
"""Get FieldInfo init kwargs from a FieldInfo instance."""
|
||||
|
||||
kwargs = {
|
||||
s: getattr(field_info, s) for s in field_info.__slots__ if s != "extra"
|
||||
}
|
||||
kwargs.update(field_info.extra)
|
||||
return kwargs
|
||||
|
||||
@overload
|
||||
def field_validator(
|
||||
field: str,
|
||||
@@ -419,9 +447,7 @@ else: # pragma: pydantic-v1
|
||||
ModelField._construct(
|
||||
name=model_field.name,
|
||||
annotation=model_field.annotation,
|
||||
field_info=FieldInfo(
|
||||
**extract_field_info(model_field.field_info),
|
||||
),
|
||||
field_info=FieldInfo._inherit_construct(model_field.field_info),
|
||||
)
|
||||
for model_field in model.__fields__.values()
|
||||
]
|
||||
|
||||
@@ -30,6 +30,7 @@ from pydantic.networks import IPvAnyAddress
|
||||
from nonebot.compat import (
|
||||
PYDANTIC_V2,
|
||||
ConfigDict,
|
||||
LegacyUnionField,
|
||||
ModelField,
|
||||
PydanticUndefined,
|
||||
PydanticUndefinedType,
|
||||
@@ -51,7 +52,7 @@ class SettingsError(ValueError): ...
|
||||
|
||||
|
||||
class BaseSettingsSource(abc.ABC):
|
||||
def __init__(self, settings_cls: type["BaseSettings"]) -> None:
|
||||
def __init__(self, settings_cls: type[BaseModel]) -> None:
|
||||
self.settings_cls = settings_cls
|
||||
|
||||
@property
|
||||
@@ -67,7 +68,7 @@ class InitSettingsSource(BaseSettingsSource):
|
||||
__slots__ = ("init_kwargs",)
|
||||
|
||||
def __init__(
|
||||
self, settings_cls: type["BaseSettings"], init_kwargs: dict[str, Any]
|
||||
self, settings_cls: type[BaseModel], init_kwargs: dict[str, Any]
|
||||
) -> None:
|
||||
self.init_kwargs = init_kwargs
|
||||
super().__init__(settings_cls)
|
||||
@@ -82,33 +83,17 @@ class InitSettingsSource(BaseSettingsSource):
|
||||
class DotEnvSettingsSource(BaseSettingsSource):
|
||||
def __init__(
|
||||
self,
|
||||
settings_cls: type["BaseSettings"],
|
||||
env_file: Optional[DOTENV_TYPE] = ENV_FILE_SENTINEL,
|
||||
env_file_encoding: Optional[str] = None,
|
||||
case_sensitive: Optional[bool] = None,
|
||||
settings_cls: type[BaseModel],
|
||||
env_file: Optional[DOTENV_TYPE],
|
||||
env_file_encoding: str,
|
||||
case_sensitive: Optional[bool] = False,
|
||||
env_nested_delimiter: Optional[str] = None,
|
||||
) -> None:
|
||||
super().__init__(settings_cls)
|
||||
self.env_file = (
|
||||
env_file
|
||||
if env_file is not ENV_FILE_SENTINEL
|
||||
else self.config.get("env_file", (".env",))
|
||||
)
|
||||
self.env_file_encoding = (
|
||||
env_file_encoding
|
||||
if env_file_encoding is not None
|
||||
else self.config.get("env_file_encoding", "utf-8")
|
||||
)
|
||||
self.case_sensitive = (
|
||||
case_sensitive
|
||||
if case_sensitive is not None
|
||||
else self.config.get("case_sensitive", False)
|
||||
)
|
||||
self.env_nested_delimiter = (
|
||||
env_nested_delimiter
|
||||
if env_nested_delimiter is not None
|
||||
else self.config.get("env_nested_delimiter", None)
|
||||
)
|
||||
self.env_file = env_file
|
||||
self.env_file_encoding = env_file_encoding
|
||||
self.case_sensitive = case_sensitive
|
||||
self.env_nested_delimiter = env_nested_delimiter
|
||||
|
||||
def _apply_case_sensitive(self, var_name: str) -> str:
|
||||
return var_name if self.case_sensitive else var_name.lower()
|
||||
@@ -212,12 +197,33 @@ class DotEnvSettingsSource(BaseSettingsSource):
|
||||
for field in model_fields(self.settings_cls):
|
||||
field_name = field.name
|
||||
env_name = self._apply_case_sensitive(field_name)
|
||||
alias_name = field.field_info.alias
|
||||
alias_env_name = (
|
||||
None if alias_name is None else self._apply_case_sensitive(alias_name)
|
||||
)
|
||||
|
||||
# pydantic use alias name to validate if exist
|
||||
if alias_name is not None:
|
||||
field_name = alias_name
|
||||
|
||||
# try get values from env vars
|
||||
env_val = env_vars.get(env_name, PydanticUndefined)
|
||||
alias_env_val = (
|
||||
PydanticUndefined
|
||||
if alias_env_name is None
|
||||
else env_vars.get(alias_env_name, PydanticUndefined)
|
||||
)
|
||||
# alias env value has higher priority
|
||||
env_val = (
|
||||
env_val
|
||||
if isinstance(alias_env_val, PydanticUndefinedType)
|
||||
else alias_env_val
|
||||
)
|
||||
# delete from file vars when used
|
||||
if env_name in env_file_vars:
|
||||
del env_file_vars[env_name]
|
||||
if alias_env_name is not None and alias_env_name in env_file_vars:
|
||||
del env_file_vars[alias_env_name]
|
||||
|
||||
is_complex, allow_parse_failure = self._field_is_complex(field)
|
||||
if is_complex:
|
||||
@@ -331,25 +337,48 @@ class BaseSettings(BaseModel):
|
||||
_env_nested_delimiter: Optional[str] = None,
|
||||
**values: Any,
|
||||
) -> None:
|
||||
settings_config = model_config(__settings_self__.__class__)
|
||||
env_file = (
|
||||
_env_file
|
||||
if _env_file is not ENV_FILE_SENTINEL
|
||||
else settings_config.get("env_file", (".env",))
|
||||
)
|
||||
env_file_encoding = (
|
||||
_env_file_encoding
|
||||
if _env_file_encoding is not None
|
||||
else settings_config.get("env_file_encoding", "utf-8")
|
||||
)
|
||||
env_nested_delimiter = (
|
||||
_env_nested_delimiter
|
||||
if _env_nested_delimiter is not None
|
||||
else settings_config.get("env_nested_delimiter", None)
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
**__settings_self__._settings_build_values(
|
||||
__settings_self__.__class__,
|
||||
values,
|
||||
env_file=_env_file,
|
||||
env_file_encoding=_env_file_encoding,
|
||||
env_nested_delimiter=_env_nested_delimiter,
|
||||
env_file=env_file,
|
||||
env_file_encoding=env_file_encoding,
|
||||
env_nested_delimiter=env_nested_delimiter,
|
||||
)
|
||||
)
|
||||
|
||||
__settings_self__._env_file = env_file
|
||||
__settings_self__._env_file_encoding = env_file_encoding
|
||||
__settings_self__._env_nested_delimiter = env_nested_delimiter
|
||||
|
||||
@staticmethod
|
||||
def _settings_build_values(
|
||||
self,
|
||||
settings_cls: type[BaseModel],
|
||||
init_kwargs: dict[str, Any],
|
||||
env_file: Optional[DOTENV_TYPE] = None,
|
||||
env_file_encoding: Optional[str] = None,
|
||||
env_nested_delimiter: Optional[str] = None,
|
||||
env_file: Optional[DOTENV_TYPE],
|
||||
env_file_encoding: str,
|
||||
env_nested_delimiter: Optional[str],
|
||||
) -> dict[str, Any]:
|
||||
init_settings = InitSettingsSource(self.__class__, init_kwargs=init_kwargs)
|
||||
init_settings = InitSettingsSource(settings_cls, init_kwargs=init_kwargs)
|
||||
env_settings = DotEnvSettingsSource(
|
||||
self.__class__,
|
||||
settings_cls,
|
||||
env_file=env_file,
|
||||
env_file_encoding=env_file_encoding,
|
||||
env_nested_delimiter=env_nested_delimiter,
|
||||
@@ -396,7 +425,7 @@ class Config(BaseSettings):
|
||||
"""NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的 IP/主机名。"""
|
||||
port: int = Field(default=8080, ge=1, le=65535)
|
||||
"""NoneBot {ref}`nonebot.drivers.ReverseDriver` 服务端监听的端口。"""
|
||||
log_level: Union[int, str] = "INFO"
|
||||
log_level: Union[int, str] = LegacyUnionField(default="INFO")
|
||||
"""NoneBot 日志输出等级,可以为 `int` 类型等级或等级名称。
|
||||
|
||||
参考 [记录日志](https://nonebot.dev/docs/appendices/log),[loguru 日志等级](https://loguru.readthedocs.io/en/stable/api/logger.html#levels)。
|
||||
|
||||
@@ -17,7 +17,7 @@ import anyio
|
||||
from exceptiongroup import BaseExceptionGroup, catch
|
||||
from pydantic.fields import FieldInfo as PydanticFieldInfo
|
||||
|
||||
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined, extract_field_info
|
||||
from nonebot.compat import FieldInfo, ModelField, PydanticUndefined
|
||||
from nonebot.consts import ARG_KEY, REJECT_PROMPT_RESULT_KEY
|
||||
from nonebot.dependencies import Dependent, Param
|
||||
from nonebot.dependencies.utils import check_field_type
|
||||
@@ -194,15 +194,12 @@ class DependParam(Param):
|
||||
use_cache: bool,
|
||||
validate: Union[bool, PydanticFieldInfo],
|
||||
) -> Self:
|
||||
kwargs = {}
|
||||
if isinstance(validate, PydanticFieldInfo):
|
||||
kwargs.update(extract_field_info(validate))
|
||||
|
||||
kwargs["validate"] = bool(validate)
|
||||
kwargs["dependent"] = sub_dependent
|
||||
kwargs["use_cache"] = use_cache
|
||||
|
||||
return cls(**kwargs)
|
||||
return cls._inherit_construct(
|
||||
validate if isinstance(validate, PydanticFieldInfo) else None,
|
||||
dependent=sub_dependent,
|
||||
use_cache=use_cache,
|
||||
validate=bool(validate),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@override
|
||||
|
||||
@@ -47,6 +47,7 @@ from pydantic import BaseModel
|
||||
|
||||
from nonebot import get_driver
|
||||
from nonebot.compat import model_dump, type_validate_python
|
||||
from nonebot.config import BaseSettings
|
||||
|
||||
C = TypeVar("C", bound=BaseModel)
|
||||
|
||||
@@ -172,7 +173,17 @@ def get_available_plugin_names() -> set[str]:
|
||||
|
||||
def get_plugin_config(config: type[C]) -> C:
|
||||
"""从全局配置获取当前插件需要的配置项。"""
|
||||
return type_validate_python(config, model_dump(get_driver().config))
|
||||
global_config = get_driver().config
|
||||
return type_validate_python(
|
||||
config,
|
||||
BaseSettings._settings_build_values(
|
||||
config,
|
||||
model_dump(global_config),
|
||||
env_file=global_config._env_file,
|
||||
env_file_encoding=global_config._env_file_encoding,
|
||||
env_nested_delimiter=global_config._env_nested_delimiter,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
from .load import inherit_supported_adapters as inherit_supported_adapters
|
||||
|
||||
@@ -8,11 +8,13 @@ FrontMatter:
|
||||
"""
|
||||
|
||||
from collections.abc import Iterable
|
||||
from itertools import chain
|
||||
import json
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Optional, Union
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.utils import path_to_module_name
|
||||
|
||||
from . import _managers, _module_name_to_plugin_id, get_plugin
|
||||
@@ -108,6 +110,19 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> set[Plugin]:
|
||||
encoding: 指定 toml 文件编码
|
||||
|
||||
用法:
|
||||
新格式:
|
||||
|
||||
```toml title=pyproject.toml
|
||||
[tool.nonebot]
|
||||
plugin_dirs = ["some_dir"]
|
||||
|
||||
[tool.nonebot.plugins]
|
||||
some-store-plugin = ["some_store_plugin"]
|
||||
"@local" = ["some_local_plugin"]
|
||||
```
|
||||
|
||||
旧格式:
|
||||
|
||||
```toml title=pyproject.toml
|
||||
[tool.nonebot]
|
||||
plugins = ["some_plugin"]
|
||||
@@ -126,11 +141,22 @@ def load_from_toml(file_path: str, encoding: str = "utf-8") -> set[Plugin]:
|
||||
raise ValueError("Cannot find '[tool.nonebot]' in given toml file!")
|
||||
if not isinstance(nonebot_data, dict):
|
||||
raise TypeError("'[tool.nonebot]' must be a Table!")
|
||||
plugins = nonebot_data.get("plugins", [])
|
||||
plugins = nonebot_data.get("plugins", {})
|
||||
plugin_dirs = nonebot_data.get("plugin_dirs", [])
|
||||
assert isinstance(plugins, list), "plugins must be a list of plugin name"
|
||||
assert isinstance(plugins, (list, dict)), (
|
||||
"plugins must be a list or a dict of plugin name"
|
||||
)
|
||||
assert isinstance(plugin_dirs, list), "plugin_dirs must be a list of directories"
|
||||
return load_all_plugins(plugins, plugin_dirs)
|
||||
if isinstance(plugins, list):
|
||||
logger.warning("Legacy project format found! Upgrade with `nb upgrade-format`.")
|
||||
return load_all_plugins(
|
||||
set(
|
||||
chain.from_iterable(plugins.values())
|
||||
if isinstance(plugins, dict)
|
||||
else plugins
|
||||
),
|
||||
plugin_dirs,
|
||||
)
|
||||
|
||||
|
||||
def load_builtin_plugin(name: str) -> Optional[Plugin]:
|
||||
|
||||
@@ -89,7 +89,7 @@ def origin_is_annotated(origin: t.Optional[type[t.Any]]) -> bool:
|
||||
return origin is t_ext.Annotated
|
||||
|
||||
|
||||
NONE_TYPES = {None, type(None), t.Literal[None], t_ext.Literal[None]}
|
||||
NONE_TYPES = {None, type(None), t.Literal[None], t_ext.Literal[None]} # noqa: PYI061
|
||||
if sys.version_info >= (3, 10):
|
||||
NONE_TYPES.add(types.NoneType)
|
||||
|
||||
@@ -104,6 +104,7 @@ if sys.version_info < (3, 12):
|
||||
def is_type_alias_type(type_: type[t.Any]) -> bool:
|
||||
"""判断是否是 TypeAliasType 类型"""
|
||||
return isinstance(type_, t_ext.TypeAliasType)
|
||||
|
||||
else:
|
||||
|
||||
def is_type_alias_type(type_: type[t.Any]) -> bool:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "nonebot2"
|
||||
version = "2.4.3"
|
||||
version = "2.4.4"
|
||||
description = "An asynchronous python bot framework."
|
||||
authors = [{ name = "yanyongyu", email = "yyy@nonebot.dev" }]
|
||||
license = "MIT"
|
||||
@@ -42,7 +42,9 @@ all = [
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"ruff >=0.12.0, <0.13.0",
|
||||
{ include-group = "test" },
|
||||
{ include-group = "docs" },
|
||||
"ruff >=0.14.0, <0.15.0",
|
||||
"nonemoji >=0.1.2, <0.2.0",
|
||||
"pre-commit >=4.0.0, <5.0.0",
|
||||
]
|
||||
@@ -51,7 +53,7 @@ test = [
|
||||
"nonebug >=0.4.1, <0.5.0",
|
||||
"wsproto >=1.2.0, <2.0.0",
|
||||
"werkzeug >=2.3.6, <4.0.0",
|
||||
"pytest-cov >=6.0.0, <7.0.0",
|
||||
"pytest-cov >=7.0.0, <8.0.0",
|
||||
"pytest-xdist >=3.0.2, <4.0.0",
|
||||
"coverage-conditional-plugin >=0.9.0, <0.10.0",
|
||||
]
|
||||
@@ -69,7 +71,6 @@ Funding = "https://afdian.com/@nonebot"
|
||||
|
||||
[tool.uv]
|
||||
required-version = ">=0.8.0"
|
||||
default-groups = ["dev", "test", "docs"]
|
||||
conflicts = [[{ group = "pydantic-v1" }, { group = "pydantic-v2" }]]
|
||||
|
||||
[tool.uv.build-backend]
|
||||
@@ -143,5 +144,5 @@ reportShadowedImports = false
|
||||
disableBytesTypePromotions = true
|
||||
|
||||
[build-system]
|
||||
requires = ["uv_build >=0.8.3, <0.9.0"]
|
||||
requires = ["uv_build >=0.8.3, <0.10.0"]
|
||||
build-backend = "uv_build"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
SIMPLE=simple
|
||||
int_str=123
|
||||
COMPLEX='
|
||||
[1, 2, 3]
|
||||
'
|
||||
@@ -10,6 +11,7 @@ NESTED__C__C=3
|
||||
NESTED__COMPLEX=[1, 2, 3]
|
||||
NESTED_INNER__A=1
|
||||
NESTED_INNER__B=2
|
||||
ALIAS_SIMPLE=aliased_simple
|
||||
OTHER_SIMPLE=simple
|
||||
OTHER_NESTED={"a": 1}
|
||||
OTHER_NESTED__B=2
|
||||
|
||||
3
tests/plugins.legacy.toml
Normal file
3
tests/plugins.legacy.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[tool.nonebot]
|
||||
plugins = []
|
||||
plugin_dirs = []
|
||||
@@ -1,3 +1,5 @@
|
||||
[tool.nonebot]
|
||||
plugins = []
|
||||
plugin_dirs = []
|
||||
|
||||
[tool.nonebot.plugins]
|
||||
"@local" = []
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Optional, Union
|
||||
from pydantic import BaseModel, Field
|
||||
import pytest
|
||||
|
||||
from nonebot.compat import PYDANTIC_V2
|
||||
from nonebot.compat import PYDANTIC_V2, LegacyUnionField
|
||||
from nonebot.config import DOTENV_TYPE, BaseSettings, SettingsConfig, SettingsError
|
||||
|
||||
|
||||
@@ -32,11 +32,13 @@ class Example(BaseSettings):
|
||||
env_nested_delimiter = "__"
|
||||
|
||||
simple: str = ""
|
||||
int_str: Union[int, str] = LegacyUnionField(default="")
|
||||
complex: list[int] = Field(default=[1])
|
||||
complex_none: Optional[list[int]] = None
|
||||
complex_union: Union[int, list[int]] = 1
|
||||
nested: Simple = Simple()
|
||||
nested_inner: Simple = Simple()
|
||||
aliased_simple: str = Field(default="", alias="alias_simple")
|
||||
|
||||
|
||||
class ExampleWithoutDelimiter(Example):
|
||||
@@ -61,6 +63,8 @@ def test_config_with_env():
|
||||
config = Example(_env_file=(".env", ".env.example"))
|
||||
assert config.simple == "simple"
|
||||
|
||||
assert config.int_str == 123
|
||||
|
||||
assert config.complex == [1, 2, 3]
|
||||
|
||||
assert config.complex_none is None
|
||||
@@ -85,6 +89,8 @@ def test_config_with_env():
|
||||
with pytest.raises(AttributeError):
|
||||
config.nested_inner__b
|
||||
|
||||
assert config.aliased_simple == "aliased_simple"
|
||||
|
||||
assert config.common_config == "common"
|
||||
|
||||
assert config.other_simple == "simple"
|
||||
|
||||
@@ -42,6 +42,10 @@ UNKNOWN_PARAM = "Unknown parameter"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.xfail(
|
||||
((3, 13) <= sys.version_info < (3, 13, 8)) or (3, 14) <= sys.version_info,
|
||||
reason="CPython Bug, see python/cpython#137317, python/cpython#137862",
|
||||
)
|
||||
async def test_depend(app: App):
|
||||
from plugins.param.param_depend import (
|
||||
ClassDependency,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
import pytest
|
||||
|
||||
import nonebot
|
||||
from nonebot.plugin import PluginManager, _managers
|
||||
@@ -67,3 +68,27 @@ def test_get_plugin_config():
|
||||
config = nonebot.get_plugin_config(Config)
|
||||
assert isinstance(config, Config)
|
||||
assert config.plugin_config == 1
|
||||
|
||||
|
||||
def test_get_plugin_config_with_env(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("PLUGIN_CONFIG_ONE", "no_dummy_val")
|
||||
monkeypatch.setenv("PLUGIN_SUB_CONFIG__TWO", "two")
|
||||
monkeypatch.setenv("PLUGIN_CFG_THREE", "33")
|
||||
monkeypatch.setenv("CONFIG_FROM_INIT", "impossible")
|
||||
|
||||
class SubConfig(BaseModel):
|
||||
two: str = "dummy_val"
|
||||
|
||||
class Config(BaseModel):
|
||||
plugin_config: int
|
||||
plugin_config_one: str = "dummy_val"
|
||||
plugin_sub_config: SubConfig = Field(default_factory=SubConfig)
|
||||
plugin_config_three: int = Field(default=3, alias="plugin_cfg_three")
|
||||
config_from_init: str = "dummy_val"
|
||||
|
||||
config = nonebot.get_plugin_config(Config)
|
||||
assert config.plugin_config == 1
|
||||
assert config.plugin_config_one == "no_dummy_val"
|
||||
assert config.plugin_sub_config.two == "two"
|
||||
assert config.plugin_config_three == 33
|
||||
assert config.config_from_init == "init"
|
||||
|
||||
@@ -93,6 +93,8 @@ def test_load_json():
|
||||
|
||||
@_recover
|
||||
def test_load_toml():
|
||||
nonebot.load_from_toml("./plugins.legacy.toml")
|
||||
|
||||
nonebot.load_from_toml("./plugins.toml")
|
||||
|
||||
with pytest.raises(ValueError, match="Cannot find"):
|
||||
|
||||
3
tests/uv.lock
generated
Normal file
3
tests/uv.lock
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.12"
|
||||
@@ -84,7 +84,7 @@ export CUSTOM_CONFIG='config in environment variables'
|
||||
那最终 NoneBot 所读取的内容为环境变量中的内容,即 `config in environment variables`。
|
||||
|
||||
:::caution 注意
|
||||
NoneBot 不会自发读取未被定义的配置项的环境变量,如果需要读取某一环境变量需要在 dotenv 配置文件中进行声明。
|
||||
如果一个环境变量既不是 NoneBot 的[**内置配置项**](#内置配置项),也不是任何插件所定义的[**插件配置**](#插件配置),那么 NoneBot 不会自发读取该环境变量,需要在 dotenv 配置文件中先行声明。
|
||||
:::
|
||||
|
||||
### dotenv 配置文件
|
||||
@@ -242,11 +242,17 @@ weather = on_command(
|
||||
|
||||
这种方式可以简洁、高效地读取配置项,同时也可以设置默认值或者在运行时对配置项进行合法性检查,防止由于配置项导致的插件出错等情况出现。
|
||||
|
||||
:::tip 提示
|
||||
:::tip 可配置的事件响应优先级
|
||||
发布插件应该为自身的事件响应器提供可配置的优先级,以便插件使用者可以自定义多个插件间的响应顺序。
|
||||
:::
|
||||
|
||||
由于插件配置项是从全局配置中读取的,通常我们需要在配置项名称前面添加前缀名,以防止配置项冲突。例如在上方的示例中,我们就添加了配置项前缀 `weather_`。但是这样会导致在使用配置项时过长的变量名,因此我们可以使用 `pydantic` 的 `alias` 或者通过配置 scope 来简化配置项名称。这里我们以 scope 配置为例:
|
||||
:::tip 插件配置获取逻辑
|
||||
无论是否在 dotenv 文件中声明了插件配置项,使用 `get_plugin_config` 获取插件配置模型中定义的配置项时都遵循[**配置项的加载**](#配置项的加载)一节中的优先级顺序进行读取。
|
||||
:::
|
||||
|
||||
### 避免插件配置名称冲突
|
||||
|
||||
由于插件配置项是从全局配置和环境变量中读取的,通常我们需要在配置项名称前面添加前缀名,以防止配置项冲突。例如在上方的示例中,我们就添加了配置项前缀 `weather_`。但是这样会导致使用配置项时变量名过长,此时我们可以使用 `pydantic` 的 `alias` 或者通过配置 scope 来简化配置项名称。这里我们以 scope 配置为例:
|
||||
|
||||
```python title=weather/config.py
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -289,7 +289,6 @@ opt2 = Option("--foo", default=OptionResult(value=False, args={"bar": 1}))
|
||||
`Arparma` 有如下属性:
|
||||
|
||||
- 调试类
|
||||
|
||||
- matched: 是否匹配成功
|
||||
- error_data: 解析失败时剩余的数据
|
||||
- error_info: 解析失败时的异常内容
|
||||
|
||||
@@ -150,7 +150,7 @@ async def handle(
|
||||
|
||||
- `xxx: CommandResult`
|
||||
- `xxx: Arparma`:命令的[解析结果](./command.md#解析结果)
|
||||
- `xxx: Duplication`:命令的解析结果的 [`Duplication`](./command.md#Duplication)
|
||||
- `xxx: Duplication`:命令的解析结果的 [`Duplication`](./command.md#duplication)
|
||||
- `xxx: Alconna`:命令的源命令
|
||||
- `<key>: Match[<type>]`:上述的匹配项,使用 `key` 作为查询路径
|
||||
- `xxx: Query[<type>] = Query(<path>, default)`:上述的查询项,必需声明默认值以设置查询路径 `path`
|
||||
|
||||
@@ -159,7 +159,7 @@ async def _(target: MsgTarget):
|
||||
|
||||
事实上,构造 `Target` 对象时,`self_id`, `scope`, `adapter` 和 `platform` 都会参与到 `selector` 的构造中。
|
||||
|
||||
::tip
|
||||
:::tip
|
||||
|
||||
你其实可以使用 `Target` 来帮你筛选 `Bot` 对象:
|
||||
|
||||
|
||||
229
website/docs/best-practice/htmlkit-render.md
Normal file
229
website/docs/best-practice/htmlkit-render.md
Normal file
@@ -0,0 +1,229 @@
|
||||
---
|
||||
sidebar_position: 8
|
||||
description: 轻量化 HTML 绘图
|
||||
---
|
||||
|
||||
# 轻量化 HTML 绘图
|
||||
|
||||
图片是机器人交互中不可或缺的一部分,对于信息展示的直观性、美观性有很大的作用。
|
||||
基于 PIL 直接绘制图片具有良好的性能和存储开销,但是难以调试、维护过程式的绘图代码。
|
||||
使用浏览器渲染类插件可以方便地绘制网页,且能够直接通过 JS 对网页效果进行编程,但是它占用的存储和内存空间相对可观。
|
||||
|
||||
NoneBot 提供的 `nonebot-plugin-htmlkit` 提供了另一种基于 HTML 和 CSS 语法的轻量化绘图选择:它基于 `litehtml` 解析库,无须安装额外的依赖即可使用,没有进程间通信带来的额外开销,且在支持 `webp` `avif` 等丰富图片格式的前提下,安装用的 wheel 文件大小仅有约 10 MB。
|
||||
|
||||
作为粗略的性能参考,在一台 Ryzen 7 9700X 的 Windows 电脑上,渲染 [PEP 7](https://peps.python.org/pep-0007/) 的 HTML 页面(分辨率为 800x5788,大小约 1.4MB,从本地文件系统读取 CSS)大约需要 100ms,每个渲染任务内存最高占用约为 40MB.
|
||||
|
||||
## 安装插件
|
||||
|
||||
在使用前请先安装 `nonebot-plugin-htmlkit` 插件至项目环境中,可参考[获取商店插件](../tutorial/store.mdx#安装插件)来了解并选择安装插件的方式。如:
|
||||
|
||||
在**项目目录**下执行以下命令:
|
||||
|
||||
```bash
|
||||
nb plugin install nonebot-plugin-htmlkit
|
||||
```
|
||||
|
||||
`nonebot-plugin-htmlkit` 插件目前兼容以下系统架构:
|
||||
|
||||
- Windows x64
|
||||
- macOS arm64(M-系列芯片)
|
||||
- Linux x64 (非 Alpine 等 musl 系发行版)
|
||||
- Linux arm64 (非 Alpine 等 musl 系发行版)
|
||||
|
||||
:::caution 访问网络内容
|
||||
|
||||
如果需要访问网络资源(如 http(s) 网页内容),NoneBot 需要客户端型驱动器(Forward)。内置的驱动器有 `~httpx` 与 `~aiohttp`。
|
||||
|
||||
详见[选择驱动器](../advanced/driver.md)。
|
||||
|
||||
:::
|
||||
|
||||
## 使用插件
|
||||
|
||||
### 加载插件
|
||||
|
||||
在使用本插件前同样需要使用 `require` 方法进行**加载**并**导入**需要使用的方法,可参考 [跨插件访问](../advanced/requiring.md) 一节进行了解,如:
|
||||
|
||||
```python
|
||||
from nonebot import require
|
||||
|
||||
require("nonebot_plugin_htmlkit")
|
||||
|
||||
from nonebot_plugin_htmlkit import html_to_pic, md_to_pic, template_to_pic, text_to_pic
|
||||
```
|
||||
|
||||
插件会自动使用[配置中的参数](#配置-fontconfig)初始化 `fontconfig` 以提供字体查找功能。
|
||||
|
||||
### 渲染 API
|
||||
|
||||
`nonebot-plugin-htmlkit` 主要提供以下**异步**渲染函数:
|
||||
|
||||
#### html_to_pic
|
||||
|
||||
```python
|
||||
async def html_to_pic(
|
||||
html: str,
|
||||
*,
|
||||
base_url: str = "",
|
||||
dpi: float = 144.0,
|
||||
max_width: float = 800.0,
|
||||
device_height: float = 600.0,
|
||||
default_font_size: float = 12.0,
|
||||
font_name: str = "sans-serif",
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
lang: str = "zh",
|
||||
culture: str = "CN",
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
css_fetch_fn: CSSFetchFn = combined_css_fetcher,
|
||||
urljoin_fn: Callable[[str, str], str] = urllib3.parse.urljoin,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
最核心的渲染函数。
|
||||
|
||||
`base_url` 和 `urljoin_fn` 控制着传入 `image_fetch_fn` 和 `css_fetch_fn` 回调的 url 内容。
|
||||
|
||||
`allow_refit` 如果为真,渲染时会自动缩小产出图片的宽度到最适合的宽度,否则必定产出 `max_width` 宽度的图片。
|
||||
|
||||
`max_width` 与 `device_height` 会在 `@media` 判断中被使用。
|
||||
|
||||
`img_fetch_fn` 预期为一个异步可调用对象(函数),接收图片 url 并返回对应 url 的 jpeg 或 png 二进制数据(`bytes`),可在拒绝加载时返回 `None`.
|
||||
|
||||
`css_fetch_fn` 预期为一个异步可调用对象(函数),接收目标 CSS url 并返回对应 url 的 CSS 文本(`str`),可在拒绝加载时返回 `None`.
|
||||
|
||||
以下为辅助的封装函数,关键字参数若未特殊说明均与 `html_to_pic` 含义相同。
|
||||
|
||||
#### text_to_pic
|
||||
|
||||
```python
|
||||
async def text_to_pic(
|
||||
text: str,
|
||||
css_path: str = "",
|
||||
*,
|
||||
max_width: int = 500,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
可用于渲染多行文本。
|
||||
|
||||
`text` 会被放置于 `<div id="main" class="main-box"> <div class="text">` 中,可据此编写 CSS 来改变文本表现。
|
||||
|
||||
#### md_to_pic
|
||||
|
||||
```python
|
||||
async def md_to_pic(
|
||||
md: str = "",
|
||||
md_path: str = "",
|
||||
css_path: str = "",
|
||||
*,
|
||||
max_width: int = 500,
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
可用于渲染 Markdown 文本。默认为 GitHub Markdown Light 风格,支持基于 `pygments` 的代码高亮。
|
||||
|
||||
`md` 和 `md_path` 二选一,前者设置时应为 Markdown 的文本,后者设置时应为指向 Markdown 文本文件的路径。
|
||||
|
||||
#### template_to_pic
|
||||
|
||||
```python
|
||||
async def template_to_pic(
|
||||
template_path: str | PathLike[str] | Sequence[str | PathLike[str]],
|
||||
template_name: str,
|
||||
templates: Mapping[Any, Any],
|
||||
filters: None | Mapping[str, Any] = None,
|
||||
*,
|
||||
max_width: int = 500,
|
||||
device_height: int = 600,
|
||||
base_url: str | None = None,
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
css_fetch_fn: CSSFetchFn = combined_css_fetcher,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
渲染 jinja2 模板。
|
||||
|
||||
`template_path` 为 jinja2 环境的路径,`template_name` 是环境中要加载模板的名字,`templates` 为传入模板的参数,`filters` 为过滤器名 -> 自定义过滤器的映射。
|
||||
|
||||
### 控制外部资源获取
|
||||
|
||||
通过传入 `img_fetch_fn` 与 `css_fetch_fn`,我们可以在实际访问资源前进行审查,修改资源的来源,或是对 IO 操作进行缓存。
|
||||
|
||||
`img_fetch_fn` 预期为一个异步可调用对象(函数),接收图片 url 并返回对应 url 的 jpeg 或 png 二进制数据(`bytes`),可在拒绝加载时返回 `None`.
|
||||
|
||||
`css_fetch_fn` 预期为一个异步可调用对象(函数),接收目标 CSS url 并返回对应 url 的 CSS 文本(`str`),可在拒绝加载时返回 `None`.
|
||||
|
||||
如果你想要禁用外部资源加载/只从文件系统加载/只从网络加载,可以使用 `none_fetcher` `filesystem_***_fetcher` `network_***_fetcher`。
|
||||
|
||||
默认的 fetcher 行为(对于 `file://` 从文件系统加载,其余从网络加载)位于 `combined_***_fetcher`,可以通过对其封装实现缓存等操作。
|
||||
|
||||
## 配置项
|
||||
|
||||
### 配置 fontconfig
|
||||
|
||||
`htmlkit` 使用 `fontconfig` 查找字体,请参阅 [`fontconfig 用户手册`](https://fontconfig.pages.freedesktop.org/fontconfig/fontconfig-user) 了解环境变量的具体含义、如何通过编写配置文件修改字体配置等。
|
||||
|
||||
#### fontconfig_file
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的配置文件路径。
|
||||
|
||||
#### fontconfig_path
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的配置目录。
|
||||
|
||||
#### fontconfig_sysroot
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的 sysroot。
|
||||
|
||||
#### fc_debug
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
设置 Fontconfig 的 debug 级别。
|
||||
|
||||
#### fc_dbg_match_filter
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
当 `FC_DEBUG` 设置为 `MATCH2` 时,过滤 debug 输出。
|
||||
|
||||
#### fc_lang
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
设置默认语言,否则从 `LOCALE` 环境变量获取。
|
||||
|
||||
#### fontconfig_use_mmap
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
是否使用 `mmap(2)` 读取字体缓存。
|
||||
@@ -42,7 +42,7 @@ async def handle_function():
|
||||
|
||||
#### 处理近似事件
|
||||
|
||||
对于一系列**差异不大**的事件,我们往往具有相同的处理逻辑。这时,我们不希望将相同的逻辑编写两遍,而应该复用代码,以实现在同一个事件处理函数中处理多个近似事件。我们可以使用[事件重载](../advanced/dependency.mdx#Event)的特性来实现这一功能。例如:
|
||||
对于一系列**差异不大**的事件,我们往往具有相同的处理逻辑。这时,我们不希望将相同的逻辑编写两遍,而应该复用代码,以实现在同一个事件处理函数中处理多个近似事件。我们可以使用[事件重载](../advanced/dependency.mdx#event)的特性来实现这一功能。例如:
|
||||
|
||||
<Tabs groupId="python">
|
||||
<TabItem value="3.10" label="Python 3.10+" default>
|
||||
|
||||
@@ -155,7 +155,6 @@ async def test_example(app: App):
|
||||
1. `should_call_send`
|
||||
|
||||
定义事件响应器预期发送的消息,即通过[事件响应器操作 send](../../appendices/session-control.mdx#send)进行的操作。`should_call_send` 有四个参数:
|
||||
|
||||
- `event`:回复的目标事件。
|
||||
- `message`:预期的消息对象,可以是 `str`、`Message` 或 `MessageSegment`。
|
||||
- `result`:send 的返回值,将会返回给插件。
|
||||
@@ -163,8 +162,7 @@ async def test_example(app: App):
|
||||
- `**kwargs`:send 方法的额外参数。
|
||||
|
||||
2. `should_call_api`
|
||||
定义事件响应器预期调用的平台 API 接口,即通过[调用平台 API](../../appendices/api-calling.mdx#调用平台-API)进行的操作。`should_call_api` 有四个参数:
|
||||
|
||||
定义事件响应器预期调用的平台 API 接口,即通过[调用平台 API](../../appendices/api-calling.mdx#调用平台-api)进行的操作。`should_call_api` 有四个参数:
|
||||
- `api`:API 名称。
|
||||
- `data`:预期的请求数据。
|
||||
- `result`:call_api 的返回值,将会返回给插件。
|
||||
|
||||
@@ -260,7 +260,7 @@ class Adapter(BaseAdapter):
|
||||
更多通信交互方式可以参考以下适配器:
|
||||
|
||||
- [OneBot](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/adapter.py) - `WebSocket 客户端`、`WebSocket 服务端`、`HTTP WEBHOOK`、`HTTP POST`
|
||||
- [QQGuild](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/adapter.py) - `WebSocket 服务端`
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/master/nonebot/adapters/qq/adapter.py) - `WebSocket 服务端`、`HTTP WEBHOOK`
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/adapter.py) - `HTTP WEBHOOK`
|
||||
|
||||
#### 建立 Bot 连接
|
||||
@@ -375,14 +375,16 @@ class Adapter(BaseAdapter):
|
||||
|
||||
Websocket:
|
||||
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/adapter.py#L127)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v12/adapter.py#L162)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/adapter.py#L167-L177)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v12/adapter.py#L204-L218)
|
||||
|
||||
HTTP:
|
||||
|
||||
- [QQ 频道](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/adapter.py#L354)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/adapter.py#L145)
|
||||
- [飞书](https://github.com/nonebot/adapter-feishu/blob/master/nonebot/adapters/feishu/adapter.py#L158)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/adapter.py#L179-L215)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v12/adapter.py#L220-L266)
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/dc5d437e101f0e3db542de3300758a035ed7036e/nonebot/adapters/qq/adapter.py#L599-L605)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/4a8633627e619245516767f5503dec2f58fe2193/nonebot/adapters/telegram/adapter.py#L148-L253)
|
||||
- [飞书](https://github.com/nonebot/adapter-feishu/blob/f8ab05e6d57a5e9013b944b0d019ca777725dfb0/nonebot/adapters/feishu/adapter.py#L201-L218)
|
||||
|
||||
### Bot
|
||||
|
||||
@@ -576,9 +578,9 @@ class Message(BaseMessage[MessageSegment]):
|
||||
|
||||
然后根据平台具体的消息类型,来实现各种 `MessageSegment` 消息段,具体可以参考以下适配器:
|
||||
|
||||
- [OneBot](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/message.py#L77-L261)
|
||||
- [QQGuild](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/message.py#L22-L150)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/message.py#L43-L250)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/message.py#L25-L259)
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/dc5d437e101f0e3db542de3300758a035ed7036e/nonebot/adapters/qq/message.py#L30-L520)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/4a8633627e619245516767f5503dec2f58fe2193/nonebot/adapters/telegram/message.py#L13-L414)
|
||||
|
||||
## 适配器测试
|
||||
|
||||
|
||||
@@ -5,7 +5,62 @@ description: 配置编辑器以获得最佳体验
|
||||
|
||||
# 编辑器支持
|
||||
|
||||
框架基于 [PEP484](https://www.python.org/dev/peps/pep-0484/)、[PEP 561](https://www.python.org/dev/peps/pep-0561/)、[PEP8](https://www.python.org/dev/peps/pep-0008/) 等规范进行开发并且**拥有完整类型注解**。框架使用 Pyright(Pylance)工具进行类型检查,确保代码可以被编辑器正确解析。
|
||||
框架基于 [PEP 484](https://www.python.org/dev/peps/pep-0484/)、[PEP 561](https://www.python.org/dev/peps/pep-0561/)、[PEP 8](https://www.python.org/dev/peps/pep-0008/) 等规范进行开发并且**拥有完整类型注解**。框架使用 Pyright(Pylance)工具进行类型检查,确保代码可以被编辑器正确解析。
|
||||
|
||||
## CLI 脚手架提供的编辑器工具支持
|
||||
|
||||
在使用 NB-CLI [创建项目](./quick-start.mdx#创建项目)时,如果选择了用于插件开发的 `simple` 模板,其会根据选择的开发工具,**自动配置项目根目录下的 `.vscode/extensions.json` 文件**,以推荐最匹配的 VS Code 插件,同时自动将相应的预设配置项写入 `pyproject.toml` 作为“开箱即用”配置,从而提升开发体验。
|
||||
|
||||
```bash
|
||||
[?] 选择一个要使用的模板: simple (插件开发者)
|
||||
...
|
||||
[?] 要使用哪些开发工具?
|
||||
```
|
||||
|
||||
### 支持的开发工具
|
||||
|
||||
1. Pyright (Pylance)
|
||||
|
||||
[VS Code 插件](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) | [项目](https://github.com/microsoft/pyright) | [文档](https://microsoft.github.io/pyright/)
|
||||
|
||||
由微软开发的 Python 静态类型检查器和语言服务器,提供智能感知、跳转定义、查找引用、实时错误检查等强大功能。
|
||||
|
||||
作为 VS Code 官方推荐的 Python 语言服务器,与 Pylance 扩展配合使用,能提供最流畅、最准确的代码补全和类型推断体验,是绝大多数开发者的首选。
|
||||
|
||||
2. Ruff
|
||||
|
||||
[VS Code 插件](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) | [项目](https://github.com/astral-sh/ruff) | [文档](https://docs.astral.sh/ruff/)
|
||||
|
||||
一个用 Rust 编写的超快 Python 代码格式化和 lint 工具,完全兼容 `black`、`isort`、`flake8` 等主流工具的规则。
|
||||
|
||||
速度极快(比 `black` 和 `flake8` 快 100 倍以上),配置简单,能自动格式化代码并检测潜在错误、代码风格问题(尤其是误用同步网络请求库),是提升代码质量和开发效率的必备利器。
|
||||
|
||||
3. MyPy
|
||||
|
||||
[VS Code 插件](https://marketplace.visualstudio.com/items?itemName=matangover.mypy) | [项目](https://github.com/python/mypy) | [文档](https://mypy.readthedocs.io/en/stable/index.html)
|
||||
|
||||
一个官方实现的 Python 静态类型检查器,通过分析代码中的类型注解来发现类型错误。
|
||||
|
||||
4. BasedPyright
|
||||
|
||||
[VS Code 插件](https://marketplace.visualstudio.com/items?itemName=detachhead.basedpyright) | [项目](https://github.com/DetachHead/basedpyright) | [文档](https://docs.basedpyright.com/)
|
||||
|
||||
一个基于 Pyright 的、由社区维护的替代性 Python 语言服务器,旨在提供更优的类型检查支持与接近 Pylance 的更好的使用体验。
|
||||
|
||||
相较于 Pylance,BasedPyright 允许配合 VS Code 之外的其他编辑器使用,同时也复刻了部分 Pylance 限定的功能。
|
||||
|
||||
如果您是高级用户,希望尝试 Pylance 的替代方案,或遇到 Pylance 在特定环境下的兼容性问题,可以考虑使用 BasedPyright。
|
||||
|
||||
:::caution 提示
|
||||
为避免 `Pylance` 和 `BasedPyright` 相互冲突导致配置混乱甚至异常,脚手架默认不允许在创建项目时同时配置这两者。
|
||||
|
||||
如果确实需要同时使用,请在创建项目时选择 Pylance/Pyright 并根据[相关文档](https://docs.basedpyright.com/latest/installation/ides/#vscode-vscodium)进行手动配置。
|
||||
:::
|
||||
|
||||
### 配置效果
|
||||
|
||||
选择上述工具后,NB-CLI 会在您的项目根目录下生成一个 `.vscode/extensions.json` 文件并在 `pyproject.toml` 文件中写入相应的配置项。当您在 VS Code 中打开此项目时,IDE
|
||||
会自动弹出提示,建议您安装这些推荐的扩展,一键即可完成开发环境的初始化,让您可以立即开始编写代码,无需手动搜索和安装插件。
|
||||
|
||||
## 编辑器推荐配置
|
||||
|
||||
|
||||
@@ -81,8 +81,9 @@ nb create
|
||||
请注意,多选项使用**空格**选中或取消,**回车**确认。
|
||||
|
||||
```bash
|
||||
[?] 要使用哪些驱动器? FastAPI (FastAPI 驱动器)
|
||||
[?] 要使用哪些适配器? Console (基于终端的交互式适配器)
|
||||
[?] 要使用哪些驱动器? FastAPI (FastAPI 驱动器)
|
||||
[?] 要使用什么本地存储策略? 用户全局 (默认,适用于单用户下单实例)
|
||||
[?] 立即安装依赖? (Y/n) Yes
|
||||
[?] 创建虚拟环境? (Y/n) Yes
|
||||
```
|
||||
|
||||
@@ -10,6 +10,9 @@ options:
|
||||
|
||||
# 手动创建项目
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
在[快速上手](../quick-start.mdx)中,我们已经介绍了如何安装和使用 `nb-cli` 创建一个项目。在本章节中,我们将简要介绍如何在不使用 `nb-cli` 的方式创建一个机器人项目的**最小实例**并启动。如果你想要了解 NoneBot 的启动流程,也可以阅读本章节。
|
||||
|
||||
:::caution 警告
|
||||
@@ -30,23 +33,51 @@ options:
|
||||
|
||||
1. (可选)创建虚拟环境,以 venv 为例
|
||||
|
||||
<Tabs groupId="platform">
|
||||
<TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv .venv --prompt nonebot2
|
||||
# windows
|
||||
# 激活虚拟环境
|
||||
.venv\Scripts\activate
|
||||
# linux/macOS
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv .venv --prompt nonebot2
|
||||
# 激活虚拟环境
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
2. 安装 nonebot2 以及驱动器
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
2. 安装 nonebot2 以及驱动器,以 Fastapi 驱动器为例
|
||||
|
||||
<Tabs groupId="platform">
|
||||
<TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
pip install 'nonebot2[fastapi]'
|
||||
pip install "nonebot2[fastapi]"
|
||||
```
|
||||
|
||||
驱动器包名可以在 [驱动器商店](/store/drivers) 中找到。
|
||||
</TabItem>
|
||||
<TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
3. 安装适配器
|
||||
```bash
|
||||
pip install "nonebot2[fastapi]"
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
驱动器包名可以在 [驱动器商店](/store/drivers) 中找到,请替换上文方括号中的内容。
|
||||
|
||||
3. 安装适配器,以 Console 适配器为例
|
||||
|
||||
```bash
|
||||
pip install nonebot-adapter-console
|
||||
@@ -58,7 +89,7 @@ options:
|
||||
|
||||
配置文件用于存放 NoneBot 运行所需要的配置项,使用 [`pydantic`](https://docs.pydantic.dev/) 以及 [`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。配置项需符合 dotenv 格式,复杂类型数据需使用 JSON 格式填写。具体可选配置方式以及配置项详情参考[配置](../appendices/config.mdx)。
|
||||
|
||||
在**项目文件夹**中创建一个 `.env` 文本文件,并写入以下内容:
|
||||
在**项目文件夹**中创建一个名为 `.env` 的文件,并写入以下内容:
|
||||
|
||||
```bash title=.env
|
||||
HOST=0.0.0.0 # 配置 NoneBot 监听的 IP / 主机名
|
||||
@@ -101,10 +132,29 @@ if __name__ == "__main__":
|
||||
|
||||
## 运行机器人
|
||||
|
||||
在**项目文件夹**中,使用配置好环境的 Python 解释器运行入口文件(如果使用虚拟环境,请先激活虚拟环境):
|
||||
在**项目文件夹**中,使用配置好环境的 Python 解释器运行入口文件:
|
||||
|
||||
<Tabs groupId="platform">
|
||||
<TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
# 激活虚拟环境(未使用虚拟环境时跳过此行)
|
||||
.venv\Scripts\activate
|
||||
# 运行机器人
|
||||
python bot.py
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
```bash
|
||||
# 激活虚拟环境(未使用虚拟环境时跳过此行)
|
||||
source .venv/bin/activate
|
||||
# 运行机器人
|
||||
python bot.py
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
如果你后续使用了 `nb-cli` ,你仍可以使用 `nb run` 命令来运行机器人,`nb-cli` 会自动检测入口文件 `bot.py` 是否存在并运行。同时,你也可以使用 `nb run --reload` 来自动检测代码的更改并自动重新运行入口文件。
|
||||
@@ -64,7 +64,7 @@ options:
|
||||
:::
|
||||
|
||||
:::caution 注意
|
||||
如果在之前的[创建项目](./application.md)章节中手动创建了相关文件,那么你需要做出如下修改:
|
||||
如果在之前的[创建项目](./application.mdx)章节中手动创建了相关文件,那么你需要做出如下修改:
|
||||
|
||||
1. 在项目目录中创建一个两层文件夹 `awesome_bot/plugins`
|
||||
|
||||
@@ -189,12 +189,16 @@ nonebot.load_from_json("plugin_config.json", encoding="utf-8")
|
||||
|
||||
### `load_from_toml`
|
||||
|
||||
通过 TOML 文件加载插件,是 [`load_all_plugins`](#load_all_plugins) 的 TOML 变种。通过读取 TOML 文件中的 `[tool.nonebot]` Table 中的 `plugins` 和 `plugin_dirs` Array 进行加载。例如:
|
||||
通过 TOML 文件加载插件,是 [`load_all_plugins`](#load_all_plugins) 的 TOML 变种。通过读取 TOML 文件中的 `[tool.nonebot]` Table 中的 `plugin_dirs` Array 与
|
||||
`[tool.nonebot.plugins]` Table 中的多个 Array 进行加载。例如:
|
||||
|
||||
```toml title=plugin_config.toml
|
||||
[tool.nonebot]
|
||||
plugins = ["path.to.your.plugin"]
|
||||
plugin_dirs = ["path/to/your/plugins"]
|
||||
|
||||
[tool.nonebot.plugins]
|
||||
"@local" = ["path.to.your.plugin"] # 本地插件等非插件商店来源的插件
|
||||
"nonebot-plugin-someplugin" = ["nonebot_plugin_someplugin"] # 插件商店来源的插件
|
||||
```
|
||||
|
||||
```python
|
||||
|
||||
@@ -24,6 +24,9 @@ NoneBot 提供了一个[商店](/store/plugins),商店内容均由社区开发
|
||||
|
||||
商店中每个内容的卡片都包含了其名称和简介等信息,点击**卡片右上角**链接图标即可跳转到其主页。
|
||||
|
||||
与此同时,NB-CLI 也提供了一个 TUI 版本的商店界面,可通过 `nb adapter store`、`nb plugin store`、`nb driver store` 命令或 CLI
|
||||
交互式界面进入。其提供了接近网页商店的体验,同时允许快捷安装到当前项目。
|
||||
|
||||
## 安装插件
|
||||
|
||||
<Asciinema
|
||||
|
||||
@@ -300,6 +300,7 @@ export default async function createConfigAsync() {
|
||||
|
||||
future: {
|
||||
experimental_faster: true,
|
||||
v4: true,
|
||||
},
|
||||
|
||||
plugins: [
|
||||
|
||||
@@ -5,6 +5,80 @@ toc_max_heading_level: 2
|
||||
|
||||
# 更新日志
|
||||
|
||||
## v2.4.4
|
||||
|
||||
### 🚀 新功能
|
||||
|
||||
- Feature: 允许插件从环境变量中读取配置项并支持 alias [@AzideCupric](https://github.com/AzideCupric) ([#3673](https://github.com/nonebot/nonebot2/pull/3673))
|
||||
- Feature: 更新 NB-CLI 新版插件加载格式与文档 [@NCBM](https://github.com/NCBM) ([#3614](https://github.com/nonebot/nonebot2/pull/3614))
|
||||
|
||||
### 🐛 Bug 修复
|
||||
|
||||
- Fix: log level 配置项无法使用 int 类型配置 [@yanyongyu](https://github.com/yanyongyu) ([#3732](https://github.com/nonebot/nonebot2/pull/3732))
|
||||
- Fix: 兼容 pydantic v2.12 `FieldInfo` 改动 [@yanyongyu](https://github.com/yanyongyu) ([#3722](https://github.com/nonebot/nonebot2/pull/3722))
|
||||
|
||||
### 📝 文档
|
||||
|
||||
- Docs: 更新适配器编写指南中的链接 [@xjh2009](https://github.com/xjh2009) ([#3731](https://github.com/nonebot/nonebot2/pull/3731))
|
||||
- Feature: 更新 NB-CLI 新版插件加载格式与文档 [@NCBM](https://github.com/NCBM) ([#3614](https://github.com/nonebot/nonebot2/pull/3614))
|
||||
- Docs: 添加 htmlkit 文档至最佳实践 [@BlueGlassBlock](https://github.com/BlueGlassBlock) ([#3682](https://github.com/nonebot/nonebot2/pull/3682))
|
||||
- Docs: 修复 userinfo 插件链接 [@XieXiLin2](https://github.com/XieXiLin2) ([#3660](https://github.com/nonebot/nonebot2/pull/3660))
|
||||
- Docs: 升级 docusaurus 3.8.1 [@StarHeartHunt](https://github.com/StarHeartHunt) ([#3649](https://github.com/nonebot/nonebot2/pull/3649))
|
||||
- Docs: 更新文档《手动创建项目》 [@Chen-Luan](https://github.com/Chen-Luan) ([#3623](https://github.com/nonebot/nonebot2/pull/3623))
|
||||
- Docs: 增加 B站直播间 适配器说明 [@MingxuanGame](https://github.com/MingxuanGame) ([#3636](https://github.com/nonebot/nonebot2/pull/3636))
|
||||
- Docs: 增加 VoceChat 适配器说明 [@5656565566](https://github.com/5656565566) ([#3627](https://github.com/nonebot/nonebot2/pull/3627))
|
||||
|
||||
### 💫 杂项
|
||||
|
||||
- CI: 严格约束 `test_depend` CPython 版本范围 [@StarHeartHunt](https://github.com/StarHeartHunt) ([#3713](https://github.com/nonebot/nonebot2/pull/3713))
|
||||
- CI: 升级文档构建 node 版本 [@StarHeartHunt](https://github.com/StarHeartHunt) ([#3668](https://github.com/nonebot/nonebot2/pull/3668))
|
||||
- CI: 测试矩阵加入 Python 3.13 [@StarHeartHunt](https://github.com/StarHeartHunt) ([#3605](https://github.com/nonebot/nonebot2/pull/3605))
|
||||
|
||||
### 🍻 插件发布
|
||||
|
||||
- Plugin: 海龟汤游戏 [@noneflow](https://github.com/noneflow) ([#3697](https://github.com/nonebot/nonebot2/pull/3697))
|
||||
- Plugin: 每日必应壁纸 [@noneflow](https://github.com/noneflow) ([#3721](https://github.com/nonebot/nonebot2/pull/3721))
|
||||
- Plugin: pxchat [@noneflow](https://github.com/noneflow) ([#3712](https://github.com/nonebot/nonebot2/pull/3712))
|
||||
- Plugin: nonebot-plugin-memory [@noneflow](https://github.com/noneflow) ([#3701](https://github.com/nonebot/nonebot2/pull/3701))
|
||||
- Plugin: 远程文件打开 [@noneflow](https://github.com/noneflow) ([#3717](https://github.com/nonebot/nonebot2/pull/3717))
|
||||
- Plugin: MC新闻更新检测 [@noneflow](https://github.com/noneflow) ([#3699](https://github.com/nonebot/nonebot2/pull/3699))
|
||||
- Plugin: kook卡片消息编写适配插件 [@noneflow](https://github.com/noneflow) ([#3708](https://github.com/nonebot/nonebot2/pull/3708))
|
||||
- Plugin: 链接分享自动解析 [@noneflow](https://github.com/noneflow) ([#3706](https://github.com/nonebot/nonebot2/pull/3706))
|
||||
- Plugin: 怪物猎人集会码插件 [@noneflow](https://github.com/noneflow) ([#3684](https://github.com/nonebot/nonebot2/pull/3684))
|
||||
- Plugin: nonebot-plugin-htmlkit [@noneflow](https://github.com/noneflow) ([#3695](https://github.com/nonebot/nonebot2/pull/3695))
|
||||
- Plugin: 言令 [@noneflow](https://github.com/noneflow) ([#3675](https://github.com/nonebot/nonebot2/pull/3675))
|
||||
- Plugin: 算法比赛助手 [@noneflow](https://github.com/noneflow) ([#3672](https://github.com/nonebot/nonebot2/pull/3672))
|
||||
- Plugin: 复盘打卡 [@noneflow](https://github.com/noneflow) ([#3681](https://github.com/nonebot/nonebot2/pull/3681))
|
||||
- Plugin: DMP 饥荒管理平台机器人 [@noneflow](https://github.com/noneflow) ([#3616](https://github.com/nonebot/nonebot2/pull/3616))
|
||||
- Plugin: 谁是卧底小游戏 [@noneflow](https://github.com/noneflow) ([#3629](https://github.com/nonebot/nonebot2/pull/3629))
|
||||
- Plugin: 夸克自动转存 [@noneflow](https://github.com/noneflow) ([#3671](https://github.com/nonebot/nonebot2/pull/3671))
|
||||
- Plugin: 禁止复读 [@noneflow](https://github.com/noneflow) ([#3644](https://github.com/nonebot/nonebot2/pull/3644))
|
||||
- Plugin: 蔚蓝档案今日运势 [@noneflow](https://github.com/noneflow) ([#3653](https://github.com/nonebot/nonebot2/pull/3653))
|
||||
- Plugin: 分布式黑名单插件 [@noneflow](https://github.com/noneflow) ([#3655](https://github.com/nonebot/nonebot2/pull/3655))
|
||||
- Plugin: 图片手办化 [@noneflow](https://github.com/noneflow) ([#3662](https://github.com/nonebot/nonebot2/pull/3662))
|
||||
- Plugin: Akash Image Generator [@noneflow](https://github.com/noneflow) ([#3651](https://github.com/nonebot/nonebot2/pull/3651))
|
||||
- Plugin: 让我看看!! [@noneflow](https://github.com/noneflow) ([#3648](https://github.com/nonebot/nonebot2/pull/3648))
|
||||
- Plugin: ImageLibrary [@noneflow](https://github.com/noneflow) ([#3620](https://github.com/nonebot/nonebot2/pull/3620))
|
||||
- Plugin: 抽象 [@noneflow](https://github.com/noneflow) ([#3638](https://github.com/nonebot/nonebot2/pull/3638))
|
||||
- Plugin: 卖若插件 [@noneflow](https://github.com/noneflow) ([#3631](https://github.com/nonebot/nonebot2/pull/3631))
|
||||
- Plugin: HuaEr聊天bot [@noneflow](https://github.com/noneflow) ([#3564](https://github.com/nonebot/nonebot2/pull/3564))
|
||||
- Plugin: Remove nonebot_plugin_cnrail [@noneflow](https://github.com/noneflow) ([#3645](https://github.com/nonebot/nonebot2/pull/3645))
|
||||
- Plugin: Remove nonebot_plugin_pingti [@noneflow](https://github.com/noneflow) ([#3646](https://github.com/nonebot/nonebot2/pull/3646))
|
||||
- Plugin: Anipusher推送机 [@noneflow](https://github.com/noneflow) ([#3582](https://github.com/nonebot/nonebot2/pull/3582))
|
||||
- Plugin: nonebot-plugin-simple-setu [@noneflow](https://github.com/noneflow) ([#3594](https://github.com/nonebot/nonebot2/pull/3594))
|
||||
- Plugin: Alisten [@noneflow](https://github.com/noneflow) ([#3635](https://github.com/nonebot/nonebot2/pull/3635))
|
||||
- Plugin: MC玩家皮肤渲染 [@noneflow](https://github.com/noneflow) ([#3613](https://github.com/nonebot/nonebot2/pull/3613))
|
||||
- Plugin: EconomyValue [@noneflow](https://github.com/noneflow) ([#3566](https://github.com/nonebot/nonebot2/pull/3566))
|
||||
|
||||
### 🍻 机器人发布
|
||||
|
||||
- Bot: Amrita [@noneflow](https://github.com/noneflow) ([#3641](https://github.com/nonebot/nonebot2/pull/3641))
|
||||
|
||||
### 🍻 适配器发布
|
||||
|
||||
- Adapter: B站直播间 [@noneflow](https://github.com/noneflow) ([#3592](https://github.com/nonebot/nonebot2/pull/3592))
|
||||
- Adapter: nonebot-adapter-vocechat [@noneflow](https://github.com/noneflow) ([#3536](https://github.com/nonebot/nonebot2/pull/3536))
|
||||
|
||||
## v2.4.3
|
||||
|
||||
### 🚀 新功能
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
description: Alconna 命令解析拓展
|
||||
|
||||
slug: /best-practice/alconna/
|
||||
---
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
# Alconna 插件
|
||||
|
||||
[`nonebot-plugin-alconna`](https://github.com/nonebot/plugin-alconna) 是一类提供了拓展响应规则的插件。
|
||||
该插件使用 [Alconna](https://github.com/ArcletProject/Alconna) 作为命令解析器,
|
||||
是一个简单、灵活、高效的命令参数解析器,并且不局限于解析命令式字符串。
|
||||
|
||||
该插件提供了一类新的事件响应器辅助函数 `on_alconna`,以及 `AlconnaResult` 等依赖注入函数。
|
||||
|
||||
该插件声明了一个 `Matcher` 的子类 `AlconnaMatcher`,并在 `AlconnaMatcher` 中添加了一些新的方法,例如:
|
||||
|
||||
- `assign`:基于 `Alconna` 解析结果,执行满足目标路径的处理函数
|
||||
- `dispatch`:类似 `CommandGroup`,对目标路径创建一个新的 `AlconnaMatcher`,并将解析结果分配给该 `AlconnaMatcher`
|
||||
- `got_path`:类似 `got`,但是可以指定目标路径,并且能够验证解析结果是否可用
|
||||
- ...
|
||||
|
||||
基于 `Alconna` 的特性,该插件同时提供了一系列便捷的消息段标注。
|
||||
标注可用于在 `Alconna` 中匹配消息中除 text 外的其他消息段,也可用于快速创建各适配器下的消息段。所有标注位于 `nonebot_plugin_alconna.adapters` 中。
|
||||
|
||||
该插件同时通过提供 `UniMessage` (通用消息模型) 实现了**跨平台接收和发送消息**的功能。
|
||||
|
||||
## 安装插件
|
||||
|
||||
在使用前请先安装 `nonebot-plugin-alconna` 插件至项目环境中,可参考[获取商店插件](../../tutorial/store.mdx#安装插件)来了解并选择安装插件的方式。如:
|
||||
|
||||
在**项目目录**下执行以下命令:
|
||||
|
||||
<Tabs groupId="install">
|
||||
<TabItem value="cli" label="使用 nb-cli">
|
||||
|
||||
```shell
|
||||
nb plugin install nonebot-plugin-alconna
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="pip" label="使用 pip">
|
||||
|
||||
```shell
|
||||
pip install nonebot-plugin-alconna
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="pdm" label="使用 pdm">
|
||||
|
||||
```shell
|
||||
pdm add nonebot-plugin-alconna
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## 导入插件
|
||||
|
||||
由于 `nonebot-plugin-alconna` 作为插件,因此需要在使用前对其进行**加载**并**导入**其中的 `on_alconna` 来使用命令拓展。使用 `require` 方法可轻松完成这一过程,可参考 [跨插件访问](../../advanced/requiring.md) 一节进行了解。
|
||||
|
||||
```python
|
||||
from nonebot import require
|
||||
|
||||
require("nonebot_plugin_alconna")
|
||||
|
||||
from nonebot_plugin_alconna import on_alconna
|
||||
```
|
||||
|
||||
## 使用插件
|
||||
|
||||
在前面的[深入指南](../../appendices/session-control.mdx)中,我们已经得到了一个天气插件。
|
||||
现在我们将使用 `Alconna` 来改写这个插件。
|
||||
|
||||
<details>
|
||||
<summary>插件示例</summary>
|
||||
|
||||
```python title=weather/__init__.py
|
||||
from nonebot import on_command
|
||||
from nonebot.rule import to_me
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters import Message
|
||||
from nonebot.params import CommandArg, ArgPlainText
|
||||
|
||||
weather = on_command("天气", rule=to_me(), aliases={"weather", "天气预报"})
|
||||
|
||||
@weather.handle()
|
||||
async def handle_function(matcher: Matcher, args: Message = CommandArg()):
|
||||
if args.extract_plain_text():
|
||||
matcher.set_arg("location", args)
|
||||
|
||||
@weather.got("location", prompt="请输入地名")
|
||||
async def got_location(location: str = ArgPlainText()):
|
||||
if location not in ["北京", "上海", "广州", "深圳"]:
|
||||
await weather.reject(f"你想查询的城市 {location} 暂不支持,请重新输入!")
|
||||
await weather.finish(f"今天{location}的天气是...")
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
```python {5-9,13-15,17-18}
|
||||
from nonebot.rule import to_me
|
||||
from arclet.alconna import Alconna, Args
|
||||
from nonebot_plugin_alconna import Match, on_alconna
|
||||
|
||||
weather = on_alconna(
|
||||
Alconna("天气", Args["location?", str]),
|
||||
aliases={"weather", "天气预报"},
|
||||
rule=to_me(),
|
||||
)
|
||||
|
||||
|
||||
@weather.handle()
|
||||
async def handle_function(location: Match[str]):
|
||||
if location.available:
|
||||
weather.set_path_arg("location", location.result)
|
||||
|
||||
@weather.got_path("location", prompt="请输入地名")
|
||||
async def got_location(location: str):
|
||||
if location not in ["北京", "上海", "广州", "深圳"]:
|
||||
await weather.reject(f"你想查询的城市 {location} 暂不支持,请重新输入!")
|
||||
await weather.finish(f"今天{location}的天气是...")
|
||||
```
|
||||
|
||||
在上面的代码中,我们使用 `Alconna` 来解析命令,`on_alconna` 用来创建响应器,使用 `Match` 来获取解析结果。
|
||||
|
||||
关于更多 `Alconna` 的使用方法,可参考 [Alconna 文档](https://arclet.top/docs/tutorial/alconna),
|
||||
或阅读 [Alconna 基本介绍](./command.md) 一节。
|
||||
|
||||
关于更多 `on_alconna` 的使用方法,可参考 [插件文档](https://github.com/nonebot/plugin-alconna/blob/master/docs.md),
|
||||
或阅读 [响应规则的使用](./matcher.mdx) 一节。
|
||||
|
||||
## 交流与反馈
|
||||
|
||||
QQ 交流群: [🔗 链接](https://jq.qq.com/?_wv=1027&k=PUPOnCSH)
|
||||
|
||||
友链: [📚 文档](https://graiax.cn/guide/message_parser/alconna.html)
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"label": "Alconna 命令解析拓展",
|
||||
"position": 6
|
||||
}
|
||||
@@ -1,607 +0,0 @@
|
||||
---
|
||||
sidebar_position: 3
|
||||
description: 响应规则的使用
|
||||
---
|
||||
|
||||
import Messenger from "@site/src/components/Messenger";
|
||||
|
||||
# Alconna 插件
|
||||
|
||||
展示:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import At, Image, on_alconna
|
||||
from arclet.alconna import Args, Option, Alconna, Arparma, MultiVar, Subcommand
|
||||
|
||||
|
||||
alc = Alconna(
|
||||
["/", "!"],
|
||||
"role-group",
|
||||
Subcommand(
|
||||
"add",
|
||||
Args["name", str],
|
||||
Option("member", Args["target", MultiVar(At)]),
|
||||
),
|
||||
Option("list"),
|
||||
Option("icon", Args["icon", Image])
|
||||
)
|
||||
rg = on_alconna(alc, auto_send_output=True)
|
||||
|
||||
|
||||
@rg.handle()
|
||||
async def _(result: Arparma):
|
||||
if result.find("list"):
|
||||
img: bytes = await gen_role_group_list_image()
|
||||
await rg.finish(Image(raw=img))
|
||||
if result.find("add"):
|
||||
group = await create_role_group(result.query[str]("add.name"))
|
||||
if result.find("add.member"):
|
||||
ats = result.query[tuple[At, ...]]("add.member.target")
|
||||
group.extend(member.target for member in ats)
|
||||
await rg.finish("添加成功")
|
||||
```
|
||||
|
||||
## 响应器使用
|
||||
|
||||
本插件基于 **Alconna**,为 **Nonebot** 提供了一类新的事件响应器辅助函数 `on_alconna`:
|
||||
|
||||
```python
|
||||
def on_alconna(
|
||||
command: Alconna | str,
|
||||
skip_for_unmatch: bool = True,
|
||||
auto_send_output: bool = False,
|
||||
aliases: set[str | tuple[str, ...]] | None = None,
|
||||
comp_config: CompConfig | None = None,
|
||||
extensions: list[type[Extension] | Extension] | None = None,
|
||||
exclude_ext: list[type[Extension] | str] | None = None,
|
||||
use_origin: bool = False,
|
||||
use_cmd_start: bool = False,
|
||||
use_cmd_sep: bool = False,
|
||||
**kwargs,
|
||||
...,
|
||||
):
|
||||
```
|
||||
|
||||
- `command`: Alconna 命令或字符串,字符串将通过 `AlconnaFormat` 转换为 Alconna 命令
|
||||
- `skip_for_unmatch`: 是否在命令不匹配时跳过该响应
|
||||
- `auto_send_output`: 是否自动发送输出信息并跳过响应
|
||||
- `aliases`: 命令别名, 作用类似于 `on_command` 中的 aliases
|
||||
- `comp_config`: 补全会话配置, 不传入则不启用补全会话
|
||||
- `extensions`: 需要加载的匹配扩展, 可以是扩展类或扩展实例
|
||||
- `exclude_ext`: 需要排除的匹配扩展, 可以是扩展类或扩展的id
|
||||
- `use_origin`: 是否使用未经 to_me 等处理过的消息
|
||||
- `use_cmd_start`: 是否使用 COMMAND_START 作为命令前缀
|
||||
- `use_cmd_sep`: 是否使用 COMMAND_SEP 作为命令分隔符
|
||||
|
||||
`on_alconna` 返回的是 `Matcher` 的子类 `AlconnaMatcher` ,其拓展了如下方法:
|
||||
|
||||
- `.assign(path, value, or_not)`: 用于对包含多个选项/子命令的命令的分派处理(具体请看[条件控制](./matcher.mdx#条件控制))
|
||||
- `.got_path(path, prompt, middleware)`: 在 `got` 方法的基础上,会以 path 对应的参数为准,读取传入 message 的最后一个消息段并验证转换
|
||||
- `.set_path_arg(key, value)`, `.get_path_arg(key)`: 类似 `set_arg` 和 `got_arg`,为 `got_path` 的特化版本
|
||||
- `.reject_path(path[, prompt, fallback])`: 类似于 `reject_arg`,对应 `got_path`
|
||||
- `.dispatch`: 同样的分派处理,但是是类似 `CommandGroup` 一样返回新的 `AlconnaMatcher`
|
||||
- `.got`, `send`, `reject`, ... : 拓展了 prompt 类型,即支持使用 `UniMessage` 作为 prompt
|
||||
|
||||
实例:
|
||||
|
||||
```python
|
||||
from nonebot import require
|
||||
require("nonebot_plugin_alconna")
|
||||
|
||||
from arclet.alconna import Alconna, Option, Args
|
||||
from nonebot_plugin_alconna import on_alconna, Match, UniMessage
|
||||
|
||||
|
||||
login = on_alconna(Alconna(["/"], "login", Args["password?", str], Option("-r|--recall"))) # 这里["/"]指命令前缀必须是/
|
||||
|
||||
# /login -r 触发
|
||||
@login.assign("recall")
|
||||
async def login_exit():
|
||||
await login.finish("已退出")
|
||||
|
||||
# /login xxx 触发
|
||||
@login.assign("password")
|
||||
async def login_handle(pw: Match[str]):
|
||||
if pw.available:
|
||||
login.set_path_arg("password", pw.result)
|
||||
|
||||
# /login 触发
|
||||
@login.got_path("password", prompt=UniMessage.template("{:At(user, $event.get_user_id())} 请输入密码"))
|
||||
async def login_got(password: str):
|
||||
assert password
|
||||
await login.send("登录成功")
|
||||
```
|
||||
|
||||
## 依赖注入
|
||||
|
||||
本插件提供了一系列依赖注入函数,便于在响应函数中获取解析结果:
|
||||
|
||||
- `AlconnaResult`: `CommandResult` 类型的依赖注入函数
|
||||
- `AlconnaMatches`: `Arparma` 类型的依赖注入函数
|
||||
- `AlconnaDuplication`: `Duplication` 类型的依赖注入函数
|
||||
- `AlconnaMatch`: `Match` 类型的依赖注入函数
|
||||
- `AlconnaQuery`: `Query` 类型的依赖注入函数
|
||||
|
||||
同时,基于 [`Annotated` 支持](https://github.com/nonebot/nonebot2/pull/1832),添加了两类注解:
|
||||
|
||||
- `AlcMatches`:同 `AlconnaMatches`
|
||||
- `AlcResult`:同 `AlconnaResult`
|
||||
|
||||
可以看到,本插件提供了几类额外的模型:
|
||||
|
||||
- `CommandResult`: 解析结果,包括了源命令 `source: Alconna` ,解析结果 `result: Arparma`,以及可能的输出信息 `output: str | None` 字段
|
||||
- `Match`: 匹配项,表示参数是否存在于 `all_matched_args` 内,可用 `Match.available` 判断是否匹配,`Match.result` 获取匹配的值
|
||||
- `Query`: 查询项,表示参数是否可由 `Arparma.query` 查询并获得结果,可用 `Query.available` 判断是否查询成功,`Query.result` 获取查询结果
|
||||
|
||||
**Alconna** 默认依赖注入的目标参数皆不需要使用依赖注入函数, 该效果对于 `AlconnaMatcher.got_path` 下的 Arg 同样有效:
|
||||
|
||||
```python
|
||||
async def handle(
|
||||
result: CommandResult,
|
||||
arp: Arparma,
|
||||
dup: Duplication,
|
||||
source: Alconna,
|
||||
abc: str, # 类似 Match, 但是若匹配结果不存在对应字段则跳过该 handler
|
||||
foo: Match[str],
|
||||
bar: Query[int] = Query("ttt.bar", 0) # Query 仍然需要一个默认值来传递 path 参数
|
||||
):
|
||||
...
|
||||
```
|
||||
|
||||
:::note
|
||||
|
||||
如果你更喜欢 Depends 式的依赖注入,`nonebot_plugin_alconna` 同时提供了一系列的依赖注入函数,他们包括:
|
||||
|
||||
- `AlconnaResult`: `CommandResult` 类型的依赖注入函数
|
||||
- `AlconnaMatches`: `Arparma` 类型的依赖注入函数
|
||||
- `AlconnaDuplication`: `Duplication` 类型的依赖注入函数
|
||||
- `AlconnaMatch`: `Match` 类型的依赖注入函数,其能够额外传入一个 middleware 函数来处理得到的参数
|
||||
- `AlconnaQuery`: `Query` 类型的依赖注入函数,其能够额外传入一个 middleware 函数来处理得到的参数
|
||||
- `AlconnaExecResult`: 提供挂载在命令上的 callback 的返回结果 (`Dict[str, Any]`) 的依赖注入函数
|
||||
- `AlconnaExtension`: 提供指定类型的 `Extension` 的依赖注入函数
|
||||
|
||||
:::
|
||||
|
||||
实例:
|
||||
|
||||
```python
|
||||
from nonebot import require
|
||||
require("nonebot_plugin_alconna")
|
||||
|
||||
from nonebot_plugin_alconna import (
|
||||
on_alconna,
|
||||
Match,
|
||||
Query,
|
||||
AlconnaMatch,
|
||||
AlcResult
|
||||
)
|
||||
from arclet.alconna import Alconna, Args, Option, Arparma
|
||||
|
||||
|
||||
test = on_alconna(
|
||||
Alconna(
|
||||
"test",
|
||||
Option("foo", Args["bar", int]),
|
||||
Option("baz", Args["qux", bool, False])
|
||||
),
|
||||
auto_send_output=True
|
||||
)
|
||||
|
||||
@test.handle()
|
||||
async def handle_test1(result: AlcResult):
|
||||
await test.send(f"matched: {result.matched}")
|
||||
await test.send(f"maybe output: {result.output}")
|
||||
|
||||
@test.handle()
|
||||
async def handle_test2(result: Arparma):
|
||||
await test.send(f"head result: {result.header_result}")
|
||||
await test.send(f"args: {result.all_matched_args}")
|
||||
|
||||
@test.handle()
|
||||
async def handle_test3(bar: Match[int] = AlconnaMatch("bar")):
|
||||
if bar.available:
|
||||
await test.send(f"foo={bar.result}")
|
||||
|
||||
@test.handle()
|
||||
async def handle_test4(qux: Query[bool] = Query("baz.qux", False)):
|
||||
if qux.available:
|
||||
await test.send(f"baz.qux={qux.result}")
|
||||
```
|
||||
|
||||
## 多平台适配
|
||||
|
||||
本插件提供了通用消息段标注, 通用消息段序列, 使插件使用者可以忽略平台之间字段的差异
|
||||
|
||||
响应器使用示例中使用了消息段标注,其中 `At` 属于通用标注,而 `Image` 属于 `onebot12` 适配器下的标注。
|
||||
|
||||
具体介绍和使用请查看 [通用信息组件](./uniseg.mdx#通用消息段)
|
||||
|
||||
本插件为以下适配器提供了专门的适配器标注:
|
||||
|
||||
| 协议名称 | 路径 |
|
||||
| ------------------------------------------------------------------- | ------------------------------------ |
|
||||
| [OneBot 协议](https://github.com/nonebot/adapter-onebot) | adapters.onebot11, adapters.onebot12 |
|
||||
| [Telegram](https://github.com/nonebot/adapter-telegram) | adapters.telegram |
|
||||
| [飞书](https://github.com/nonebot/adapter-feishu) | adapters.feishu |
|
||||
| [GitHub](https://github.com/nonebot/adapter-github) | adapters.github |
|
||||
| [QQ bot](https://github.com/nonebot/adapter-qq) | adapters.qq |
|
||||
| [钉钉](https://github.com/nonebot/adapter-ding) | adapters.ding |
|
||||
| [Dodo](https://github.com/nonebot/adapter-dodo) | adapters.dodo |
|
||||
| [Console](https://github.com/nonebot/adapter-console) | adapters.console |
|
||||
| [开黑啦](https://github.com/Tian-que/nonebot-adapter-kaiheila) | adapters.kook |
|
||||
| [Mirai](https://github.com/ieew/nonebot_adapter_mirai2) | adapters.mirai |
|
||||
| [Ntchat](https://github.com/JustUndertaker/adapter-ntchat) | adapters.ntchat |
|
||||
| [MineCraft](https://github.com/17TheWord/nonebot-adapter-minecraft) | adapters.minecraft |
|
||||
| [BiliBili Live](https://github.com/wwweww/adapter-bilibili) | adapters.bilibili |
|
||||
| [Walle-Q](https://github.com/onebot-walle/nonebot_adapter_walleq) | adapters.onebot12 |
|
||||
| [Discord](https://github.com/nonebot/adapter-discord) | adapters.discord |
|
||||
| [Red 协议](https://github.com/nonebot/adapter-red) | adapters.red |
|
||||
| [Satori 协议](https://github.com/nonebot/adapter-satori) | adapters.satori |
|
||||
|
||||
## 条件控制
|
||||
|
||||
本插件可以通过 `assign` 来控制一个具体的响应函数是否在不满足条件时跳过响应。
|
||||
|
||||
```python
|
||||
...
|
||||
from nonebot import require
|
||||
require("nonebot_plugin_alconna")
|
||||
...
|
||||
|
||||
from arclet.alconna import Alconna, Subcommand, Option, Args
|
||||
from nonebot_plugin_alconna import on_alconna, CommandResult
|
||||
|
||||
|
||||
pip = Alconna(
|
||||
"pip",
|
||||
Subcommand(
|
||||
"install", Args["pak", str],
|
||||
Option("--upgrade"),
|
||||
Option("--force-reinstall")
|
||||
),
|
||||
Subcommand("list", Option("--out-dated"))
|
||||
)
|
||||
|
||||
pip_cmd = on_alconna(pip)
|
||||
|
||||
# 仅在命令为 `pip install pip` 时响应
|
||||
@pip_cmd.assign("install.pak", "pip")
|
||||
async def update(res: CommandResult):
|
||||
...
|
||||
|
||||
# 仅在命令为 `pip list` 时响应
|
||||
@pip_cmd.assign("list")
|
||||
async def list_(res: CommandResult):
|
||||
...
|
||||
|
||||
# 在命令为 `pip install xxx` 时响应
|
||||
@pip_cmd.assign("install")
|
||||
async def install(res: CommandResult):
|
||||
...
|
||||
```
|
||||
|
||||
此外,使用 `AlconnaMatcher.dispatch` 还能像 `CommandGroup` 一样为每个分发设置独立的 matcher:
|
||||
|
||||
```python
|
||||
update_cmd = pip_cmd.dispatch("install.pak", "pip")
|
||||
|
||||
@update_cmd.handle()
|
||||
async def update(arp: CommandResult):
|
||||
...
|
||||
```
|
||||
|
||||
另外,`AlconnaMatcher` 有类似于 `got` 的 `got_path`:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import At, Match, UniMessage, on_alconna
|
||||
|
||||
|
||||
test_cmd = on_alconna(Alconna("test", Args["target?", Union[str, At]]))
|
||||
|
||||
@test_cmd.handle()
|
||||
async def tt_h(target: Match[Union[str, At]]):
|
||||
if target.available:
|
||||
test_cmd.set_path_arg("target", target.result)
|
||||
|
||||
@test_cmd.got_path("target", prompt="请输入目标")
|
||||
async def tt(target: Union[str, At]):
|
||||
await test_cmd.send(UniMessage(["ok\n", target]))
|
||||
```
|
||||
|
||||
`got_path` 与 `assign`,`Match`,`Query` 等地方一样,都需要指明 `path` 参数 (即对应 Arg 验证的路径)
|
||||
|
||||
`got_path` 会获取消息的最后一个消息段并转为 path 对应的类型,例如示例中 `target` 对应的 Arg 里要求 str 或 At,则 got 后用户输入的消息只有为 text 或 at 才能进入处理函数。
|
||||
|
||||
:::tip
|
||||
|
||||
`path` 支持 ~XXX 语法,其会把 ~ 替换为可能的父级路径:
|
||||
|
||||
```python
|
||||
pip = Alconna(
|
||||
"pip",
|
||||
Subcommand(
|
||||
"install",
|
||||
Args["pak", str],
|
||||
Option("--upgrade|-U"),
|
||||
Option("--force-reinstall"),
|
||||
),
|
||||
Subcommand("list", Option("--out-dated")),
|
||||
)
|
||||
|
||||
pipcmd = on_alconna(pip)
|
||||
pip_install_cmd = pipcmd.dispatch("install")
|
||||
|
||||
|
||||
@pip_install_cmd.assign("~upgrade")
|
||||
async def pip1_u(pak: Query[str] = Query("~pak")):
|
||||
await pip_install_cmd.finish(f"pip upgrading {pak.result}...")
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## 响应器创建装饰
|
||||
|
||||
本插件提供了一个 `funcommand` 装饰器, 其用于将一个接受任意参数, 返回 `str` 或 `Message` 或 `MessageSegment` 的函数转换为命令响应器:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import funcommand
|
||||
|
||||
|
||||
@funcommand()
|
||||
async def echo(msg: str):
|
||||
return msg
|
||||
```
|
||||
|
||||
其等同于:
|
||||
|
||||
```python
|
||||
from arclet.alconna import Alconna, Args
|
||||
from nonebot_plugin_alconna import on_alconna, AlconnaMatch, Match
|
||||
|
||||
|
||||
echo = on_alconna(Alconna("echo", Args["msg", str]))
|
||||
|
||||
@echo.handle()
|
||||
async def echo_exit(msg: Match[str] = AlconnaMatch("msg")):
|
||||
await echo.finish(msg.result)
|
||||
|
||||
```
|
||||
|
||||
## 类Koishi构造器
|
||||
|
||||
本插件提供了一个 `Command` 构造器,其基于 `arclet.alconna.tools` 中的 `AlconnaString`, 以类似 `Koishi` 中注册命令的方式来构建一个 **AlconnaMatcher** :
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import Command, Arparma
|
||||
|
||||
|
||||
book = (
|
||||
Command("book", "测试")
|
||||
.option("writer", "-w <id:int>")
|
||||
.option("writer", "--anonymous", {"id": 0})
|
||||
.usage("book [-w <id:int> | --anonymous]")
|
||||
.shortcut("测试", {"args": ["--anonymous"]})
|
||||
.build()
|
||||
)
|
||||
|
||||
@book.handle()
|
||||
async def _(arp: Arparma):
|
||||
await book.send(str(arp.options))
|
||||
```
|
||||
|
||||
甚至,你可以设置 `action` 来设定响应行为:
|
||||
|
||||
```python
|
||||
book = (
|
||||
Command("book", "测试")
|
||||
.option("writer", "-w <id:int>")
|
||||
.option("writer", "--anonymous", {"id": 0})
|
||||
.usage("book [-w <id:int> | --anonymous]")
|
||||
.shortcut("测试", {"args": ["--anonymous"]})
|
||||
.action(lambda options: str(options)) # 会自动通过 bot.send 发送
|
||||
.build()
|
||||
)
|
||||
```
|
||||
|
||||
## 返回值中间件
|
||||
|
||||
在 `AlconnaMatch`,`AlconnaQuery` 或 `got_path` 中,你可以使用 `middleware` 参数来传入一个对返回值进行处理的函数:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import image_fetch
|
||||
|
||||
|
||||
mask_cmd = on_alconna(
|
||||
Alconna("search", Args["img?", Image]),
|
||||
)
|
||||
|
||||
|
||||
@mask_cmd.handle()
|
||||
async def mask_h(matcher: AlconnaMatcher, img: Match[bytes] = AlconnaMatch("img", image_fetch)):
|
||||
result = await search_img(img.result)
|
||||
await matcher.send(result.content)
|
||||
```
|
||||
|
||||
其中,`image_fetch` 是一个中间件,其接受一个 `Image` 对象,并提取图片的二进制数据返回。
|
||||
|
||||
## 匹配拓展
|
||||
|
||||
本插件提供了一个 `Extension` 类,其用于自定义 AlconnaMatcher 的部分行为
|
||||
|
||||
例如一个 `LLMExtension` 可以如下实现 (仅举例):
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import Extension, Alconna, on_alconna, Interface
|
||||
|
||||
|
||||
class LLMExtension(Extension):
|
||||
@property
|
||||
def priority(self) -> int:
|
||||
return 10
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
return "LLMExtension"
|
||||
|
||||
def __init__(self, llm):
|
||||
self.llm = llm
|
||||
|
||||
def post_init(self, alc: Alconna) -> None:
|
||||
self.llm.add_context(alc.command, alc.meta.description)
|
||||
|
||||
async def receive_wrapper(self, bot, event, receive):
|
||||
resp = await self.llm.input(str(receive))
|
||||
return receive.__class__(resp.content)
|
||||
|
||||
def before_catch(self, name, annotation, default):
|
||||
return name == "llm"
|
||||
|
||||
def catch(self, interface: Interface):
|
||||
if interface.name == "llm":
|
||||
return self.llm
|
||||
|
||||
matcher = on_alconna(
|
||||
Alconna(...),
|
||||
extensions=[LLMExtension(LLM)]
|
||||
)
|
||||
...
|
||||
```
|
||||
|
||||
那么添加了 `LLMExtension` 的响应器便能接受任何能通过 llm 翻译为具体命令的自然语言消息,同时可以在响应器中为所有 `llm` 参数注入模型变量。
|
||||
|
||||
目前 `Extension` 的功能有:
|
||||
|
||||
- `validate`: 对于事件的来源适配器或 bot 选择是否接受响应
|
||||
- `output_converter`: 输出信息的自定义转换方法
|
||||
- `message_provider`: 从传入事件中自定义提取消息的方法
|
||||
- `receive_provider`: 对传入的消息 (Message 或 UniMessage) 的额外处理
|
||||
- `context_provider`: 对命令上下文的额外处理
|
||||
- `permission_check`: 命令对消息解析并确认头部匹配(即确认选择响应)时对发送者的权限判断
|
||||
- `parse_wrapper`: 对命令解析结果的额外处理
|
||||
- `send_wrapper`: 对发送的消息 (Message 或 UniMessage) 的额外处理
|
||||
- `before_catch`: 自定义依赖注入的绑定确认函数
|
||||
- `catch`: 自定义依赖注入处理函数
|
||||
- `post_init`: 响应器创建后对命令对象的额外处理
|
||||
|
||||
例如内置的 `DiscordSlashExtension`,其可自动将 Alconna 对象翻译成 slash 指令并注册,且将收到的指令交互事件转为指令供命令解析:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import Match, on_alconna
|
||||
from nonebot_plugin_alconna.builtins.extensions.discord import DiscordSlashExtension
|
||||
|
||||
|
||||
alc = Alconna(
|
||||
["/"],
|
||||
"permission",
|
||||
Subcommand("add", Args["plugin", str]["priority?", int]),
|
||||
Option("remove", Args["plugin", str]["time?", int]),
|
||||
meta=CommandMeta(description="权限管理"),
|
||||
)
|
||||
|
||||
matcher = on_alconna(alc, extensions=[DiscordSlashExtension()])
|
||||
|
||||
@matcher.assign("add")
|
||||
async def add(plugin: Match[str], priority: Match[int]):
|
||||
await matcher.finish(f"added {plugin.result} with {priority.result if priority.available else 0}")
|
||||
|
||||
@matcher.assign("remove")
|
||||
async def remove(plugin: Match[str], time: Match[int]):
|
||||
await matcher.finish(f"removed {plugin.result} with {time.result if time.available else -1}")
|
||||
```
|
||||
|
||||
目前插件提供了 4 个内置的 `Extension`,它们在 `nonebot_plugin_alconna.builtins.extensions` 下:
|
||||
|
||||
- `ReplyRecordExtension`: 将消息事件中的回复暂存在 extension 中,使得解析用的消息不带回复信息,同时可以在后续的处理中获取回复信息。
|
||||
- `DiscordSlashExtension`: 将 Alconna 的命令自动转换为 Discord 的 Slash Command,并将 Slash Command 的交互事件转换为消息交给 Alconna 处理。
|
||||
- `MarkdownOutputExtension`: 将 Alconna 的自动输出转换为 Markdown 格式
|
||||
- `TelegramSlashExtension`: 将 Alconna 的命令注册在 Telegram 上以获得提示。
|
||||
|
||||
:::tip
|
||||
|
||||
全局的 Extension 可延迟加载 (即若有全局拓展加载于部分 AlconnaMatcher 之后,这部分响应器会被追加拓展)
|
||||
|
||||
:::
|
||||
|
||||
## 补全会话
|
||||
|
||||
补全会话基于 [`半自动补全`](./command.md#半自动补全),用于指令参数缺失或参数错误时给予交互式提示,类似于 `got-reject`:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import Alconna, Args, Field, At, on_alconna
|
||||
|
||||
alc = Alconna(
|
||||
"添加教师",
|
||||
Args["name", str, Field(completion=lambda: "请输入姓名")],
|
||||
Args["phone", int, Field(completion=lambda: "请输入手机号")],
|
||||
Args["at", [str, At], Field(completion=lambda: "请输入教师号")],
|
||||
)
|
||||
|
||||
cmd = on_alconna(alc, comp_config={"lite": True}, skip_for_unmatch=False)
|
||||
|
||||
@cmd.handle()
|
||||
async def handle(result: Arparma):
|
||||
cmd.finish("添加成功")
|
||||
```
|
||||
|
||||
此时,当用户输入 `添加教师` 时,会自动提示用户输入姓名,手机号和教师号,用户输入后会自动进入下一个提示:
|
||||
|
||||
<Messenger
|
||||
msgs={[
|
||||
{ position: "right", msg: "添加教师" },
|
||||
{ position: "left", msg: "以下是建议的输入: \n- name: 请输入姓名" },
|
||||
{ position: "right", msg: "foo" },
|
||||
{ position: "left", msg: "以下是建议的输入: \n- phone: 请输入手机号" },
|
||||
{ position: "right", msg: "12345" },
|
||||
{ position: "left", msg: "以下是建议的输入: \n- at: 请输入教师号" },
|
||||
{ position: "right", msg: "@me" },
|
||||
{ position: "left", msg: "添加成功" },
|
||||
]}
|
||||
/>
|
||||
|
||||
补全会话配置如下:
|
||||
|
||||
```python
|
||||
class CompConfig(TypedDict):
|
||||
tab: NotRequired[str]
|
||||
"""用于切换提示的指令的名称"""
|
||||
enter: NotRequired[str]
|
||||
"""用于输入提示的指令的名称"""
|
||||
exit: NotRequired[str]
|
||||
"""用于退出会话的指令的名称"""
|
||||
timeout: NotRequired[int]
|
||||
"""超时时间"""
|
||||
hide_tabs: NotRequired[bool]
|
||||
"""是否隐藏所有提示"""
|
||||
hides: NotRequired[Set[Literal["tab", "enter", "exit"]]]
|
||||
"""隐藏的指令"""
|
||||
disables: NotRequired[Set[Literal["tab", "enter", "exit"]]]
|
||||
"""禁用的指令"""
|
||||
lite: NotRequired[bool]
|
||||
"""是否使用简洁版本的补全会话(相当于同时配置 disables、hides、hide_tabs)"""
|
||||
```
|
||||
|
||||
## 内置插件
|
||||
|
||||
类似于 Nonebot 本身提供的内置插件,`nonebot_plugin_alconna` 提供了两个内置插件:`echo` 和 `help`。
|
||||
|
||||
你可以用本插件的 `load_builtin_plugin(s)` 来加载它们:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna import load_builtin_plugins
|
||||
|
||||
load_builtin_plugins("echo", "help")
|
||||
```
|
||||
|
||||
其中 `help` 仅能列出所有 Alconna 指令。
|
||||
|
||||
<Messenger
|
||||
msgs={[
|
||||
{ position: "right", msg: "/帮助" },
|
||||
{
|
||||
position: "left",
|
||||
msg: "# 当前可用的命令有:\n 0 /echo : echo 指令\n 1 /help : 显示所有命令帮助\n# 输入'命令名 -h|--help' 查看特定命令的语法",
|
||||
},
|
||||
{ position: "right", msg: "/echo [图片]" },
|
||||
{ position: "left", msg: "[图片]" },
|
||||
]}
|
||||
/>
|
||||
@@ -1,590 +0,0 @@
|
||||
---
|
||||
sidebar_position: 5
|
||||
description: 通用消息组件
|
||||
---
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
# 通用消息组件
|
||||
|
||||
`uniseg` 模块属于 `nonebot-plugin-alconna` 的子插件,其提供了一套通用的消息组件,用于在 `nonebot-plugin-alconna` 下构建通用消息。
|
||||
|
||||
## 通用消息段
|
||||
|
||||
适配器下的消息段标注会匹配适配器特定的 `MessageSegment`, 而通用消息段与适配器消息段的区别在于:
|
||||
通用消息段会匹配多个适配器中相似类型的消息段,并返回 `uniseg` 模块中定义的 [`Segment` 模型](https://nonebot.dev/docs/next/best-practice/alconna/utils#%E9%80%9A%E7%94%A8%E6%B6%88%E6%81%AF%E6%AE%B5), 以达到**跨平台接收消息**的作用。
|
||||
|
||||
`nonebot-plugin-alconna.uniseg` 提供了类似 `MessageSegment` 的通用消息段,并可在 `Alconna` 下直接标注使用:
|
||||
|
||||
```python
|
||||
class Segment:
|
||||
"""基类标注"""
|
||||
children: List["Segment"]
|
||||
|
||||
class Text(Segment):
|
||||
"""Text对象, 表示一类文本元素"""
|
||||
text: str
|
||||
styles: Dict[Tuple[int, int], List[str]]
|
||||
|
||||
class At(Segment):
|
||||
"""At对象, 表示一类提醒某用户的元素"""
|
||||
flag: Literal["user", "role", "channel"]
|
||||
target: str
|
||||
display: Optional[str]
|
||||
|
||||
class AtAll(Segment):
|
||||
"""AtAll对象, 表示一类提醒所有人的元素"""
|
||||
here: bool
|
||||
|
||||
class Emoji(Segment):
|
||||
"""Emoji对象, 表示一类表情元素"""
|
||||
id: str
|
||||
name: Optional[str]
|
||||
|
||||
class Media(Segment):
|
||||
url: Optional[str]
|
||||
id: Optional[str]
|
||||
path: Optional[Union[str, Path]]
|
||||
raw: Optional[Union[bytes, BytesIO]]
|
||||
mimetype: Optional[str]
|
||||
name: str
|
||||
|
||||
to_url: ClassVar[Optional[MediaToUrl]]
|
||||
|
||||
class Image(Media):
|
||||
"""Image对象, 表示一类图片元素"""
|
||||
|
||||
class Audio(Media):
|
||||
"""Audio对象, 表示一类音频元素"""
|
||||
duration: Optional[int]
|
||||
|
||||
class Voice(Media):
|
||||
"""Voice对象, 表示一类语音元素"""
|
||||
duration: Optional[int]
|
||||
|
||||
class Video(Media):
|
||||
"""Video对象, 表示一类视频元素"""
|
||||
|
||||
class File(Segment):
|
||||
"""File对象, 表示一类文件元素"""
|
||||
id: str
|
||||
name: Optional[str]
|
||||
|
||||
class Reply(Segment):
|
||||
"""Reply对象,表示一类回复消息"""
|
||||
id: str
|
||||
"""此处不一定是消息ID,可能是其他ID,如消息序号等"""
|
||||
msg: Optional[Union[Message, str]]
|
||||
origin: Optional[Any]
|
||||
|
||||
class Reference(Segment):
|
||||
"""Reference对象,表示一类引用消息。转发消息 (Forward) 也属于此类"""
|
||||
id: Optional[str]
|
||||
"""此处不一定是消息ID,可能是其他ID,如消息序号等"""
|
||||
children: List[Union[RefNode, CustomNode]]
|
||||
|
||||
class Hyper(Segment):
|
||||
"""Hyper对象,表示一类超级消息。如卡片消息、ark消息、小程序等"""
|
||||
format: Literal["xml", "json"]
|
||||
raw: Optional[str]
|
||||
content: Optional[Union[dict, list]]
|
||||
|
||||
class Other(Segment):
|
||||
"""其他 Segment"""
|
||||
origin: MessageSegment
|
||||
|
||||
```
|
||||
|
||||
:::tip
|
||||
|
||||
或许你注意到了 `Segment` 上有一个 `children` 属性。
|
||||
|
||||
这是因为在 [`Satori`](https://satori.js.org/zh-CN/) 协议的规定下,一类元素可以用其子元素来代表一类兼容性消息
|
||||
(例如,qq 的商场表情在某些平台上可以用图片代替)。
|
||||
|
||||
为此,本插件提供了两种方式来表达 "获取子元素" 的方法:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.builtins.uniseg.chronocat import MarketFace
|
||||
from nonebot_plugin_alconna import Args, Image, Alconna, select, select_first
|
||||
|
||||
# 表示这个指令需要的图片要么直接是 Image 要么是在 MarketFace 元素内的 Image
|
||||
alc1 = Alconna("make_meme", Args["img", [Image, Image.from_(MarketFace)]])
|
||||
|
||||
# 表示这个指令需要的图片会在目标元素下进行搜索,将所有符合 Image 的元素选出来并将第一个作为结果
|
||||
alc2 = Alconna("make_meme", Args["img", select(Image, index=0)]) # 也可以使用 select_first(Image)
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
## 通用消息序列
|
||||
|
||||
`nonebot-plugin-alconna.uniseg` 同时提供了一个类似于 `Message` 的 `UniMessage` 类型,其元素为经过通用标注转换后的通用消息段。
|
||||
|
||||
你可以用如下方式获取 `UniMessage`:
|
||||
|
||||
<Tabs groupId="get_unimsg">
|
||||
<TabItem value="depend" label="使用依赖注入">
|
||||
|
||||
通过提供的 `UniversalMessage` 或 `UniMsg` 依赖注入器来获取 `UniMessage`。
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMsg, At, Reply
|
||||
|
||||
|
||||
matcher = on_xxx(...)
|
||||
|
||||
@matcher.handle()
|
||||
async def _(msg: UniMsg):
|
||||
reply = msg[Reply, 0]
|
||||
print(reply.origin)
|
||||
if msg.has(At):
|
||||
ats = msg.get(At)
|
||||
print(ats)
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="method" label="使用 UniMessage.generate">
|
||||
|
||||
注意,`generate` 方法在响应器以外的地方如果不传入 `event` 与 `bot` 则无法处理 reply。
|
||||
|
||||
```python
|
||||
from nonebot import Message, EventMessage
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
|
||||
|
||||
matcher = on_xxx(...)
|
||||
|
||||
@matcher.handle()
|
||||
async def _(message: Message = EventMessage()):
|
||||
msg = await UniMessage.generate(message=message)
|
||||
msg1 = UniMessage.generate_without_reply(message=message)
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
不仅如此,你还可以通过 `UniMessage` 的 `export` 与 `send` 方法来**跨平台发送消息**。
|
||||
|
||||
`UniMessage.export` 会通过传入的 `bot: Bot` 参数,或上下文中的 `Bot` 对象读取适配器信息,并使用对应的生成方法把通用消息转为适配器对应的消息序列:
|
||||
|
||||
```python
|
||||
from nonebot import Bot, on_command
|
||||
from nonebot_plugin_alconna.uniseg import Image, UniMessage
|
||||
|
||||
|
||||
test = on_command("test")
|
||||
|
||||
@test.handle()
|
||||
async def handle_test():
|
||||
await test.send(await UniMessage(Image(path="path/to/img")).export())
|
||||
```
|
||||
|
||||
除此之外 `UniMessage.send` 方法基于 `UniMessage.export` 并调用各适配器下的发送消息方法,返回一个 `Receipt` 对象,用于修改/撤回消息:
|
||||
|
||||
```python
|
||||
from nonebot import Bot, on_command
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
|
||||
|
||||
test = on_command("test")
|
||||
|
||||
@test.handle()
|
||||
async def handle():
|
||||
receipt = await UniMessage.text("hello!").send(at_sender=True, reply_to=True)
|
||||
await receipt.recall(delay=1)
|
||||
```
|
||||
|
||||
而在 `AlconnaMatcher` 下,`got`, `send`, `reject` 等可以发送消息的方法皆支持使用 `UniMessage`,不需要手动调用 export 方法:
|
||||
|
||||
```python
|
||||
from arclet.alconna import Alconna, Args
|
||||
from nonebot_plugin_alconna import Match, AlconnaMatcher, on_alconna
|
||||
from nonebot_plugin_alconna.uniseg import At, UniMessage
|
||||
|
||||
|
||||
test_cmd = on_alconna(Alconna("test", Args["target?", At]))
|
||||
|
||||
@test_cmd.handle()
|
||||
async def tt_h(matcher: AlconnaMatcher, target: Match[At]):
|
||||
if target.available:
|
||||
matcher.set_path_arg("target", target.result)
|
||||
|
||||
@test_cmd.got_path("target", prompt="请输入目标")
|
||||
async def tt(target: At):
|
||||
await test_cmd.send(UniMessage([target, "\ndone."]))
|
||||
```
|
||||
|
||||
:::caution
|
||||
|
||||
在响应器以外的地方,除非启用了 `alconna_apply_fetch_targets` 配置项,否则 `bot` 参数必须手动传入。
|
||||
|
||||
:::
|
||||
|
||||
### 构造
|
||||
|
||||
如同 `Message`, `UniMessage` 可以传入单个字符串/消息段,或可迭代的字符串/消息段:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, At
|
||||
|
||||
|
||||
msg = UniMessage("Hello")
|
||||
msg1 = UniMessage(At("user", "124"))
|
||||
msg2 = UniMessage(["Hello", At("user", "124")])
|
||||
```
|
||||
|
||||
`UniMessage` 上同时存在便捷方法,令其可以链式地添加消息段:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, At, Image
|
||||
|
||||
|
||||
msg = UniMessage.text("Hello").at("124").image(path="/path/to/img")
|
||||
assert msg == UniMessage(
|
||||
["Hello", At("user", "124"), Image(path="/path/to/img")]
|
||||
)
|
||||
```
|
||||
|
||||
### 拼接消息
|
||||
|
||||
`str`、`UniMessage`、`Segment` 对象之间可以直接相加,相加均会返回一个新的 `UniMessage` 对象:
|
||||
|
||||
```python
|
||||
# 消息序列与消息段相加
|
||||
UniMessage("text") + Text("text")
|
||||
# 消息序列与字符串相加
|
||||
UniMessage([Text("text")]) + "text"
|
||||
# 消息序列与消息序列相加
|
||||
UniMessage("text") + UniMessage([Text("text")])
|
||||
# 字符串与消息序列相加
|
||||
"text" + UniMessage([Text("text")])
|
||||
# 消息段与消息段相加
|
||||
Text("text") + Text("text")
|
||||
# 消息段与字符串相加
|
||||
Text("text") + "text"
|
||||
# 消息段与消息序列相加
|
||||
Text("text") + UniMessage([Text("text")])
|
||||
# 字符串与消息段相加
|
||||
"text" + Text("text")
|
||||
```
|
||||
|
||||
如果需要在当前消息序列后直接拼接新的消息段,可以使用 `Message.append`、`Message.extend` 方法,或者使用自加:
|
||||
|
||||
```python
|
||||
msg = UniMessage([Text("text")])
|
||||
# 自加
|
||||
msg += "text"
|
||||
msg += Text("text")
|
||||
msg += UniMessage([Text("text")])
|
||||
# 附加
|
||||
msg.append(Text("text"))
|
||||
# 扩展
|
||||
msg.extend([Text("text")])
|
||||
```
|
||||
|
||||
### 使用消息模板
|
||||
|
||||
`UniMessage.template` 同样类似于 `Message.template`,可以用于格式化消息,大体用法参考 [消息模板](../../tutorial/message#使用消息模板)。
|
||||
|
||||
这里额外说明 `UniMessage.template` 的拓展控制符
|
||||
|
||||
相比 `Message`,UniMessage 对于 `{:XXX}` 做了另一类拓展。其能够识别例如 At(xxx, yyy) 或 Emoji(aaa, bbb)的字符串并执行
|
||||
|
||||
以 At(...) 为例:
|
||||
|
||||
```python title=使用通用消息段的拓展控制符
|
||||
>>> from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
>>> UniMessage.template("{:At(user, target)}").format(target="123")
|
||||
UniMessage(At("user", "123"))
|
||||
>>> UniMessage.template("{:At(type=user, target=id)}").format(id="123")
|
||||
UniMessage(At("user", "123"))
|
||||
>>> UniMessage.template("{:At(type=user, target=123)}").format()
|
||||
UniMessage(At("user", "123"))
|
||||
```
|
||||
|
||||
而在 `AlconnaMatcher` 中,`{:XXX}` 更进一步地提供了获取 `event` 和 `bot` 中的属性的功能:
|
||||
|
||||
```python title=在AlconnaMatcher中使用通用消息段的拓展控制符
|
||||
from arclet.alconna import Alconna, Args
|
||||
from nonebot_plugin_alconna import At, Match, UniMessage, AlconnaMatcher, on_alconna
|
||||
|
||||
|
||||
test_cmd = on_alconna(Alconna("test", Args["target?", At]))
|
||||
|
||||
@test_cmd.handle()
|
||||
async def tt_h(matcher: AlconnaMatcher, target: Match[At]):
|
||||
if target.available:
|
||||
matcher.set_path_arg("target", target.result)
|
||||
|
||||
@test_cmd.got_path(
|
||||
"target",
|
||||
prompt=UniMessage.template("{:At(user, $event.get_user_id())} 请确认目标")
|
||||
)
|
||||
async def tt():
|
||||
await test_cmd.send(
|
||||
UniMessage.template("{:At(user, $event.get_user_id())} 已确认目标为 {target}")
|
||||
)
|
||||
```
|
||||
|
||||
另外也有 `$message_id` 与 `$target` 两个特殊值。
|
||||
|
||||
### 检查消息段
|
||||
|
||||
我们可以通过 `in` 运算符或消息序列的 `has` 方法来:
|
||||
|
||||
```python
|
||||
# 是否存在消息段
|
||||
At("user", "1234") in message
|
||||
# 是否存在指定类型的消息段
|
||||
At in message
|
||||
```
|
||||
|
||||
我们还可以使用 `only` 方法来检查消息中是否仅包含指定的消息段:
|
||||
|
||||
```python
|
||||
# 是否都为 "test"
|
||||
message.only("test")
|
||||
# 是否仅包含指定类型的消息段
|
||||
message.only(Text)
|
||||
```
|
||||
|
||||
### 获取消息纯文本
|
||||
|
||||
类似于 `Message.extract_plain_text()`,用于获取通用消息的纯文本:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, At
|
||||
|
||||
|
||||
# 提取消息纯文本字符串
|
||||
assert UniMessage(
|
||||
[At("user", "1234"), "text"]
|
||||
).extract_plain_text() == "text"
|
||||
```
|
||||
|
||||
### 遍历
|
||||
|
||||
通用消息序列继承自 `List[Segment]` ,因此可以使用 `for` 循环遍历消息段:
|
||||
|
||||
```python
|
||||
for segment in message: # type: Segment
|
||||
...
|
||||
```
|
||||
|
||||
### 过滤、索引与切片
|
||||
|
||||
消息序列对列表的索引与切片进行了增强,在原有列表 `int` 索引与 `slice` 切片的基础上,支持 `type` 过滤索引与切片:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, At, Text, Reply
|
||||
|
||||
|
||||
message = UniMessage(
|
||||
[
|
||||
Reply(...),
|
||||
"text1",
|
||||
At("user", "1234"),
|
||||
"text2"
|
||||
]
|
||||
)
|
||||
# 索引
|
||||
message[0] == Reply(...)
|
||||
# 切片
|
||||
message[0:2] == UniMessage([Reply(...), Text("text1")])
|
||||
# 类型过滤
|
||||
message[At] == Message([At("user", "1234")])
|
||||
# 类型索引
|
||||
message[At, 0] == At("user", "1234")
|
||||
# 类型切片
|
||||
message[Text, 0:2] == UniMessage([Text("text1"), Text("text2")])
|
||||
```
|
||||
|
||||
我们也可以通过消息序列的 `include`、`exclude` 方法进行类型过滤:
|
||||
|
||||
```python
|
||||
message.include(Text, At)
|
||||
message.exclude(Reply)
|
||||
```
|
||||
|
||||
同样的,消息序列对列表的 `index`、`count` 方法也进行了增强,可以用于索引指定类型的消息段:
|
||||
|
||||
```python
|
||||
# 指定类型首个消息段索引
|
||||
message.index(Text) == 1
|
||||
# 指定类型消息段数量
|
||||
message.count(Text) == 2
|
||||
```
|
||||
|
||||
此外,消息序列添加了一个 `get` 方法,可以用于获取指定类型指定个数的消息段:
|
||||
|
||||
```python
|
||||
# 获取指定类型指定个数的消息段
|
||||
message.get(Text, 1) == UniMessage([Text("test1")])
|
||||
```
|
||||
|
||||
## 消息发送
|
||||
|
||||
前面提到,通用消息可用 `UniMessage.send` 发送自身:
|
||||
|
||||
```python
|
||||
async def send(
|
||||
self,
|
||||
target: Union[Event, Target, None] = None,
|
||||
bot: Optional[Bot] = None,
|
||||
fallback: bool = True,
|
||||
at_sender: Union[str, bool] = False,
|
||||
reply_to: Union[str, bool] = False,
|
||||
) -> Receipt:
|
||||
```
|
||||
|
||||
实际上,`UniMessage` 同时提供了获取消息事件 id 与消息发送对象的方法:
|
||||
|
||||
<Tabs groupId="get_unimsg">
|
||||
<TabItem value="depend" label="使用依赖注入">
|
||||
|
||||
通过提供的 `MessageTarget`, `MessageId` 或 `MsgTarget`, `MsgId` 依赖注入器来获取消息事件 id 与消息发送对象。
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import MessageId, MsgTarget
|
||||
|
||||
|
||||
matcher = on_xxx(...)
|
||||
|
||||
@matcher.handle()
|
||||
asycn def _(target: MsgTarget, msg_id: MessageId):
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="method" label="使用 UniMessage 的方法">
|
||||
|
||||
```python
|
||||
from nonebot import Event, Bot
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, Target
|
||||
|
||||
|
||||
matcher = on_xxx(...)
|
||||
|
||||
@matcher.handle()
|
||||
asycn def _(bot: Bot, event: Event):
|
||||
target: Target = UniMessage.get_target(event, bot)
|
||||
msg_id: str = UniMessage.get_message_id(event, bot)
|
||||
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
`send`, `get_target`, `get_message_id` 中与 `event`, `bot` 相关的参数都会尝试从上下文中获取对象。
|
||||
|
||||
### 消息发送对象
|
||||
|
||||
消息发送对象是用来描述响应消息时的发送对象或者主动发送消息时的目标对象的对象,它包含了以下属性:
|
||||
|
||||
```python
|
||||
class Target:
|
||||
id: str
|
||||
"""目标id;若为群聊则为group_id或者channel_id,若为私聊则为user_id"""
|
||||
parent_id: str
|
||||
"""父级id;若为频道则为guild_id,其他情况下可能为空字符串(例如 Feishu 下可作为部门 id)"""
|
||||
channel: bool
|
||||
"""是否为频道,仅当目标平台符合频道概念时"""
|
||||
private: bool
|
||||
"""是否为私聊"""
|
||||
source: str
|
||||
"""可能的事件id"""
|
||||
self_id: Union[str, None]
|
||||
"""机器人id,若为 None 则 Bot 对象会随机选择"""
|
||||
selector: Union[Callable[[Bot], Awaitable[bool]], None]
|
||||
"""选择器,用于在多个 Bot 对象中选择特定 Bot"""
|
||||
extra: Dict[str, Any]
|
||||
"""额外信息,用于适配器扩展"""
|
||||
```
|
||||
|
||||
其构造时需要如下参数:
|
||||
|
||||
- `id` 为目标id;若为群聊则为 group_id 或者 channel_id,若为私聊则为user_id
|
||||
- `parent_id` 为父级id;若为频道则为 guild_id,其他情况下可能为空字符串(例如 Feishu 下可作为部门 id)
|
||||
- `channel` 为是否为频道,仅当目标平台符合频道概念时
|
||||
- `private` 为是否为私聊
|
||||
- `source` 为可能的事件id
|
||||
- `self_id` 为机器人id,若为 None 则 Bot 对象会随机选择
|
||||
- `selector` 为选择器,用于在多个 Bot 对象中选择特定 Bot
|
||||
- `scope` 为适配器范围,用于传入内置的特定选择器
|
||||
- `adapter` 为适配器名称,若为 None 则需要明确指定 Bot 对象
|
||||
- `platform` 为平台名称,仅当目标适配器存在多个平台时使用
|
||||
- `extra` 为额外信息,用于适配器扩展
|
||||
|
||||
通过 `Target` 对象,我们可以在 `UniMessage.send` 中指定发送对象:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, MsgTarget, Target, SupportScope
|
||||
|
||||
|
||||
matcher = on_xxx(...)
|
||||
|
||||
@matcher.handle()
|
||||
async def _(target: MsgTarget):
|
||||
await UniMessage("Hello!").send(target=target)
|
||||
target1 = Target("xxxx", scope=SupportScope.qq_client)
|
||||
await UniMessage("Hello!").send(target=target1)
|
||||
```
|
||||
|
||||
### 主动发送消息
|
||||
|
||||
`UniMessage.send` 也可以用于主动发送消息:
|
||||
|
||||
```python
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage, Target, SupportScope
|
||||
from nonebot import get_driver
|
||||
|
||||
|
||||
driver = get_driver()
|
||||
|
||||
@driver.on_startup
|
||||
async def on_startup():
|
||||
target = Target("xxxx", scope=SupportScope.qq_client)
|
||||
await UniMessage("Hello!").send(target=target)
|
||||
```
|
||||
|
||||
## 自定义消息段
|
||||
|
||||
`uniseg` 提供了部分方法来允许用户自定义 Segment 的序列化和反序列化:
|
||||
|
||||
```python
|
||||
from dataclasses import dataclass
|
||||
|
||||
from nonebot.adapters import Bot
|
||||
from nonebot.adapters import MessageSegment as BaseMessageSegment
|
||||
from nonebot.adapters.satori import Custom, Message, MessageSegment
|
||||
|
||||
from nonebot_plugin_alconna.uniseg.builder import MessageBuilder
|
||||
from nonebot_plugin_alconna.uniseg.exporter import MessageExporter
|
||||
from nonebot_plugin_alconna.uniseg import Segment, custom_handler, custom_register
|
||||
|
||||
|
||||
@dataclass
|
||||
class MarketFace(Segment):
|
||||
tabId: str
|
||||
faceId: str
|
||||
key: str
|
||||
|
||||
|
||||
@custom_register(MarketFace, "chronocat:marketface")
|
||||
def mfbuild(builder: MessageBuilder, seg: BaseMessageSegment):
|
||||
if not isinstance(seg, Custom):
|
||||
raise ValueError("MarketFace can only be built from Satori Message")
|
||||
return MarketFace(**seg.data)(*builder.generate(seg.children))
|
||||
|
||||
|
||||
@custom_handler(MarketFace)
|
||||
async def mfexport(exporter: MessageExporter, seg: MarketFace, bot: Bot, fallback: bool):
|
||||
if exporter.get_message_type() is Message:
|
||||
return MessageSegment("chronocat:marketface", seg.data)(await exporter.export(seg.children, bot, fallback))
|
||||
|
||||
```
|
||||
|
||||
具体而言,你可以使用 `custom_register` 来增加一个从 MessageSegment 到 Segment 的处理方法;使用 `custom_handler` 来增加一个从 Segment 到 MessageSegment 的处理方法。
|
||||
@@ -1,31 +0,0 @@
|
||||
---
|
||||
sidebar_position: 2
|
||||
description: 配置编辑器以获得最佳体验
|
||||
---
|
||||
|
||||
# 编辑器支持
|
||||
|
||||
框架基于 [PEP484](https://www.python.org/dev/peps/pep-0484/)、[PEP 561](https://www.python.org/dev/peps/pep-0561/)、[PEP8](https://www.python.org/dev/peps/pep-0008/) 等规范进行开发并且**拥有完整类型注解**。框架使用 Pyright(Pylance)工具进行类型检查,确保代码可以被编辑器正确解析。
|
||||
|
||||
## 编辑器推荐配置
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
在 Visual Studio Code 中,可以使用 Pylance Language Server 并启用 `Type Checking` 配置以达到最佳开发体验。
|
||||
|
||||
1. 在 VSCode 插件视图搜索并安装 `Python (ms-python.python)` 和 `Pylance (ms-python.vscode-pylance)` 插件。
|
||||
2. 修改 VSCode 配置
|
||||
在 VSCode 设置视图搜索配置项 `Python: Language Server` 并将其值设置为 `Pylance`,搜索配置项 `Python > Analysis: Type Checking Mode` 并将其值设置为 `basic`。
|
||||
|
||||
或者向项目 `.vscode` 文件夹中配置文件添加以下内容:
|
||||
|
||||
```json title=settings.json
|
||||
{
|
||||
"python.languageServer": "Pylance",
|
||||
"python.analysis.typeCheckingMode": "basic"
|
||||
}
|
||||
```
|
||||
|
||||
### 其他
|
||||
|
||||
欢迎提交 Pull Request 添加其他编辑器配置推荐。点击左下角 `Edit this page` 前往编辑。
|
||||
@@ -20,7 +20,6 @@ description: nonebot.adapters 模块
|
||||
通常,在 Adapter 中编写协议通信相关代码,如: 建立通信连接、处理接收与发送 data 等。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` ([Driver](../drivers/index.md#Driver)): [Driver](../drivers/index.md#Driver) 实例
|
||||
|
||||
- `**kwargs` (Any): 其他由 [Driver.register_adapter](../drivers/index.md#Driver-register-adapter) 传入的额外参数
|
||||
@@ -46,7 +45,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _property_ `config` {#Adapter-config}
|
||||
@@ -64,11 +62,9 @@ description: nonebot.adapters 模块
|
||||
当有新的 [Bot](#Bot) 实例连接建立成功时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](#Bot)): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `bot_disconnect(bot)` {#Adapter-bot-disconnect}
|
||||
@@ -80,11 +76,9 @@ description: nonebot.adapters 模块
|
||||
当有 [Bot](#Bot) 实例连接断开时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](#Bot)): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `setup_http_server(setup)` {#Adapter-setup-http-server}
|
||||
@@ -92,11 +86,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](../drivers/index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Adapter-setup-websocket-server}
|
||||
@@ -104,11 +96,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](../drivers/index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `request(setup)` {#Adapter-request}
|
||||
@@ -116,11 +106,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 进行一个 HTTP 客户端请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](../drivers/index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](../drivers/index.md#Response)
|
||||
|
||||
### _method_ `websocket(setup)` {#Adapter-websocket}
|
||||
@@ -128,21 +116,17 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 建立一个 WebSocket 客户端连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](../drivers/index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](../drivers/index.md#WebSocket), None]
|
||||
|
||||
### _method_ `on_ready(func)` {#Adapter-on-ready}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
## _abstract class_ `Bot(adapter, self_id)` {#Bot}
|
||||
@@ -154,7 +138,6 @@ description: nonebot.adapters 模块
|
||||
用于处理上报消息,并提供 API 调用接口。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` ([Adapter](#Adapter)): 协议适配器实例
|
||||
|
||||
- `self_id` (str): 机器人 ID
|
||||
@@ -188,13 +171,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `api` (str): API 名称
|
||||
|
||||
- `**data` (Any): API 数据
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
- **用法**
|
||||
@@ -209,7 +190,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 调用机器人基础发送消息接口
|
||||
|
||||
- **参数**
|
||||
|
||||
- `event` ([Event](#Event)): 上报事件
|
||||
|
||||
- `message` (str | [Message](#Message) | [MessageSegment](#MessageSegment)): 要发送的消息
|
||||
@@ -217,7 +197,6 @@ description: nonebot.adapters 模块
|
||||
- `**kwargs` (Any): 任意额外参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _classmethod_ `on_calling_api(func)` {#Bot-on-calling-api}
|
||||
@@ -227,17 +206,14 @@ description: nonebot.adapters 模块
|
||||
调用 api 预处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- api: 调用的 api 名称
|
||||
- data: api 调用的参数字典
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_CallingAPIHook](../typing.md#T-CallingAPIHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_CallingAPIHook](../typing.md#T-CallingAPIHook)
|
||||
|
||||
### _classmethod_ `on_called_api(func)` {#Bot-on-called-api}
|
||||
@@ -247,7 +223,6 @@ description: nonebot.adapters 模块
|
||||
调用 api 后处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- exception: 调用 api 时发生的错误
|
||||
- api: 调用的 api 名称
|
||||
@@ -255,11 +230,9 @@ description: nonebot.adapters 模块
|
||||
- result: api 调用的返回
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_CalledAPIHook](../typing.md#T-CalledAPIHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_CalledAPIHook](../typing.md#T-CalledAPIHook)
|
||||
|
||||
## _abstract class_ `Event(<auto>)` {#Event}
|
||||
@@ -279,7 +252,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_event_name()` {#Event-get-event-name}
|
||||
@@ -291,7 +263,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_event_description()` {#Event-get-event-description}
|
||||
@@ -303,7 +274,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `get_log_string()` {#Event-get-log-string}
|
||||
@@ -320,11 +290,9 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
- **异常**
|
||||
|
||||
- NoLogException: 希望 NoneBot 隐藏该事件日志
|
||||
|
||||
### _abstract method_ `get_user_id()` {#Event-get-user-id}
|
||||
@@ -336,7 +304,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_session_id()` {#Event-get-session-id}
|
||||
@@ -348,7 +315,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_message()` {#Event-get-message}
|
||||
@@ -360,7 +326,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Message](#Message)
|
||||
|
||||
### _method_ `get_plaintext()` {#Event-get-plaintext}
|
||||
@@ -376,7 +341,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `is_tome()` {#Event-is-tome}
|
||||
@@ -388,7 +352,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _abstract class_ `Message(<auto>)` {#Message}
|
||||
@@ -396,7 +359,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 消息序列
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message`: 消息内容
|
||||
|
||||
### _classmethod_ `template(format_string)` {#Message-template}
|
||||
@@ -410,11 +372,9 @@ description: nonebot.adapters 模块
|
||||
可以通过该消息类型的 `MessageSegment` 工厂方法创建消息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str | TM): 格式化模板
|
||||
|
||||
- **返回**
|
||||
|
||||
- [MessageTemplate](#MessageTemplate)[Self]: 消息格式化器
|
||||
|
||||
### _abstract classmethod_ `get_segment_class()` {#Message-get-segment-class}
|
||||
@@ -426,7 +386,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[TMS]
|
||||
|
||||
### _abstract staticmethod_ `_construct(msg)` {#Message--construct}
|
||||
@@ -434,11 +393,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 构造消息数组
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Iterable[TMS]
|
||||
|
||||
### _method_ `__getitem__(args)` {#Message---getitem--}
|
||||
@@ -446,53 +403,38 @@ description: nonebot.adapters 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (str): 消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 所有类型为 `args` 的消息段
|
||||
|
||||
**2.** `(args) -> TMS`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (tuple[str, int]): 消息段类型和索引
|
||||
|
||||
- **返回**
|
||||
|
||||
- TMS: 类型为 `args[0]` 的消息段第 `args[1]` 个
|
||||
|
||||
**3.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (tuple[str, slice]): 消息段类型和切片
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 类型为 `args[0]` 的消息段切片 `args[1]`
|
||||
|
||||
**4.** `(args) -> TMS`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (int): 索引
|
||||
|
||||
- **返回**
|
||||
|
||||
- TMS: 第 `args` 个消息段
|
||||
|
||||
**5.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (slice): 切片
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 消息切片 `args`
|
||||
|
||||
### _method_ `__contains__(value)` {#Message---contains--}
|
||||
@@ -500,11 +442,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 检查消息段是否存在
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 消息内是否存在给定消息段或给定类型的消息段
|
||||
|
||||
### _method_ `has(value)` {#Message-has}
|
||||
@@ -512,11 +452,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 与 [`__contains__`](#Message---contains--) 相同
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
### _method_ `index(value, *args)` {#Message-index}
|
||||
@@ -524,7 +462,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 索引消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或者消息段类型
|
||||
|
||||
- `*args` (SupportsIndex)
|
||||
@@ -532,11 +469,9 @@ description: nonebot.adapters 模块
|
||||
- `arg`: start 与 end
|
||||
|
||||
- **返回**
|
||||
|
||||
- int: 索引 index
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 消息段不存在
|
||||
|
||||
### _method_ `get(type_, count=None)` {#Message-get}
|
||||
@@ -544,13 +479,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 获取指定类型的消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (str): 消息段类型
|
||||
|
||||
- `count` (int | None): 获取个数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 构建的新消息
|
||||
|
||||
### _method_ `count(value)` {#Message-count}
|
||||
@@ -558,11 +491,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 计算指定消息段的个数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- int: 个数
|
||||
|
||||
### _method_ `only(value)` {#Message-only}
|
||||
@@ -570,11 +501,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 检查消息中是否仅包含指定消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 指定消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否仅包含指定消息段
|
||||
|
||||
### _method_ `append(obj)` {#Message-append}
|
||||
@@ -582,11 +511,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 添加一个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (str | TMS): 要添加的消息段
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `extend(obj)` {#Message-extend}
|
||||
@@ -594,11 +521,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 拼接一个消息数组或多个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (Self | Iterable[TMS]): 要添加的消息数组
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `join(iterable)` {#Message-join}
|
||||
@@ -606,11 +531,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 将多个消息连接并将自身作为分割
|
||||
|
||||
- **参数**
|
||||
|
||||
- `iterable` (Iterable[TMS | Self]): 要连接的消息
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 连接后的消息
|
||||
|
||||
### _method_ `copy()` {#Message-copy}
|
||||
@@ -622,7 +545,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `include(*types)` {#Message-include}
|
||||
@@ -630,11 +552,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 过滤消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (str): 包含的消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 新构造的消息
|
||||
|
||||
### _method_ `exclude(*types)` {#Message-exclude}
|
||||
@@ -642,11 +562,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 过滤消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (str): 不包含的消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 新构造的消息
|
||||
|
||||
### _method_ `extract_plain_text()` {#Message-extract-plain-text}
|
||||
@@ -658,7 +576,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _abstract class_ `MessageSegment(<auto>)` {#MessageSegment}
|
||||
@@ -690,7 +607,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[TM]
|
||||
|
||||
### _abstract method_ `__str__()` {#MessageSegment---str--}
|
||||
@@ -702,29 +618,24 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `__add__(other)` {#MessageSegment---add--}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `other` (str | TMS | Iterable[TMS])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TM
|
||||
|
||||
### _method_ `get(key, default=None)` {#MessageSegment-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `keys()` {#MessageSegment-keys}
|
||||
@@ -734,7 +645,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `values()` {#MessageSegment-values}
|
||||
@@ -744,7 +654,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `items()` {#MessageSegment-items}
|
||||
@@ -754,17 +663,14 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `join(iterable)` {#MessageSegment-join}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `iterable` (Iterable[TMS | TM])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TM
|
||||
|
||||
### _method_ `copy()` {#MessageSegment-copy}
|
||||
@@ -774,7 +680,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _abstract method_ `is_text()` {#MessageSegment-is-text}
|
||||
@@ -786,7 +691,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `MessageTemplate(template, factory=str, private_getattr=False)` {#MessageTemplate}
|
||||
@@ -794,7 +698,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 消息模板格式化实现类。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `template` (str | TM): 模板
|
||||
|
||||
- `factory` (type[str] | type[TM]): 消息类型工厂,默认为 `str`
|
||||
@@ -804,13 +707,11 @@ description: nonebot.adapters 模块
|
||||
### _method_ `add_format_spec(spec, name=None)` {#MessageTemplate-add-format-spec}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `spec` (FormatSpecFunc_T)
|
||||
|
||||
- `name` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- FormatSpecFunc_T
|
||||
|
||||
### _method_ `format(*args, **kwargs)` {#MessageTemplate-format}
|
||||
@@ -818,13 +719,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 根据传入参数和模板生成消息对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `format_map(mapping)` {#MessageTemplate-format-map}
|
||||
@@ -832,17 +731,14 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 根据传入字典和模板生成消息对象, 在传入字段名不是有效标识符时有用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `mapping` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `vformat(format_string, args, kwargs)` {#MessageTemplate-vformat}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str)
|
||||
|
||||
- `args` (Sequence[Any])
|
||||
@@ -850,13 +746,11 @@ description: nonebot.adapters 模块
|
||||
- `kwargs` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `get_field(field_name, args, kwargs)` {#MessageTemplate-get-field}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field_name` (str)
|
||||
|
||||
- `args` (Sequence[Any])
|
||||
@@ -864,17 +758,14 @@ description: nonebot.adapters 模块
|
||||
- `kwargs` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Any, int | str]
|
||||
|
||||
### _method_ `format_field(value, format_spec)` {#MessageTemplate-format-field}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- `format_spec` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
@@ -36,7 +36,6 @@ description: nonebot.compat 模块
|
||||
- **说明:** FieldInfo class with extra property for compatibility with pydantic v1
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
@@ -82,7 +81,6 @@ description: nonebot.compat 模块
|
||||
- **说明:** Construct a ModelField from given infos.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `annotation` (Any)
|
||||
@@ -90,7 +88,6 @@ description: nonebot.compat 模块
|
||||
- `field_info` (FieldInfo | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `get_default()` {#ModelField-get-default}
|
||||
@@ -102,7 +99,6 @@ description: nonebot.compat 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _method_ `validate_value(value)` {#ModelField-validate-value}
|
||||
@@ -110,11 +106,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate the value pass to the field.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `extract_field_info(field_info)` {#extract-field-info}
|
||||
@@ -122,11 +116,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get FieldInfo init kwargs from a FieldInfo instance.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field_info` (BaseFieldInfo)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `model_fields(model)` {#model-fields}
|
||||
@@ -134,11 +126,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get field list of a model.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (type[BaseModel])
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[ModelField]
|
||||
|
||||
## _def_ `model_config(model)` {#model-config}
|
||||
@@ -146,17 +136,14 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get config of a model.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (type[BaseModel])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `model_dump(model, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)` {#model-dump}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (BaseModel)
|
||||
|
||||
- `include` (set[str] | None)
|
||||
@@ -172,7 +159,6 @@ description: nonebot.compat 模块
|
||||
- `exclude_none` (bool)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `type_validate_python(type_, data)` {#type-validate-python}
|
||||
@@ -180,13 +166,11 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate data with given type.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[T])
|
||||
|
||||
- `data` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T
|
||||
|
||||
## _def_ `type_validate_json(type_, data)` {#type-validate-json}
|
||||
@@ -194,13 +178,11 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate JSON with given type.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[T])
|
||||
|
||||
- `data` (str | bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T
|
||||
|
||||
## _def_ `custom_validation(class_)` {#custom-validation}
|
||||
@@ -208,9 +190,7 @@ description: nonebot.compat 模块
|
||||
- **说明:** Use pydantic v1 like validator generator in pydantic v2
|
||||
|
||||
- **参数**
|
||||
|
||||
- `class_` (type[CVC])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[CVC]
|
||||
|
||||
@@ -24,7 +24,6 @@ NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及
|
||||
将会从 **环境变量** > **dotenv 配置文件** 的优先级读取环境信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
@@ -55,7 +54,6 @@ NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及
|
||||
配置方法参考: [配置](https://nonebot.dev/docs/appendices/config)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
@@ -18,7 +18,6 @@ description: nonebot.dependencies 模块
|
||||
继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `validate` (bool)
|
||||
@@ -30,7 +29,6 @@ description: nonebot.dependencies 模块
|
||||
- **说明:** 依赖注入容器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call`: 依赖注入的可调用对象,可以是任何 Callable 对象
|
||||
|
||||
- `pre_checkers`: 依赖注入解析前的参数检查
|
||||
@@ -44,31 +42,26 @@ description: nonebot.dependencies 模块
|
||||
### _staticmethod_ `parse_params(call, allow_types)` {#Dependent-parse-params}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` (\_DependentCallable[R])
|
||||
|
||||
- `allow_types` (tuple[type[Param], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[[ModelField](../compat.md#ModelField), ...]
|
||||
|
||||
### _staticmethod_ `parse_parameterless(parameterless, allow_types)` {#Dependent-parse-parameterless}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `parameterless` (tuple[Any, ...])
|
||||
|
||||
- `allow_types` (tuple[type[Param], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Param, ...]
|
||||
|
||||
### _classmethod_ `parse(*, call, parameterless=None, allow_types)` {#Dependent-parse}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` (\_DependentCallable[R])
|
||||
|
||||
- `parameterless` (Iterable[Any] | None)
|
||||
@@ -76,25 +69,20 @@ description: nonebot.dependencies 模块
|
||||
- `allow_types` (Iterable[type[Param]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Dependent[R]
|
||||
|
||||
### _async method_ `check(**params)` {#Dependent-check}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `solve(**params)` {#Dependent-solve}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
@@ -12,11 +12,9 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 获取可调用对象签名
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((...) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- inspect.Signature
|
||||
|
||||
## _def_ `get_typed_annotation(param, globalns)` {#get-typed-annotation}
|
||||
@@ -24,13 +22,11 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 获取参数的类型注解
|
||||
|
||||
- **参数**
|
||||
|
||||
- `param` (inspect.Parameter)
|
||||
|
||||
- `globalns` (dict[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `check_field_type(field, value)` {#check-field-type}
|
||||
@@ -38,11 +34,9 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 检查字段类型是否匹配
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field` ([ModelField](../compat.md#ModelField))
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
@@ -22,7 +22,6 @@ pip install nonebot2[aiohttp]
|
||||
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -38,11 +37,9 @@ pip install nonebot2[aiohttp]
|
||||
### _async method_ `request(setup)` {#Session-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _async method_ `setup()` {#Session-setup}
|
||||
@@ -52,7 +49,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close()` {#Session-close}
|
||||
@@ -62,7 +58,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -76,27 +71,22 @@ pip install nonebot2[aiohttp]
|
||||
### _async method_ `request(setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `websocket(setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
|
||||
|
||||
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -110,7 +100,6 @@ pip install nonebot2[aiohttp]
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Session
|
||||
|
||||
## _class_ `WebSocket(*, request, session, websocket)` {#WebSocket}
|
||||
@@ -118,7 +107,6 @@ pip install nonebot2[aiohttp]
|
||||
- **说明:** AIOHTTP Websocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` ([Request](index.md#Request))
|
||||
|
||||
- `session` (aiohttp.ClientSession)
|
||||
@@ -132,19 +120,16 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -154,7 +139,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -164,7 +148,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -174,33 +157,27 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -92,7 +92,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** FastAPI 驱动框架。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` (NoneBotConfig)
|
||||
@@ -124,21 +123,17 @@ pip install nonebot2[fastapi]
|
||||
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
|
||||
@@ -146,7 +141,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** 使用 `uvicorn` 启动 FastAPI
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
@@ -158,7 +152,6 @@ pip install nonebot2[fastapi]
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `FastAPIWebSocket(*, request, websocket)` {#FastAPIWebSocket}
|
||||
@@ -166,7 +159,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** FastAPI WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (BaseRequest)
|
||||
|
||||
- `websocket` ([WebSocket](index.md#WebSocket))
|
||||
@@ -178,19 +170,16 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close(code=status.WS_1000_NORMAL_CLOSURE, reason="")` {#FastAPIWebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `receive()` {#FastAPIWebSocket-receive}
|
||||
@@ -200,7 +189,6 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#FastAPIWebSocket-receive-text}
|
||||
@@ -210,7 +198,6 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#FastAPIWebSocket-receive-bytes}
|
||||
@@ -220,25 +207,20 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#FastAPIWebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#FastAPIWebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
@@ -22,7 +22,6 @@ pip install nonebot2[httpx]
|
||||
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -38,11 +37,9 @@ pip install nonebot2[httpx]
|
||||
### _async method_ `request(setup)` {#Session-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _async method_ `setup()` {#Session-setup}
|
||||
@@ -52,7 +49,6 @@ pip install nonebot2[httpx]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close()` {#Session-close}
|
||||
@@ -62,7 +58,6 @@ pip install nonebot2[httpx]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -76,17 +71,14 @@ pip install nonebot2[httpx]
|
||||
### _async method_ `request(setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -100,13 +92,11 @@ pip install nonebot2[httpx]
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Session
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -40,11 +40,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract method_ `setup_websocket_server(setup)` {#ASGIMixin-setup-websocket-server}
|
||||
@@ -52,23 +50,19 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Cookies(cookies=None)` {#Cookies}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (CookieTypes)
|
||||
|
||||
### _method_ `set(name, value, domain="", path="/")` {#Cookies-set}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `value` (str)
|
||||
@@ -78,13 +72,11 @@ description: nonebot.drivers 模块
|
||||
- `path` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get(name, default=None, domain=None, path=None)` {#Cookies-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `default` (str | None)
|
||||
@@ -94,13 +86,11 @@ description: nonebot.drivers 模块
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | None
|
||||
|
||||
### _method_ `delete(name, domain=None, path=None)` {#Cookies-delete}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `domain` (str | None)
|
||||
@@ -108,39 +98,32 @@ description: nonebot.drivers 模块
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `clear(domain=None, path=None)` {#Cookies-clear}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `domain` (str | None)
|
||||
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `update(cookies=None)` {#Cookies-update}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (CookieTypes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `as_header(request)` {#Cookies-as-header}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, str]
|
||||
|
||||
## _abstract class_ `Driver(env, config)` {#Driver}
|
||||
@@ -152,7 +135,6 @@ description: nonebot.drivers 模块
|
||||
驱动器控制框架的启动和停止,适配器的注册,以及机器人生命周期管理。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env)): 包含环境信息的 Env 对象
|
||||
|
||||
- `config` ([Config](../config.md#Config)): 包含配置信息的 Config 对象
|
||||
@@ -180,13 +162,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个协议适配器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` (type[[Adapter](../adapters/index.md#Adapter)]): 适配器类
|
||||
|
||||
- `**kwargs`: 其他传递给适配器的参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract property_ `type` {#Driver-type}
|
||||
@@ -206,13 +186,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 启动驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `on_startup(func)` {#Driver-on-startup}
|
||||
@@ -220,11 +198,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个启动时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
### _method_ `on_shutdown(func)` {#Driver-on-shutdown}
|
||||
@@ -232,11 +208,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个停止时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
### _classmethod_ `on_bot_connect(func)` {#Driver-on-bot-connect}
|
||||
@@ -246,15 +220,12 @@ description: nonebot.drivers 模块
|
||||
装饰一个函数使他在 bot 连接成功时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_BotConnectionHook](../typing.md#T-BotConnectionHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_BotConnectionHook](../typing.md#T-BotConnectionHook)
|
||||
|
||||
### _classmethod_ `on_bot_disconnect(func)` {#Driver-on-bot-disconnect}
|
||||
@@ -264,15 +235,12 @@ description: nonebot.drivers 模块
|
||||
装饰一个函数使他在 bot 连接断开时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook)
|
||||
|
||||
## _var_ `ForwardDriver` {#ForwardDriver}
|
||||
@@ -306,11 +274,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一个 HTTP 请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](#Response)
|
||||
|
||||
### _abstract method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#HTTPClientMixin-get-session}
|
||||
@@ -318,7 +284,6 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 获取一个 HTTP 会话
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -332,7 +297,6 @@ description: nonebot.drivers 模块
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- HTTPClientSession
|
||||
|
||||
## _class_ `HTTPServerSetup(<auto>)` {#HTTPServerSetup}
|
||||
@@ -350,7 +314,6 @@ description: nonebot.drivers 模块
|
||||
- **参数**
|
||||
|
||||
auto
|
||||
|
||||
- `H10: '1.0'`
|
||||
|
||||
- `H11: '1.1'`
|
||||
@@ -374,7 +337,6 @@ description: nonebot.drivers 模块
|
||||
## _class_ `Request(method, url, *, params=None, headers=None, cookies=None, content=None, data=None, json=None, files=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `method` (str | bytes)
|
||||
|
||||
- `url` (URL | str | RawURL)
|
||||
@@ -402,7 +364,6 @@ description: nonebot.drivers 模块
|
||||
## _class_ `Response(status_code, *, headers=None, content=None, request=None)` {#Response}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `status_code` (int)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -432,7 +393,6 @@ description: nonebot.drivers 模块
|
||||
## _abstract class_ `WebSocket(*, request)` {#WebSocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (Request)
|
||||
|
||||
### _abstract property_ `closed` {#WebSocket-closed}
|
||||
@@ -450,7 +410,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
@@ -458,13 +417,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 关闭 WebSocket 连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -476,7 +433,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _abstract async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -488,7 +444,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -500,7 +455,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send(data)` {#WebSocket-send}
|
||||
@@ -508,11 +462,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket text/bytes 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str | bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
@@ -520,11 +472,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket text 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
@@ -532,11 +482,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket binary 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _abstract class_ `WebSocketClientMixin(<auto>)` {#WebSocketClientMixin}
|
||||
@@ -552,11 +500,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发起一个 WebSocket 连接
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](#WebSocket), None]
|
||||
|
||||
## _class_ `WebSocketServerSetup(<auto>)` {#WebSocketServerSetup}
|
||||
@@ -574,19 +520,14 @@ description: nonebot.drivers 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(driver) -> type[D]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (type[D])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[D]
|
||||
|
||||
**2.** `(driver, __m, /, *mixins) -> type[CombinedDriver]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (type[D])
|
||||
|
||||
- `__m` (type[[Mixin](#Mixin)])
|
||||
@@ -594,5 +535,4 @@ description: nonebot.drivers 模块
|
||||
- `*mixins` (type[[Mixin](#Mixin)])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[CombinedDriver]
|
||||
|
||||
@@ -18,7 +18,6 @@ None 驱动适配
|
||||
- **说明:** None 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
@@ -40,13 +39,11 @@ None 驱动适配
|
||||
- **说明:** 启动 none driver
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `exit(force=False)` {#Driver-exit}
|
||||
@@ -54,9 +51,7 @@ None 驱动适配
|
||||
- **说明:** 退出 none driver
|
||||
|
||||
- **参数**
|
||||
|
||||
- `force` (bool): 强制退出
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
@@ -68,7 +68,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** Quart 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` (NoneBotConfig)
|
||||
@@ -100,21 +99,17 @@ pip install nonebot2[quart]
|
||||
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
|
||||
@@ -122,7 +117,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** 使用 `uvicorn` 启动 Quart
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
@@ -134,7 +128,6 @@ pip install nonebot2[quart]
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket_ctx)` {#WebSocket}
|
||||
@@ -142,7 +135,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** Quart WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (BaseRequest)
|
||||
|
||||
- `websocket_ctx` (WebsocketContext)
|
||||
@@ -154,19 +146,16 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -176,7 +165,6 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -186,7 +174,6 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -196,25 +183,20 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
@@ -22,11 +22,9 @@ pip install nonebot2[websockets]
|
||||
## _def_ `catch_closed(func)` {#catch-closed}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((P) -> CoroutineType[Any, Any, T])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (P) -> CoroutineType[Any, Any, T]
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -40,11 +38,9 @@ pip install nonebot2[websockets]
|
||||
### _method_ `websocket(setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket)` {#WebSocket}
|
||||
@@ -52,7 +48,6 @@ pip install nonebot2[websockets]
|
||||
- **说明:** Websockets WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` ([Request](index.md#Request))
|
||||
|
||||
- `websocket` (WebSocketClientProtocol)
|
||||
@@ -64,19 +59,16 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -86,7 +78,6 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -96,7 +87,6 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -106,33 +96,27 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -62,7 +62,6 @@ NoneBotException
|
||||
- **说明:** 指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `reason`: 忽略事件的原因
|
||||
|
||||
## _class_ `SkippedException(<auto>)` {#SkippedException}
|
||||
@@ -101,7 +100,6 @@ NoneBotException
|
||||
- **说明:** 指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。 可由 api hook 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `result`: 返回的内容
|
||||
|
||||
## _class_ `StopPropagation(<auto>)` {#StopPropagation}
|
||||
@@ -200,7 +198,6 @@ NoneBotException
|
||||
- **说明:** 代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name`: 标识 adapter
|
||||
|
||||
## _class_ `NoLogException(<auto>)` {#NoLogException}
|
||||
|
||||
@@ -60,11 +60,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Driver](drivers/index.md#Driver): 全局 [Driver](drivers/index.md#Driver) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -80,27 +78,20 @@ description: nonebot 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(name) -> Adapter`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 适配器名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Adapter](adapters/index.md#Adapter): 指定名称的 [Adapter](adapters/index.md#Adapter) 对象
|
||||
|
||||
**2.** `(name) -> A`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (type[A]): 适配器类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- A: 指定类型的 [Adapter](adapters/index.md#Adapter) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 指定的 [Adapter](adapters/index.md#Adapter) 未注册
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -121,11 +112,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, [Adapter](adapters/index.md#Adapter)]: 所有 [Adapter](adapters/index.md#Adapter) 实例字典
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -143,11 +132,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: Server App 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- AssertionError: 全局 Driver 对象不是 [ASGIMixin](drivers/index.md#ASGIMixin) 类型
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -167,11 +154,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: ASGI 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- AssertionError: 全局 Driver 对象不是 [ASGIMixin](drivers/index.md#ASGIMixin) 类型
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -192,15 +177,12 @@ description: nonebot 模块
|
||||
当不提供时,返回一个 [Bot](adapters/index.md#Bot)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `self_id` (str | None): 用来识别 [Bot](adapters/index.md#Bot) 的 [Bot.self_id](adapters/index.md#Bot-self-id) 属性
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Bot](adapters/index.md#Bot): [Bot](adapters/index.md#Bot) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- KeyError: 对应 self_id 的 Bot 不存在
|
||||
|
||||
- ValueError: 没有传入 self_id 且没有 Bot 可用
|
||||
@@ -224,13 +206,11 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, [Bot](adapters/index.md#Bot)]: 一个以 [Bot.self_id](adapters/index.md#Bot-self-id) 为键
|
||||
|
||||
[Bot](adapters/index.md#Bot) 对象为值的字典
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -250,13 +230,11 @@ description: nonebot 模块
|
||||
也可以传入自定义的 `_env_file` 来指定 NoneBot 从该文件读取配置。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None): 配置文件名,默认从 `.env.{env_name}` 中读取配置
|
||||
|
||||
- `**kwargs` (Any): 任意变量,将会存储到 [Driver.config](drivers/index.md#Driver-config) 对象里
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
@@ -270,13 +248,11 @@ description: nonebot 模块
|
||||
- **说明:** 启动 NoneBot,即运行全局 [Driver](drivers/index.md#Driver) 对象。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args` (Any): 传入 [Driver.run](drivers/index.md#Driver-run) 的位置参数
|
||||
|
||||
- `**kwargs` (Any): 传入 [Driver.run](drivers/index.md#Driver-run) 的命名参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
@@ -25,7 +25,6 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
NoneBot 日志记录器对象。
|
||||
|
||||
默认信息:
|
||||
|
||||
- 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
|
||||
- 等级: `INFO` ,根据 `config.log_level` 配置改变
|
||||
- 输出: 输出至 stdout
|
||||
@@ -47,11 +46,9 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
### _method_ `emit(record)` {#LoguruHandler-emit}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (logging.LogRecord)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _def_ `default_filter(record)` {#default-filter}
|
||||
@@ -59,11 +56,9 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
- **说明:** 默认的日志过滤器,根据 `config.log_level` 配置改变日志等级。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (Record)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _var_ `default_format` {#default-format}
|
||||
|
||||
@@ -76,7 +76,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 创建一个新的事件响应器,并存储至 `matchers <#matchers>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (str): 事件响应器类型,与 `event.get_type()` 一致时触发,空字符串表示任意
|
||||
|
||||
- `rule` ([Rule](rule.md#Rule) | None): 匹配规则
|
||||
@@ -106,7 +105,6 @@ description: nonebot.matcher 模块
|
||||
- `default_permission_updater` ([T_PermissionUpdater](typing.md#T-PermissionUpdater) | [Dependent](dependencies/index.md#Dependent)[[Permission](permission.md#Permission)] | None): 默认会话权限更新函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[Matcher]: 新的事件响应器类
|
||||
|
||||
### _classmethod_ `destroy()` {#Matcher-destroy}
|
||||
@@ -118,7 +116,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _classmethod_ `check_perm(bot, event, stack=None, dependency_cache=None)` {#Matcher-check-perm}
|
||||
@@ -126,7 +123,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 检查是否满足触发权限
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): 上报事件
|
||||
@@ -136,7 +132,6 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否满足权限
|
||||
|
||||
### _classmethod_ `check_rule(bot, event, state, stack=None, dependency_cache=None)` {#Matcher-check-rule}
|
||||
@@ -144,7 +139,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 检查是否满足匹配规则
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): 上报事件
|
||||
@@ -156,7 +150,6 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否满足匹配规则
|
||||
|
||||
### _classmethod_ `type_updater(func)` {#Matcher-type-updater}
|
||||
@@ -164,11 +157,9 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 装饰一个函数来更改当前事件响应器的默认响应事件类型更新函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_TypeUpdater](typing.md#T-TypeUpdater)): 响应事件类型更新函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_TypeUpdater](typing.md#T-TypeUpdater)
|
||||
|
||||
### _classmethod_ `permission_updater(func)` {#Matcher-permission-updater}
|
||||
@@ -176,23 +167,19 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 装饰一个函数来更改当前事件响应器的默认会话权限更新函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_PermissionUpdater](typing.md#T-PermissionUpdater)): 会话权限更新函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_PermissionUpdater](typing.md#T-PermissionUpdater)
|
||||
|
||||
### _classmethod_ `append_handler(handler, parameterless=None)` {#Matcher-append-handler}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `handler` ([T_Handler](typing.md#T-Handler))
|
||||
|
||||
- `parameterless` (Iterable[Any] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Dependent](dependencies/index.md#Dependent)[Any]
|
||||
|
||||
### _classmethod_ `handle(parameterless=None)` {#Matcher-handle}
|
||||
@@ -200,11 +187,9 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 装饰一个函数来向事件响应器直接添加一个处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ([T_Handler](typing.md#T-Handler)) -> [T_Handler](typing.md#T-Handler)
|
||||
|
||||
### _classmethod_ `receive(id="", parameterless=None)` {#Matcher-receive}
|
||||
@@ -212,13 +197,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 装饰一个函数来指示 NoneBot 在接收用户新的一条消息后继续运行该函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str): 消息 ID
|
||||
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ([T_Handler](typing.md#T-Handler)) -> [T_Handler](typing.md#T-Handler)
|
||||
|
||||
### _classmethod_ `got(key, prompt=None, parameterless=None)` {#Matcher-got}
|
||||
@@ -231,7 +214,6 @@ description: nonebot.matcher 模块
|
||||
如果 `key` 已存在则直接继续运行
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str): 参数名
|
||||
|
||||
- `prompt` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 在参数不存在时向用户发送的消息
|
||||
@@ -239,7 +221,6 @@ description: nonebot.matcher 模块
|
||||
- `parameterless` (Iterable[Any] | None): 非参数类型依赖列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- ([T_Handler](typing.md#T-Handler)) -> [T_Handler](typing.md#T-Handler)
|
||||
|
||||
### _classmethod_ `send(message, **kwargs)` {#Matcher-send}
|
||||
@@ -247,13 +228,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 发送一条消息给当前交互用户
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate)): 消息内容
|
||||
|
||||
- `**kwargs` (Any): [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _classmethod_ `finish(message=None, **kwargs)` {#Matcher-finish}
|
||||
@@ -261,13 +240,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 发送一条消息给当前交互用户并结束当前事件响应器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `pause(prompt=None, **kwargs)` {#Matcher-pause}
|
||||
@@ -275,13 +252,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 发送一条消息给当前交互用户并暂停事件响应器,在接收用户新的一条消息后继续下一个处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `prompt` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `reject(prompt=None, **kwargs)` {#Matcher-reject}
|
||||
@@ -289,13 +264,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 最近使用 `got` / `receive` 接收的消息不符合预期, 发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一个事件后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `prompt` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 消息内容
|
||||
|
||||
- `**kwargs`: [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `reject_arg(key, prompt=None, **kwargs)` {#Matcher-reject-arg}
|
||||
@@ -303,7 +276,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 最近使用 `got` 接收的消息不符合预期, 发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一条消息后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str): 参数名
|
||||
|
||||
- `prompt` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 消息内容
|
||||
@@ -311,7 +283,6 @@ description: nonebot.matcher 模块
|
||||
- `**kwargs`: [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `reject_receive(id="", prompt=None, **kwargs)` {#Matcher-reject-receive}
|
||||
@@ -319,7 +290,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 最近使用 `receive` 接收的消息不符合预期, 发送一条消息给当前交互用户并将当前事件处理流程中断在当前位置,在接收用户新的一个事件后从头开始执行当前处理函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str): 消息 id
|
||||
|
||||
- `prompt` (str | [Message](adapters/index.md#Message) | [MessageSegment](adapters/index.md#MessageSegment) | [MessageTemplate](adapters/index.md#MessageTemplate) | None): 消息内容
|
||||
@@ -327,7 +297,6 @@ description: nonebot.matcher 模块
|
||||
- `**kwargs`: [Bot.send](adapters/index.md#Bot-send) 的参数, 请参考对应 adapter 的 bot 对象 api
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _classmethod_ `skip()` {#Matcher-skip}
|
||||
@@ -343,7 +312,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- NoReturn
|
||||
|
||||
### _method_ `get_receive(id, default=None)` {#Matcher-get-receive}
|
||||
@@ -357,25 +325,19 @@ description: nonebot.matcher 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(id) -> Event | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Event](adapters/index.md#Event) | None
|
||||
|
||||
**2.** `(id, default) -> Event | T`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str)
|
||||
|
||||
- `default` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Event](adapters/index.md#Event) | T
|
||||
|
||||
### _method_ `set_receive(id, event)` {#Matcher-set-receive}
|
||||
@@ -383,13 +345,11 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 设置一个 `receive` 事件
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str)
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get_last_receive(default=None)` {#Matcher-get-last-receive}
|
||||
@@ -403,23 +363,18 @@ description: nonebot.matcher 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `() -> Event | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Event](adapters/index.md#Event) | None
|
||||
|
||||
**2.** `(default) -> Event | T`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Event](adapters/index.md#Event) | T
|
||||
|
||||
### _method_ `get_arg(key, default=None)` {#Matcher-get-arg}
|
||||
@@ -433,25 +388,19 @@ description: nonebot.matcher 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(key) -> Message | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Message](adapters/index.md#Message) | None
|
||||
|
||||
**2.** `(key, default) -> Message | T`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `default` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Message](adapters/index.md#Message) | T
|
||||
|
||||
### _method_ `set_arg(key, message)` {#Matcher-set-arg}
|
||||
@@ -459,25 +408,21 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 设置一个 `got` 消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `message` ([Message](adapters/index.md#Message))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `set_target(target, cache=True)` {#Matcher-set-target}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `target` (str)
|
||||
|
||||
- `cache` (bool)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get_target(default=None)` {#Matcher-get-target}
|
||||
@@ -485,23 +430,18 @@ description: nonebot.matcher 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `() -> str | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | None
|
||||
|
||||
**2.** `(default) -> str | T`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | T
|
||||
|
||||
### _method_ `stop_propagation()` {#Matcher-stop-propagation}
|
||||
@@ -513,13 +453,11 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `update_type(bot, event, stack=None, dependency_cache=None)` {#Matcher-update-type}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot))
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
@@ -529,13 +467,11 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `update_permission(bot, event, stack=None, dependency_cache=None)` {#Matcher-update-permission}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot))
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
@@ -545,7 +481,6 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Permission](permission.md#Permission)
|
||||
|
||||
### _async method_ `resolve_reject()` {#Matcher-resolve-reject}
|
||||
@@ -555,25 +490,21 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `ensure_context(bot, event)` {#Matcher-ensure-context}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot))
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `simple_run(bot, event, state, stack=None, dependency_cache=None)` {#Matcher-simple-run}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot))
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
@@ -585,13 +516,11 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `run(bot, event, state, stack=None, dependency_cache=None)` {#Matcher-run}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot))
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event))
|
||||
@@ -603,7 +532,6 @@ description: nonebot.matcher 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `MatcherManager()` {#MatcherManager}
|
||||
@@ -625,7 +553,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- KeysView[int]
|
||||
|
||||
### _method_ `values()` {#MatcherManager-values}
|
||||
@@ -635,7 +562,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- ValuesView[list[type[[Matcher](#Matcher)]]]
|
||||
|
||||
### _method_ `items()` {#MatcherManager-items}
|
||||
@@ -645,7 +571,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- ItemsView[int, list[type[[Matcher](#Matcher)]]]
|
||||
|
||||
### _method_ `get(key, default=None)` {#MatcherManager-get}
|
||||
@@ -653,35 +578,27 @@ description: nonebot.matcher 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(key) -> list[type[Matcher]] | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[type[[Matcher](#Matcher)]] | None
|
||||
|
||||
**2.** `(key, default) -> list[type[Matcher]] | T`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- `default` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[type[[Matcher](#Matcher)]] | T
|
||||
|
||||
### _method_ `pop(key)` {#MatcherManager-pop}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[type[[Matcher](#Matcher)]]
|
||||
|
||||
### _method_ `popitem()` {#MatcherManager-popitem}
|
||||
@@ -691,7 +608,6 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[int, list[type[[Matcher](#Matcher)]]]
|
||||
|
||||
### _method_ `clear()` {#MatcherManager-clear}
|
||||
@@ -701,29 +617,24 @@ description: nonebot.matcher 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `update(m, /)` {#MatcherManager-update}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `m` (MutableMapping[int, list[type[[Matcher](#Matcher)]]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `setdefault(key, default)` {#MatcherManager-setdefault}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (int)
|
||||
|
||||
- `default` (list[type[[Matcher](#Matcher)]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[type[[Matcher](#Matcher)]]
|
||||
|
||||
### _method_ `set_provider(provider_class)` {#MatcherManager-set-provider}
|
||||
@@ -731,11 +642,9 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 设置事件响应器存储器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `provider_class` (type[[MatcherProvider](#MatcherProvider)]): 事件响应器存储器类
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _abstract class_ `MatcherProvider(matchers)` {#MatcherProvider}
|
||||
@@ -743,7 +652,6 @@ description: nonebot.matcher 模块
|
||||
- **说明:** 事件响应器存储器基类
|
||||
|
||||
- **参数**
|
||||
|
||||
- `matchers` (Mapping[int, list[type[[Matcher](#Matcher)]]]): 当前存储器中已有的事件响应器
|
||||
|
||||
## _var_ `matchers` {#matchers}
|
||||
|
||||
@@ -20,11 +20,9 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
装饰一个函数,使它在每次接收到事件并分发给各响应器之前执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_EventPreProcessor](typing.md#T-EventPreProcessor))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_EventPreProcessor](typing.md#T-EventPreProcessor)
|
||||
|
||||
## _def_ `event_postprocessor(func)` {#event-postprocessor}
|
||||
@@ -36,11 +34,9 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
装饰一个函数,使它在每次接收到事件并分发给各响应器之后执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_EventPostProcessor](typing.md#T-EventPostProcessor))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_EventPostProcessor](typing.md#T-EventPostProcessor)
|
||||
|
||||
## _def_ `run_preprocessor(func)` {#run-preprocessor}
|
||||
@@ -52,11 +48,9 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
装饰一个函数,使它在每次事件响应器运行前执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_RunPreProcessor](typing.md#T-RunPreProcessor))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_RunPreProcessor](typing.md#T-RunPreProcessor)
|
||||
|
||||
## _def_ `run_postprocessor(func)` {#run-postprocessor}
|
||||
@@ -68,11 +62,9 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
装饰一个函数,使它在每次事件响应器运行后执行。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_RunPostProcessor](typing.md#T-RunPostProcessor))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_RunPostProcessor](typing.md#T-RunPostProcessor)
|
||||
|
||||
## _async def_ `check_and_run_matcher(Matcher, bot, event, state, stack=None, dependency_cache=None)` {#check-and-run-matcher}
|
||||
@@ -80,7 +72,6 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
- **说明:** 检查并运行事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `Matcher` (type[[Matcher](matcher.md#Matcher)]): 事件响应器
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
@@ -94,7 +85,6 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _async def_ `handle_event(bot, event)` {#handle-event}
|
||||
@@ -102,13 +92,11 @@ NoneBot 内部处理并按优先级分发事件给所有事件响应器,提供
|
||||
- **说明:** 处理一个事件。调用该函数以实现分发事件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): Event 对象
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
@@ -14,11 +14,9 @@ description: nonebot.params 模块
|
||||
- **说明:** Arg 参数消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _class_ `ArgParam(*args, key, type, **kwargs)` {#ArgParam}
|
||||
@@ -33,7 +31,6 @@ description: nonebot.params 模块
|
||||
留空则会根据参数名称获取。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `key` (str)
|
||||
@@ -47,11 +44,9 @@ description: nonebot.params 模块
|
||||
- **说明:** Arg 参数消息纯文本
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `ArgPromptResult(key=None)` {#ArgPromptResult}
|
||||
@@ -59,11 +54,9 @@ description: nonebot.params 模块
|
||||
- **说明:** `arg` prompt 发送结果
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `ArgStr(key=None)` {#ArgStr}
|
||||
@@ -71,11 +64,9 @@ description: nonebot.params 模块
|
||||
- **说明:** Arg 参数消息文本
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _class_ `BotParam(*args, checker=None, **kwargs)` {#BotParam}
|
||||
@@ -89,7 +80,6 @@ description: nonebot.params 模块
|
||||
为保证兼容性,本注入还会解析名为 `bot` 且没有类型注解的参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `checker` ([ModelField](compat.md#ModelField) | None)
|
||||
@@ -107,7 +97,6 @@ description: nonebot.params 模块
|
||||
本注入参数应该具有最低优先级,因此应该在所有其他注入参数之后使用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `validate` (bool)
|
||||
@@ -125,7 +114,6 @@ description: nonebot.params 模块
|
||||
本注入应该具有最高优先级,因此应该在其他参数之前检查。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `dependent` ([Dependent](dependencies/index.md#Dependent)[Any])
|
||||
@@ -139,7 +127,6 @@ description: nonebot.params 模块
|
||||
- **说明:** 子依赖装饰器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `dependency` ([T_Handler](typing.md#T-Handler) | None): 依赖函数。默认为参数的类型注释。
|
||||
|
||||
- `use_cache` (bool): 是否使用缓存。默认为 `True`。
|
||||
@@ -147,7 +134,6 @@ description: nonebot.params 模块
|
||||
- `validate` (bool | PydanticFieldInfo): 是否使用 Pydantic 类型校验。默认为 `False`。
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
- **用法**
|
||||
@@ -180,7 +166,6 @@ description: nonebot.params 模块
|
||||
为保证兼容性,本注入还会解析名为 `event` 且没有类型注解的参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `checker` ([ModelField](compat.md#ModelField) | None)
|
||||
@@ -198,7 +183,6 @@ description: nonebot.params 模块
|
||||
为保证兼容性,本注入还会解析名为 `exception` 且没有类型注解的参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `validate` (bool)
|
||||
@@ -216,7 +200,6 @@ description: nonebot.params 模块
|
||||
为保证兼容性,本注入还会解析名为 `matcher` 且没有类型注解的参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `checker` ([ModelField](compat.md#ModelField) | None)
|
||||
@@ -234,7 +217,6 @@ description: nonebot.params 模块
|
||||
为保证兼容性,本注入还会解析名为 `state` 且没有类型注解的参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `validate` (bool)
|
||||
@@ -250,7 +232,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `EventMessage()` {#EventMessage}
|
||||
@@ -262,7 +243,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `EventPlainText()` {#EventPlainText}
|
||||
@@ -274,7 +254,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `EventToMe()` {#EventToMe}
|
||||
@@ -286,7 +265,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `Command()` {#Command}
|
||||
@@ -298,7 +276,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[str, ...]
|
||||
|
||||
## _def_ `RawCommand()` {#RawCommand}
|
||||
@@ -310,7 +287,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `CommandArg()` {#CommandArg}
|
||||
@@ -322,7 +298,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `CommandStart()` {#CommandStart}
|
||||
@@ -334,7 +309,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `CommandWhitespace()` {#CommandWhitespace}
|
||||
@@ -346,7 +320,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `ShellCommandArgs()` {#ShellCommandArgs}
|
||||
@@ -358,7 +331,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `ShellCommandArgv()` {#ShellCommandArgv}
|
||||
@@ -370,7 +342,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `RegexMatched()` {#RegexMatched}
|
||||
@@ -382,7 +353,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Match[str]
|
||||
|
||||
## _def_ `RegexStr(*groups)` {#RegexStr}
|
||||
@@ -392,29 +362,21 @@ description: nonebot.params 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(group, /) -> str`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `group` (Literal[0])
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
**2.** `(group, /) -> str | Any`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `group` (str | int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | Any
|
||||
|
||||
**3.** `(group1, group2, /, *groups) -> tuple[str | Any, ...]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `group1` (str | int)
|
||||
|
||||
- `group2` (str | int)
|
||||
@@ -422,7 +384,6 @@ description: nonebot.params 模块
|
||||
- `*groups` (str | int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[str | Any, ...]
|
||||
|
||||
## _def_ `RegexGroup()` {#RegexGroup}
|
||||
@@ -434,7 +395,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Any, ...]
|
||||
|
||||
## _def_ `RegexDict()` {#RegexDict}
|
||||
@@ -446,7 +406,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `Startswith()` {#Startswith}
|
||||
@@ -458,7 +417,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Endswith()` {#Endswith}
|
||||
@@ -470,7 +428,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Fullmatch()` {#Fullmatch}
|
||||
@@ -482,7 +439,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Keyword()` {#Keyword}
|
||||
@@ -494,7 +450,6 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `Received(id=None, default=None)` {#Received}
|
||||
@@ -502,13 +457,11 @@ description: nonebot.params 模块
|
||||
- **说明:** `receive` 事件参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str | None)
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `LastReceived(default=None)` {#LastReceived}
|
||||
@@ -516,11 +469,9 @@ description: nonebot.params 模块
|
||||
- **说明:** `last_receive` 事件参数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `ReceivePromptResult(id=None)` {#ReceivePromptResult}
|
||||
@@ -528,11 +479,9 @@ description: nonebot.params 模块
|
||||
- **说明:** `receive` prompt 发送结果
|
||||
|
||||
- **参数**
|
||||
|
||||
- `id` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `PausePromptResult()` {#PausePromptResult}
|
||||
@@ -544,5 +493,4 @@ description: nonebot.params 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
@@ -22,7 +22,6 @@ description: nonebot.permission 模块
|
||||
如果 `perm` 中仅有 `User` 类型的权限检查函数,则会去除原有检查函数的会话 ID 限制。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*users` (str)
|
||||
|
||||
- `perm` (Permission | None): 需要同时满足的权限
|
||||
@@ -30,7 +29,6 @@ description: nonebot.permission 模块
|
||||
- `user`: 会话白名单
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `Permission(*checkers)` {#Permission}
|
||||
@@ -42,7 +40,6 @@ description: nonebot.permission 模块
|
||||
当事件传递时,在 [Matcher](matcher.md#Matcher) 运行前进行检查。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*checkers` ([T_PermissionChecker](typing.md#T-PermissionChecker) | [Dependent](dependencies/index.md#Dependent)[bool]): PermissionChecker
|
||||
|
||||
- **用法**
|
||||
@@ -64,7 +61,6 @@ description: nonebot.permission 模块
|
||||
- **说明:** 检查是否满足某个权限。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): Event 对象
|
||||
@@ -74,7 +70,6 @@ description: nonebot.permission 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `User(users, perm=None)` {#User}
|
||||
@@ -82,7 +77,6 @@ description: nonebot.permission 模块
|
||||
- **说明:** 检查当前事件是否属于指定会话。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `users` (tuple[str, ...]): 会话 ID 元组
|
||||
|
||||
- `perm` (Permission | None): 需同时满足的权限
|
||||
@@ -96,13 +90,11 @@ description: nonebot.permission 模块
|
||||
如果 `perm` 中仅有 `User` 类型的权限检查函数,则会去除原有的会话 ID 限制。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): Event 对象
|
||||
|
||||
- `perm` (Permission | None): 需同时满足的权限
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _classmethod_ `from_permission(*users, perm=None)` {#User-from-permission}
|
||||
@@ -114,13 +106,11 @@ description: nonebot.permission 模块
|
||||
如果 `perm` 中仅有 `User` 类型的权限检查函数,则会去除原有的会话 ID 限制。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*users` (str): 会话白名单
|
||||
|
||||
- `perm` (Permission | None): 需同时满足的权限
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
## _class_ `Message(<auto>)` {#Message}
|
||||
|
||||
@@ -51,11 +51,9 @@ description: nonebot.plugin 模块
|
||||
如果为嵌套的子插件,标识符为 `父插件标识符:子插件文件(夹)名`。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `plugin_id` (str): 插件标识符,即 [Plugin.id\_](model.md#Plugin-id-)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
## _def_ `get_plugin_by_module_name(module_name)` {#get-plugin-by-module-name}
|
||||
@@ -67,11 +65,9 @@ description: nonebot.plugin 模块
|
||||
如果提供的模块名为某个插件的子模块,同样会返回该插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_name` (str): 模块名,即 [Plugin.module_name](model.md#Plugin-module-name)。
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
## _def_ `get_loaded_plugins()` {#get-loaded-plugins}
|
||||
@@ -83,7 +79,6 @@ description: nonebot.plugin 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
## _def_ `get_available_plugin_names()` {#get-available-plugin-names}
|
||||
@@ -95,7 +90,6 @@ description: nonebot.plugin 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[str]
|
||||
|
||||
## _def_ `get_plugin_config(config)` {#get-plugin-config}
|
||||
@@ -103,9 +97,7 @@ description: nonebot.plugin 模块
|
||||
- **说明:** 从全局配置获取当前插件需要的配置项。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `config` (type[C])
|
||||
|
||||
- **返回**
|
||||
|
||||
- C
|
||||
|
||||
@@ -14,11 +14,9 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 加载单个插件,可以是本地插件或是通过 `pip` 安装的插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_path` (str | Path): 插件名称 `path.to.your.plugin` 或插件路径 `pathlib.Path(path/to/your/plugin)`
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
## _def_ `load_plugins(*plugin_dir)` {#load-plugins}
|
||||
@@ -26,11 +24,9 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入文件夹下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*plugin_dir` (str): 文件夹路径
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
## _def_ `load_all_plugins(module_path, plugin_dir)` {#load-all-plugins}
|
||||
@@ -38,13 +34,11 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入指定列表中的插件以及指定目录下多个插件,以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module_path` (Iterable[str]): 指定插件集合
|
||||
|
||||
- `plugin_dir` (Iterable[str]): 指定文件夹路径集合
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
## _def_ `load_from_json(file_path, encoding="utf-8")` {#load-from-json}
|
||||
@@ -52,13 +46,11 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入指定 json 文件中的 `plugins` 以及 `plugin_dirs` 下多个插件。 以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `file_path` (str): 指定 json 文件路径
|
||||
|
||||
- `encoding` (str): 指定 json 文件编码
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
- **用法**
|
||||
@@ -79,13 +71,11 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入指定 toml 文件 `[tool.nonebot]` 中的 `plugins` 以及 `plugin_dirs` 下多个插件。 以 `_` 开头的插件不会被导入!
|
||||
|
||||
- **参数**
|
||||
|
||||
- `file_path` (str): 指定 toml 文件路径
|
||||
|
||||
- `encoding` (str): 指定 toml 文件编码
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
- **用法**
|
||||
@@ -105,11 +95,9 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入 NoneBot 内置插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
## _def_ `load_builtin_plugins(*plugins)` {#load-builtin-plugins}
|
||||
@@ -117,11 +105,9 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 导入多个 NoneBot 内置插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*plugins` (str): 插件名称列表
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
## _def_ `require(name)` {#require}
|
||||
@@ -129,15 +115,12 @@ description: nonebot.plugin.load 模块
|
||||
- **说明:** 声明依赖插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件模块名或插件标识符,仅在已声明插件的情况下可使用标识符。
|
||||
|
||||
- **返回**
|
||||
|
||||
- ModuleType
|
||||
|
||||
- **异常**
|
||||
|
||||
- RuntimeError: 插件无法加载
|
||||
|
||||
## _def_ `inherit_supported_adapters(*names)` {#inherit-supported-adapters}
|
||||
@@ -149,15 +132,12 @@ description: nonebot.plugin.load 模块
|
||||
如果传入了多个插件名称,返回值会自动取交集。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*names` (str): 插件名称列表。
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[str] | None
|
||||
|
||||
- **异常**
|
||||
|
||||
- RuntimeError: 插件未加载
|
||||
|
||||
- ValueError: 插件缺少元数据
|
||||
|
||||
@@ -16,7 +16,6 @@ description: nonebot.plugin.manager 模块
|
||||
- **说明:** 插件管理器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `plugins` (Iterable[str] | None): 独立插件模块名集合。
|
||||
|
||||
- `search_path` (Iterable[str] | None): 插件搜索路径(文件夹),相对于当前工作目录。
|
||||
@@ -54,11 +53,9 @@ description: nonebot.plugin.manager 模块
|
||||
可以使用完整插件模块名或者插件标识符加载。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 插件名称或插件标识符。
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
### _method_ `load_all_plugins()` {#PluginManager-load-all-plugins}
|
||||
@@ -70,7 +67,6 @@ description: nonebot.plugin.manager 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[[Plugin](model.md#Plugin)]
|
||||
|
||||
## _class_ `PluginFinder(<auto>)` {#PluginFinder}
|
||||
@@ -82,7 +78,6 @@ description: nonebot.plugin.manager 模块
|
||||
### _method_ `find_spec(fullname, path, target=None)` {#PluginFinder-find-spec}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `fullname` (str)
|
||||
|
||||
- `path` (Sequence[str] | None)
|
||||
@@ -90,13 +85,11 @@ description: nonebot.plugin.manager 模块
|
||||
- `target` (ModuleType | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `PluginLoader(manager, fullname, path)` {#PluginLoader}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `manager` (PluginManager)
|
||||
|
||||
- `fullname` (str)
|
||||
@@ -106,19 +99,15 @@ description: nonebot.plugin.manager 模块
|
||||
### _method_ `create_module(spec)` {#PluginLoader-create-module}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `spec`
|
||||
|
||||
- **返回**
|
||||
|
||||
- ModuleType | None
|
||||
|
||||
### _method_ `exec_module(module)` {#PluginLoader-exec-module}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `module` (ModuleType)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
@@ -80,7 +80,6 @@ description: nonebot.plugin.model 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- set[type[[Adapter](../adapters/index.md#Adapter)]] | None
|
||||
|
||||
## _class_ `Plugin(<auto>)` {#Plugin}
|
||||
|
||||
@@ -14,11 +14,9 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 存储一个事件响应器到插件。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `matcher` (type[[Matcher](../matcher.md#Matcher)]): 事件响应器
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _def_ `get_matcher_plugin(depth=...)` {#get-matcher-plugin}
|
||||
@@ -30,11 +28,9 @@ description: nonebot.plugin.on 模块
|
||||
**Deprecated**, 请使用 [get_matcher_source](#get-matcher-source) 获取信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `depth` (int): 调用栈深度
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Plugin](model.md#Plugin) | None
|
||||
|
||||
## _def_ `get_matcher_module(depth=...)` {#get-matcher-module}
|
||||
@@ -46,11 +42,9 @@ description: nonebot.plugin.on 模块
|
||||
**Deprecated**, 请使用 [get_matcher_source](#get-matcher-source) 获取信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `depth` (int): 调用栈深度
|
||||
|
||||
- **返回**
|
||||
|
||||
- ModuleType | None
|
||||
|
||||
## _def_ `get_matcher_source(depth=...)` {#get-matcher-source}
|
||||
@@ -58,11 +52,9 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 获取事件响应器定义所在源码信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `depth` (int): 调用栈深度
|
||||
|
||||
- **返回**
|
||||
|
||||
- MatcherSource | None
|
||||
|
||||
## _def_ `on(type="", rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on}
|
||||
@@ -70,7 +62,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str): 事件响应器类型
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -90,7 +81,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_metaevent(rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-metaevent}
|
||||
@@ -98,7 +88,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个元事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -116,7 +105,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_message(rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-message}
|
||||
@@ -124,7 +112,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -142,7 +129,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_notice(rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-notice}
|
||||
@@ -150,7 +136,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个通知事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -168,7 +153,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_request(rule=..., permission=..., *, handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-request}
|
||||
@@ -176,7 +160,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个请求事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -194,7 +177,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_startswith(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-startswith}
|
||||
@@ -202,7 +184,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -224,7 +205,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_endswith(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-endswith}
|
||||
@@ -232,7 +212,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息结尾内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -254,7 +233,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_fullmatch(msg, rule=..., ignorecase=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-fullmatch}
|
||||
@@ -262,7 +240,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -284,7 +261,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_keyword(keywords, rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-keyword}
|
||||
@@ -292,7 +268,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `keywords` (set[str]): 关键词列表
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -312,7 +287,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_command(cmd, rule=..., aliases=..., force_whitespace=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-command}
|
||||
@@ -324,7 +298,6 @@ description: nonebot.plugin.on 模块
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -348,7 +321,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_shell_command(cmd, rule=..., aliases=..., parser=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-shell-command}
|
||||
@@ -363,7 +335,6 @@ description: nonebot.plugin.on 模块
|
||||
通过 [ShellCommandArgs](../params.md#ShellCommandArgs) 获取解析后的参数字典。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -387,7 +358,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_regex(pattern, flags=..., rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-regex}
|
||||
@@ -399,7 +369,6 @@ description: nonebot.plugin.on 模块
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `pattern` (str): 正则表达式
|
||||
|
||||
- `flags` (int | re.RegexFlag): 正则匹配标志
|
||||
@@ -421,7 +390,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _def_ `on_type(types, rule=..., *, permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#on-type}
|
||||
@@ -429,7 +397,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个事件响应器,并且当事件为指定类型时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `types` (type[[Event](../adapters/index.md#Event)] | tuple[type[[Event](../adapters/index.md#Event)], ...]): 事件类型
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -449,13 +416,11 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _class_ `CommandGroup(cmd, prefix_aliases=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#CommandGroup}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...])
|
||||
|
||||
- `prefix_aliases` (bool)
|
||||
@@ -481,7 +446,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个新的命令。新参数将会覆盖命令组默认值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -505,7 +469,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `shell_command(cmd, *, rule=..., aliases=..., parser=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#CommandGroup-shell-command}
|
||||
@@ -513,7 +476,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个新的 `shell_like` 命令。新参数将会覆盖命令组默认值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -537,13 +499,11 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
## _class_ `MatcherGroup(*, type=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str)
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None)
|
||||
@@ -567,7 +527,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个基础事件响应器,可自定义类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type` (str): 事件响应器类型
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -587,7 +546,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_metaevent(*, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-metaevent}
|
||||
@@ -595,7 +553,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个元事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -613,7 +570,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_message(*, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-message}
|
||||
@@ -621,7 +577,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -639,7 +594,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_notice(*, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-notice}
|
||||
@@ -647,7 +601,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个通知事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -665,7 +618,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_request(*, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-request}
|
||||
@@ -673,7 +625,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个请求事件响应器。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
|
||||
- `permission` ([Permission](../permission.md#Permission) | [T_PermissionChecker](../typing.md#T-PermissionChecker) | None): 事件响应权限
|
||||
@@ -691,7 +642,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_startswith(msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-startswith}
|
||||
@@ -699,7 +649,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容开头时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -721,7 +670,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_endswith(msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-endswith}
|
||||
@@ -729,7 +677,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**以指定内容结尾时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息结尾内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -751,7 +698,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_fullmatch(msg, *, ignorecase=..., rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-fullmatch}
|
||||
@@ -759,7 +705,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息的**文本部分**与指定内容完全一致时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配内容
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -781,7 +726,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_keyword(keywords, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-keyword}
|
||||
@@ -789,7 +733,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个消息事件响应器,并且当消息纯文本部分包含关键词时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `keywords` (set[str]): 关键词列表
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -809,7 +752,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_command(cmd, aliases=..., force_whitespace=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-command}
|
||||
@@ -821,7 +763,6 @@ description: nonebot.plugin.on 模块
|
||||
命令匹配规则参考: `命令形式匹配 <rule.md#command-command>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
@@ -845,7 +786,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_shell_command(cmd, aliases=..., parser=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-shell-command}
|
||||
@@ -860,7 +800,6 @@ description: nonebot.plugin.on 模块
|
||||
通过 [ShellCommandArgs](../params.md#ShellCommandArgs) 获取解析后的参数字典。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmd` (str | tuple[str, ...]): 指定命令内容
|
||||
|
||||
- `aliases` (set[str | tuple[str, ...]] | None): 命令别名
|
||||
@@ -884,7 +823,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_regex(pattern, flags=..., *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-regex}
|
||||
@@ -896,7 +834,6 @@ description: nonebot.plugin.on 模块
|
||||
命令匹配规则参考: `正则匹配 <rule.md#regex-regex-flags-0>`\_
|
||||
|
||||
- **参数**
|
||||
|
||||
- `pattern` (str): 正则表达式
|
||||
|
||||
- `flags` (int | re.RegexFlag): 正则匹配标志
|
||||
@@ -918,7 +855,6 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
### _method_ `on_type(types, *, rule=..., permission=..., handlers=..., temp=..., expire_time=..., priority=..., block=..., state=...)` {#MatcherGroup-on-type}
|
||||
@@ -926,7 +862,6 @@ description: nonebot.plugin.on 模块
|
||||
- **说明:** 注册一个事件响应器,并且当事件为指定类型时响应。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `types` (type[[Event](../adapters/index.md#Event)] | tuple[type[[Event](../adapters/index.md#Event)]]): 事件类型
|
||||
|
||||
- `rule` ([Rule](../rule.md#Rule) | [T_RuleChecker](../typing.md#T-RuleChecker) | None): 事件响应规则
|
||||
@@ -946,5 +881,4 @@ description: nonebot.plugin.on 模块
|
||||
- `state` ([T_State](../typing.md#T-State) | None): 默认 state
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[[Matcher](../matcher.md#Matcher)]
|
||||
|
||||
@@ -22,7 +22,6 @@ description: nonebot.rule 模块
|
||||
当事件传递时,在 [Matcher](matcher.md#Matcher) 运行前进行检查。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*checkers` ([T_RuleChecker](typing.md#T-RuleChecker) | [Dependent](dependencies/index.md#Dependent)[bool]): RuleChecker
|
||||
|
||||
- **用法**
|
||||
@@ -44,7 +43,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查是否符合所有规则
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](adapters/index.md#Bot)): Bot 对象
|
||||
|
||||
- `event` ([Event](adapters/index.md#Event)): Event 对象
|
||||
@@ -56,7 +54,6 @@ description: nonebot.rule 模块
|
||||
- `dependency_cache` ([T_DependencyCache](typing.md#T-DependencyCache) | None): 依赖缓存
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `CMD_RESULT(<auto>)` {#CMD-RESULT}
|
||||
@@ -78,7 +75,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息纯文本是否以指定字符串开头。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -88,13 +84,11 @@ description: nonebot.rule 模块
|
||||
- **说明:** 匹配消息纯文本开头。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
## _class_ `EndswithRule(msg, ignorecase=False)` {#EndswithRule}
|
||||
@@ -102,7 +96,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息纯文本是否以指定字符串结尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息结尾字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -112,13 +105,11 @@ description: nonebot.rule 模块
|
||||
- **说明:** 匹配消息纯文本结尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息开头字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
## _class_ `FullmatchRule(msg, ignorecase=False)` {#FullmatchRule}
|
||||
@@ -126,7 +117,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息纯文本是否与指定字符串全匹配。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (tuple[str, ...]): 指定消息全匹配字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
@@ -136,13 +126,11 @@ description: nonebot.rule 模块
|
||||
- **说明:** 完全匹配消息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str | tuple[str, ...]): 指定消息全匹配字符串元组
|
||||
|
||||
- `ignorecase` (bool): 是否忽略大小写
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
## _class_ `KeywordsRule(*keywords)` {#KeywordsRule}
|
||||
@@ -150,7 +138,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息纯文本是否包含指定关键字。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*keywords` (str): 指定关键字元组
|
||||
|
||||
## _def_ `keyword(*keywords)` {#keyword}
|
||||
@@ -158,11 +145,9 @@ description: nonebot.rule 模块
|
||||
- **说明:** 匹配消息纯文本关键词。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*keywords` (str): 指定关键字元组
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
## _class_ `CommandRule(cmds, force_whitespace=None)` {#CommandRule}
|
||||
@@ -170,7 +155,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息是否为指定命令。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmds` (list[tuple[str, ...]]): 指定命令元组列表
|
||||
|
||||
- `force_whitespace` (str | bool | None): 是否强制命令后必须有指定空白符
|
||||
@@ -189,13 +173,11 @@ description: nonebot.rule 模块
|
||||
通过 [CommandArg](params.md#CommandArg) 获取匹配成功的命令参数。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*cmds` (str | tuple[str, ...]): 命令文本或命令元组
|
||||
|
||||
- `force_whitespace` (str | bool | None): 是否强制命令后必须有指定空白符
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
- **用法**
|
||||
@@ -231,37 +213,28 @@ description: nonebot.rule 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(args=None, namespace=None) -> tuple[Namespace, list[str | MessageSegment]]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (Sequence[str | [MessageSegment](adapters/index.md#MessageSegment)] | None)
|
||||
|
||||
- `namespace` (None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Namespace, list[str | [MessageSegment](adapters/index.md#MessageSegment)]]
|
||||
|
||||
**2.** `(args, namespace) -> tuple[T, list[str | MessageSegment]]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (Sequence[str | [MessageSegment](adapters/index.md#MessageSegment)] | None)
|
||||
|
||||
- `namespace` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[T, list[str | [MessageSegment](adapters/index.md#MessageSegment)]]
|
||||
|
||||
**3.** `(*, namespace) -> tuple[T, list[str | MessageSegment]]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `namespace` (T)
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[T, list[str | [MessageSegment](adapters/index.md#MessageSegment)]]
|
||||
|
||||
## _class_ `ShellCommandRule(cmds, parser)` {#ShellCommandRule}
|
||||
@@ -269,7 +242,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息是否为指定 shell 命令。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cmds` (list[tuple[str, ...]]): 指定命令元组列表
|
||||
|
||||
- `parser` (ArgumentParser | None): 可选参数解析器
|
||||
@@ -298,13 +270,11 @@ description: nonebot.rule 模块
|
||||
:::
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*cmds` (str | tuple[str, ...]): 命令文本或命令元组
|
||||
|
||||
- `parser` (ArgumentParser | None): [ArgumentParser](#ArgumentParser) 对象
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
- **用法**
|
||||
@@ -330,7 +300,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查消息字符串是否符合指定正则表达式。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `regex` (str): 正则表达式
|
||||
|
||||
- `flags` (int): 正则表达式标记
|
||||
@@ -346,13 +315,11 @@ description: nonebot.rule 模块
|
||||
通过 [RegexDict](params.md#RegexDict) 获取匹配成功的 group 字典。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `regex` (str): 正则表达式
|
||||
|
||||
- `flags` (int | re.RegexFlag): 正则表达式标记
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
:::tip 提示
|
||||
@@ -380,7 +347,6 @@ description: nonebot.rule 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
## _class_ `IsTypeRule(*types)` {#IsTypeRule}
|
||||
@@ -388,7 +354,6 @@ description: nonebot.rule 模块
|
||||
- **说明:** 检查事件类型是否为指定类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (type[[Event](adapters/index.md#Event)])
|
||||
|
||||
## _def_ `is_type(*types)` {#is-type}
|
||||
@@ -396,9 +361,7 @@ description: nonebot.rule 模块
|
||||
- **说明:** 匹配事件类型。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (type[[Event](adapters/index.md#Event)]): 事件类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Rule](#Rule)
|
||||
|
||||
@@ -19,31 +19,25 @@ description: nonebot.typing 模块
|
||||
- **说明:** 标记一个方法为父类 interface 的 implement
|
||||
|
||||
- **参数**
|
||||
|
||||
- `InterfaceClass` (object)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _def_ `type_has_args(type_)` {#type-has-args}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `origin_is_union(origin)` {#origin-is-union}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `origin` (type[Any] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `origin_is_literal(origin)` {#origin-is-literal}
|
||||
@@ -51,11 +45,9 @@ description: nonebot.typing 模块
|
||||
- **说明:** 判断是否是 Literal 类型
|
||||
|
||||
- **参数**
|
||||
|
||||
- `origin` (type[Any] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `all_literal_values(type_)` {#all-literal-values}
|
||||
@@ -63,11 +55,9 @@ description: nonebot.typing 模块
|
||||
- **说明:** 获取 Literal 类型包含的所有值
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[Any]
|
||||
|
||||
## _def_ `origin_is_annotated(origin)` {#origin-is-annotated}
|
||||
@@ -75,11 +65,9 @@ description: nonebot.typing 模块
|
||||
- **说明:** 判断是否是 Annotated 类型
|
||||
|
||||
- **参数**
|
||||
|
||||
- `origin` (type[Any] | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_none_type(type_)` {#is-none-type}
|
||||
@@ -87,17 +75,14 @@ description: nonebot.typing 模块
|
||||
- **说明:** 判断是否是 None 类型
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `evaluate_forwardref(ref, globalns, localns)` {#evaluate-forwardref}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `ref` (ForwardRef)
|
||||
|
||||
- `globalns` (dict[str, Any])
|
||||
@@ -105,7 +90,6 @@ description: nonebot.typing 模块
|
||||
- `localns` (dict[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _class_ `StateFlag(<auto>)` {#StateFlag}
|
||||
@@ -129,7 +113,6 @@ description: nonebot.typing 模块
|
||||
Bot 连接建立时钩子函数
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
@@ -143,7 +126,6 @@ description: nonebot.typing 模块
|
||||
Bot 连接断开时钩子函数
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- DefaultParam: 带有默认值的参数
|
||||
@@ -169,7 +151,6 @@ description: nonebot.typing 模块
|
||||
事件预处理函数 EventPreProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -185,7 +166,6 @@ description: nonebot.typing 模块
|
||||
事件后处理函数 EventPostProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -201,7 +181,6 @@ description: nonebot.typing 模块
|
||||
事件响应器运行前预处理函数 RunPreProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -218,7 +197,6 @@ description: nonebot.typing 模块
|
||||
事件响应器运行后后处理函数 RunPostProcessor 类型
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -236,7 +214,6 @@ description: nonebot.typing 模块
|
||||
RuleChecker 即判断是否响应事件的处理函数。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -252,7 +229,6 @@ description: nonebot.typing 模块
|
||||
PermissionChecker 即判断事件是否满足权限的处理函数。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -273,7 +249,6 @@ description: nonebot.typing 模块
|
||||
TypeUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新响应的事件类型。 默认会更新为 `message`。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
@@ -290,7 +265,6 @@ description: nonebot.typing 模块
|
||||
PermissionUpdater 在 Matcher.pause, Matcher.reject 时被运行,用于更新会话对象权限。 默认会更新为当前事件的触发对象。
|
||||
|
||||
依赖参数:
|
||||
|
||||
- DependParam: 子依赖参数
|
||||
- BotParam: Bot 对象
|
||||
- EventParam: Event 对象
|
||||
|
||||
@@ -18,11 +18,9 @@ description: nonebot.utils 模块
|
||||
参考: [loguru color 标签](https://loguru.readthedocs.io/en/stable/api/logger.html#color)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `s` (str): 需要转义的字符串
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `deep_update(mapping, *updating_mappings)` {#deep-update}
|
||||
@@ -30,13 +28,11 @@ description: nonebot.utils 模块
|
||||
- **说明:** 深度更新合并字典
|
||||
|
||||
- **参数**
|
||||
|
||||
- `mapping` (dict[K, Any])
|
||||
|
||||
- `*updating_mappings` (dict[K, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[K, Any]
|
||||
|
||||
## _def_ `lenient_issubclass(cls, class_or_tuple)` {#lenient-issubclass}
|
||||
@@ -44,13 +40,11 @@ description: nonebot.utils 模块
|
||||
- **说明:** 检查 cls 是否是 class_or_tuple 中的一个类型子类并忽略类型错误。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cls` (Any)
|
||||
|
||||
- `class_or_tuple` (type[Any] | tuple[type[Any], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `generic_check_issubclass(cls, class_or_tuple)` {#generic-check-issubclass}
|
||||
@@ -60,7 +54,6 @@ description: nonebot.utils 模块
|
||||
检查 cls 是否是 class_or_tuple 中的一个类型子类。
|
||||
|
||||
特别的:
|
||||
|
||||
- 如果 cls 是 `typing.Union` 或 `types.UnionType` 类型,
|
||||
则会检查其中的所有类型是否是 class_or_tuple 中一个类型的子类或 None。
|
||||
- 如果 cls 是 `typing.Literal` 类型,
|
||||
@@ -70,13 +63,11 @@ description: nonebot.utils 模块
|
||||
是否是 class_or_tuple 中一个类型的子类或 None。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cls` (Any)
|
||||
|
||||
- `class_or_tuple` (type[Any] | tuple[type[Any], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `type_is_complex(type_)` {#type-is-complex}
|
||||
@@ -84,11 +75,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 检查 type\_ 是否是复杂类型
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_coroutine_callable(call)` {#is-coroutine-callable}
|
||||
@@ -96,11 +85,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 检查 call 是否是一个 callable 协程函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((...) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_gen_callable(call)` {#is-gen-callable}
|
||||
@@ -108,11 +95,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 检查 call 是否是一个生成器函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((...) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `is_async_gen_callable(call)` {#is-async-gen-callable}
|
||||
@@ -120,11 +105,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 检查 call 是否是一个异步生成器函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((...) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _def_ `run_sync(call)` {#run-sync}
|
||||
@@ -132,11 +115,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 一个用于包装 sync function 为 async function 的装饰器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((P) -> R): 被装饰的同步函数
|
||||
|
||||
- **返回**
|
||||
|
||||
- (P) -> Coroutine[None, None, R]
|
||||
|
||||
## _def_ `run_sync_ctx_manager(cm)` {#run-sync-ctx-manager}
|
||||
@@ -144,11 +125,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 一个用于包装 sync context manager 为 async context manager 的执行函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cm` (AbstractContextManager[T])
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[T, None]
|
||||
|
||||
## _async def_ `run_coro_with_catch(coro, exc, return_on_err=None)` {#run-coro-with-catch}
|
||||
@@ -158,9 +137,7 @@ description: nonebot.utils 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(coro, exc, return_on_err=None) -> T | None`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro` (Coroutine[Any, Any, T])
|
||||
|
||||
- `exc` (tuple[type[Exception], ...])
|
||||
@@ -168,13 +145,10 @@ description: nonebot.utils 模块
|
||||
- `return_on_err` (None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T | None
|
||||
|
||||
**2.** `(coro, exc, return_on_err) -> T | R`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro` (Coroutine[Any, Any, T])
|
||||
|
||||
- `exc` (tuple[type[Exception], ...])
|
||||
@@ -182,11 +156,9 @@ description: nonebot.utils 模块
|
||||
- `return_on_err` (R)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T | R
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro`: 要运行的协程
|
||||
|
||||
- `exc`: 要捕获的异常
|
||||
@@ -202,21 +174,17 @@ description: nonebot.utils 模块
|
||||
- **说明:** 运行协程并在取消时屏蔽取消异常。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `coro` (Coroutine[Any, Any, T]): 要运行的协程
|
||||
|
||||
- **返回**
|
||||
|
||||
- T: 协程的返回值
|
||||
|
||||
## _def_ `flatten_exception_group(exc_group)` {#flatten-exception-group}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `exc_group` (BaseExceptionGroup[E])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Generator[E, None, None]
|
||||
|
||||
## _def_ `get_name(obj)` {#get-name}
|
||||
@@ -224,11 +192,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 获取对象的名称
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `path_to_module_name(path)` {#path-to-module-name}
|
||||
@@ -236,11 +202,9 @@ description: nonebot.utils 模块
|
||||
- **说明:** 转换路径为模块名
|
||||
|
||||
- **参数**
|
||||
|
||||
- `path` (Path)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _def_ `resolve_dot_notation(obj_str, default_attr, default_prefix=None)` {#resolve-dot-notation}
|
||||
@@ -248,7 +212,6 @@ description: nonebot.utils 模块
|
||||
- **说明:** 解析并导入点分表示法的对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj_str` (str)
|
||||
|
||||
- `default_attr` (str)
|
||||
@@ -256,7 +219,6 @@ description: nonebot.utils 模块
|
||||
- `default_prefix` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _class_ `classproperty(func)` {#classproperty}
|
||||
@@ -264,7 +226,6 @@ description: nonebot.utils 模块
|
||||
- **说明:** 类属性装饰器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((Any) -> T)
|
||||
|
||||
## _class_ `DataclassEncoder(<auto>)` {#DataclassEncoder}
|
||||
@@ -278,11 +239,9 @@ description: nonebot.utils 模块
|
||||
### _method_ `default(o)` {#DataclassEncoder-default}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `o`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _def_ `logger_wrapper(logger_name)` {#logger-wrapper}
|
||||
@@ -290,15 +249,12 @@ description: nonebot.utils 模块
|
||||
- **说明:** 用于打印 adapter 的日志。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `logger_name` (str): adapter 的名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped: 日志记录函数
|
||||
|
||||
日志记录函数的参数:
|
||||
|
||||
- level: 日志等级
|
||||
- message: 日志信息
|
||||
- exception: 异常信息
|
||||
|
||||
@@ -278,7 +278,6 @@ opt2 = Option("--foo", default=OptionResult(value=False, args={"bar": 1}))
|
||||
`Arparma` 有如下属性:
|
||||
|
||||
- 调试类
|
||||
|
||||
- matched: 是否匹配成功
|
||||
- error_data: 解析失败时剩余的数据
|
||||
- error_info: 解析失败时的异常内容
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
---
|
||||
sidebar_position: 8
|
||||
description: 轻量化 HTML 绘图
|
||||
---
|
||||
|
||||
# 轻量化 HTML 绘图
|
||||
|
||||
图片是机器人交互中不可或缺的一部分,对于信息展示的直观性、美观性有很大的作用。
|
||||
基于 PIL 直接绘制图片具有良好的性能和存储开销,但是难以调试、维护过程式的绘图代码。
|
||||
使用浏览器渲染类插件可以方便地绘制网页,且能够直接通过 JS 对网页效果进行编程,但是它占用的存储和内存空间相对可观。
|
||||
|
||||
NoneBot 提供的 `nonebot-plugin-htmlkit` 提供了另一种基于 HTML 和 CSS 语法的轻量化绘图选择:它基于 `litehtml` 解析库,无须安装额外的依赖即可使用,没有进程间通信带来的额外开销,且在支持 `webp` `avif` 等丰富图片格式的前提下,安装用的 wheel 文件大小仅有约 10 MB。
|
||||
|
||||
作为粗略的性能参考,在一台 Ryzen 7 9700X 的 Windows 电脑上,渲染 [PEP 7](https://peps.python.org/pep-0007/) 的 HTML 页面(分辨率为 800x5788,大小约 1.4MB,从本地文件系统读取 CSS)大约需要 100ms,每个渲染任务内存最高占用约为 40MB.
|
||||
|
||||
## 安装插件
|
||||
|
||||
在使用前请先安装 `nonebot-plugin-htmlkit` 插件至项目环境中,可参考[获取商店插件](../tutorial/store.mdx#安装插件)来了解并选择安装插件的方式。如:
|
||||
|
||||
在**项目目录**下执行以下命令:
|
||||
|
||||
```bash
|
||||
nb plugin install nonebot-plugin-htmlkit
|
||||
```
|
||||
|
||||
`nonebot-plugin-htmlkit` 插件目前兼容以下系统架构:
|
||||
|
||||
- Windows x64
|
||||
- macOS arm64(M-系列芯片)
|
||||
- Linux x64 (非 Alpine 等 musl 系发行版)
|
||||
- Linux arm64 (非 Alpine 等 musl 系发行版)
|
||||
|
||||
:::caution 访问网络内容
|
||||
|
||||
如果需要访问网络资源(如 http(s) 网页内容),NoneBot 需要客户端型驱动器(Forward)。内置的驱动器有 `~httpx` 与 `~aiohttp`。
|
||||
|
||||
详见[选择驱动器](../advanced/driver.md)。
|
||||
|
||||
:::
|
||||
|
||||
## 使用插件
|
||||
|
||||
### 加载插件
|
||||
|
||||
在使用本插件前同样需要使用 `require` 方法进行**加载**并**导入**需要使用的方法,可参考 [跨插件访问](../advanced/requiring.md) 一节进行了解,如:
|
||||
|
||||
```python
|
||||
from nonebot import require
|
||||
|
||||
require("nonebot_plugin_htmlkit")
|
||||
|
||||
from nonebot_plugin_htmlkit import html_to_pic, md_to_pic, template_to_pic, text_to_pic
|
||||
```
|
||||
|
||||
插件会自动使用[配置中的参数](#配置-fontconfig)初始化 `fontconfig` 以提供字体查找功能。
|
||||
|
||||
### 渲染 API
|
||||
|
||||
`nonebot-plugin-htmlkit` 主要提供以下**异步**渲染函数:
|
||||
|
||||
#### html_to_pic
|
||||
|
||||
```python
|
||||
async def html_to_pic(
|
||||
html: str,
|
||||
*,
|
||||
base_url: str = "",
|
||||
dpi: float = 144.0,
|
||||
max_width: float = 800.0,
|
||||
device_height: float = 600.0,
|
||||
default_font_size: float = 12.0,
|
||||
font_name: str = "sans-serif",
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
lang: str = "zh",
|
||||
culture: str = "CN",
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
css_fetch_fn: CSSFetchFn = combined_css_fetcher,
|
||||
urljoin_fn: Callable[[str, str], str] = urllib3.parse.urljoin,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
最核心的渲染函数。
|
||||
|
||||
`base_url` 和 `urljoin_fn` 控制着传入 `image_fetch_fn` 和 `css_fetch_fn` 回调的 url 内容。
|
||||
|
||||
`allow_refit` 如果为真,渲染时会自动缩小产出图片的宽度到最适合的宽度,否则必定产出 `max_width` 宽度的图片。
|
||||
|
||||
`max_width` 与 `device_height` 会在 `@media` 判断中被使用。
|
||||
|
||||
`img_fetch_fn` 预期为一个异步可调用对象(函数),接收图片 url 并返回对应 url 的 jpeg 或 png 二进制数据(`bytes`),可在拒绝加载时返回 `None`.
|
||||
|
||||
`css_fetch_fn` 预期为一个异步可调用对象(函数),接收目标 CSS url 并返回对应 url 的 CSS 文本(`str`),可在拒绝加载时返回 `None`.
|
||||
|
||||
以下为辅助的封装函数,关键字参数若未特殊说明均与 `html_to_pic` 含义相同。
|
||||
|
||||
#### text_to_pic
|
||||
|
||||
```python
|
||||
async def text_to_pic(
|
||||
text: str,
|
||||
css_path: str = "",
|
||||
*,
|
||||
max_width: int = 500,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
可用于渲染多行文本。
|
||||
|
||||
`text` 会被放置于 `<div id="main" class="main-box"> <div class="text">` 中,可据此编写 CSS 来改变文本表现。
|
||||
|
||||
#### md_to_pic
|
||||
|
||||
```python
|
||||
async def md_to_pic(
|
||||
md: str = "",
|
||||
md_path: str = "",
|
||||
css_path: str = "",
|
||||
*,
|
||||
max_width: int = 500,
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
可用于渲染 Markdown 文本。默认为 GitHub Markdown Light 风格,支持基于 `pygments` 的代码高亮。
|
||||
|
||||
`md` 和 `md_path` 二选一,前者设置时应为 Markdown 的文本,后者设置时应为指向 Markdown 文本文件的路径。
|
||||
|
||||
#### template_to_pic
|
||||
|
||||
```python
|
||||
async def template_to_pic(
|
||||
template_path: str | PathLike[str] | Sequence[str | PathLike[str]],
|
||||
template_name: str,
|
||||
templates: Mapping[Any, Any],
|
||||
filters: None | Mapping[str, Any] = None,
|
||||
*,
|
||||
max_width: int = 500,
|
||||
device_height: int = 600,
|
||||
base_url: str | None = None,
|
||||
img_fetch_fn: ImgFetchFn = combined_img_fetcher,
|
||||
css_fetch_fn: CSSFetchFn = combined_css_fetcher,
|
||||
allow_refit: bool = True,
|
||||
image_format: Literal["png", "jpeg"] = "png",
|
||||
jpeg_quality: int = 100,
|
||||
) -> bytes:
|
||||
...
|
||||
```
|
||||
|
||||
渲染 jinja2 模板。
|
||||
|
||||
`template_path` 为 jinja2 环境的路径,`template_name` 是环境中要加载模板的名字,`templates` 为传入模板的参数,`filters` 为过滤器名 -> 自定义过滤器的映射。
|
||||
|
||||
### 控制外部资源获取
|
||||
|
||||
通过传入 `img_fetch_fn` 与 `css_fetch_fn`,我们可以在实际访问资源前进行审查,修改资源的来源,或是对 IO 操作进行缓存。
|
||||
|
||||
`img_fetch_fn` 预期为一个异步可调用对象(函数),接收图片 url 并返回对应 url 的 jpeg 或 png 二进制数据(`bytes`),可在拒绝加载时返回 `None`.
|
||||
|
||||
`css_fetch_fn` 预期为一个异步可调用对象(函数),接收目标 CSS url 并返回对应 url 的 CSS 文本(`str`),可在拒绝加载时返回 `None`.
|
||||
|
||||
如果你想要禁用外部资源加载/只从文件系统加载/只从网络加载,可以使用 `none_fetcher` `filesystem_***_fetcher` `network_***_fetcher`。
|
||||
|
||||
默认的 fetcher 行为(对于 `file://` 从文件系统加载,其余从网络加载)位于 `combined_***_fetcher`,可以通过对其封装实现缓存等操作。
|
||||
|
||||
## 配置项
|
||||
|
||||
### 配置 fontconfig
|
||||
|
||||
`htmlkit` 使用 `fontconfig` 查找字体,请参阅 [`fontconfig 用户手册`](https://fontconfig.pages.freedesktop.org/fontconfig/fontconfig-user) 了解环境变量的具体含义、如何通过编写配置文件修改字体配置等。
|
||||
|
||||
#### fontconfig_file
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的配置文件路径。
|
||||
|
||||
#### fontconfig_path
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的配置目录。
|
||||
|
||||
#### fontconfig_sysroot
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
覆盖默认的 sysroot。
|
||||
|
||||
#### fc_debug
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
设置 Fontconfig 的 debug 级别。
|
||||
|
||||
#### fc_dbg_match_filter
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
当 `FC_DEBUG` 设置为 `MATCH2` 时,过滤 debug 输出。
|
||||
|
||||
#### fc_lang
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
设置默认语言,否则从 `LOCALE` 环境变量获取。
|
||||
|
||||
#### fontconfig_use_mmap
|
||||
|
||||
- **类型**: `str | None`
|
||||
- **默认值**: `None`
|
||||
|
||||
是否使用 `mmap(2)` 读取字体缓存。
|
||||
@@ -40,7 +40,7 @@ async def handle_function():
|
||||
|
||||
### 处理近似事件
|
||||
|
||||
对于一系列**差异不大**的事件,我们往往具有相同的处理逻辑。这时,我们不希望将相同的逻辑编写两遍,而应该复用代码,以实现在同一个事件处理函数中处理多个近似事件。我们可以使用[事件重载](../advanced/dependency.mdx#Event)的特性来实现这一功能。例如:
|
||||
对于一系列**差异不大**的事件,我们往往具有相同的处理逻辑。这时,我们不希望将相同的逻辑编写两遍,而应该复用代码,以实现在同一个事件处理函数中处理多个近似事件。我们可以使用[事件重载](../advanced/dependency.mdx#event)的特性来实现这一功能。例如:
|
||||
|
||||
<Tabs groupId="python">
|
||||
<TabItem value="3.10" label="Python 3.10+" default>
|
||||
|
||||
@@ -155,7 +155,6 @@ async def test_example(app: App):
|
||||
1. `should_call_send`
|
||||
|
||||
定义事件响应器预期发送的消息,即通过[事件响应器操作 send](../../appendices/session-control.mdx#send)进行的操作。`should_call_send` 有四个参数:
|
||||
|
||||
- `event`:回复的目标事件。
|
||||
- `message`:预期的消息对象,可以是 `str`、`Message` 或 `MessageSegment`。
|
||||
- `result`:send 的返回值,将会返回给插件。
|
||||
@@ -163,8 +162,7 @@ async def test_example(app: App):
|
||||
- `**kwargs`:send 方法的额外参数。
|
||||
|
||||
2. `should_call_api`
|
||||
定义事件响应器预期调用的平台 API 接口,即通过[调用平台 API](../../appendices/api-calling.mdx#调用平台-API)进行的操作。`should_call_api` 有四个参数:
|
||||
|
||||
定义事件响应器预期调用的平台 API 接口,即通过[调用平台 API](../../appendices/api-calling.mdx#调用平台-api)进行的操作。`should_call_api` 有四个参数:
|
||||
- `api`:API 名称。
|
||||
- `data`:预期的请求数据。
|
||||
- `result`:call_api 的返回值,将会返回给插件。
|
||||
|
||||
@@ -260,7 +260,7 @@ class Adapter(BaseAdapter):
|
||||
更多通信交互方式可以参考以下适配器:
|
||||
|
||||
- [OneBot](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/adapter.py) - `WebSocket 客户端`、`WebSocket 服务端`、`HTTP WEBHOOK`、`HTTP POST`
|
||||
- [QQGuild](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/adapter.py) - `WebSocket 服务端`
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/master/nonebot/adapters/qq/adapter.py) - `WebSocket 服务端`、`HTTP WEBHOOK`
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/adapter.py) - `HTTP WEBHOOK`
|
||||
|
||||
#### 建立 Bot 连接
|
||||
@@ -375,14 +375,16 @@ class Adapter(BaseAdapter):
|
||||
|
||||
Websocket:
|
||||
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/adapter.py#L127)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v12/adapter.py#L162)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/adapter.py#L167-L177)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v12/adapter.py#L204-L218)
|
||||
|
||||
HTTP:
|
||||
|
||||
- [QQ 频道](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/adapter.py#L354)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/adapter.py#L145)
|
||||
- [飞书](https://github.com/nonebot/adapter-feishu/blob/master/nonebot/adapters/feishu/adapter.py#L158)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/adapter.py#L179-L215)
|
||||
- [OneBot V12](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v12/adapter.py#L220-L266)
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/dc5d437e101f0e3db542de3300758a035ed7036e/nonebot/adapters/qq/adapter.py#L599-L605)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/4a8633627e619245516767f5503dec2f58fe2193/nonebot/adapters/telegram/adapter.py#L148-L253)
|
||||
- [飞书](https://github.com/nonebot/adapter-feishu/blob/f8ab05e6d57a5e9013b944b0d019ca777725dfb0/nonebot/adapters/feishu/adapter.py#L201-L218)
|
||||
|
||||
### Bot
|
||||
|
||||
@@ -576,9 +578,9 @@ class Message(BaseMessage[MessageSegment]):
|
||||
|
||||
然后根据平台具体的消息类型,来实现各种 `MessageSegment` 消息段,具体可以参考以下适配器:
|
||||
|
||||
- [OneBot](https://github.com/nonebot/adapter-onebot/blob/master/nonebot/adapters/onebot/v11/message.py#L77-L261)
|
||||
- [QQGuild](https://github.com/nonebot/adapter-qqguild/blob/master/nonebot/adapters/qqguild/message.py#L22-L150)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/beta/nonebot/adapters/telegram/message.py#L43-L250)
|
||||
- [OneBot V11](https://github.com/nonebot/adapter-onebot/blob/54270edbbdb2a71332d744f90b1a3d7f4bf6463a/nonebot/adapters/onebot/v11/message.py#L25-L259)
|
||||
- [QQ](https://github.com/nonebot/adapter-qq/blob/dc5d437e101f0e3db542de3300758a035ed7036e/nonebot/adapters/qq/message.py#L30-L520)
|
||||
- [Telegram](https://github.com/nonebot/adapter-telegram/blob/4a8633627e619245516767f5503dec2f58fe2193/nonebot/adapters/telegram/message.py#L13-L414)
|
||||
|
||||
## 适配器测试
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ description: nonebot.adapters 模块
|
||||
通常,在 Adapter 中编写协议通信相关代码,如: 建立通信连接、处理接收与发送 data 等。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` ([Driver](../drivers/index.md#Driver)): [Driver](../drivers/index.md#Driver) 实例
|
||||
|
||||
- `**kwargs` (Any): 其他由 [Driver.register_adapter](../drivers/index.md#Driver-register-adapter) 传入的额外参数
|
||||
@@ -46,7 +45,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _property_ `config` {#Adapter-config}
|
||||
@@ -64,11 +62,9 @@ description: nonebot.adapters 模块
|
||||
当有新的 [Bot](#Bot) 实例连接建立成功时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](#Bot)): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `bot_disconnect(bot)` {#Adapter-bot-disconnect}
|
||||
@@ -80,11 +76,9 @@ description: nonebot.adapters 模块
|
||||
当有 [Bot](#Bot) 实例连接断开时调用。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `bot` ([Bot](#Bot)): [Bot](#Bot) 实例
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `setup_http_server(setup)` {#Adapter-setup-http-server}
|
||||
@@ -92,11 +86,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](../drivers/index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Adapter-setup-websocket-server}
|
||||
@@ -104,11 +96,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](../drivers/index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `request(setup)` {#Adapter-request}
|
||||
@@ -116,11 +106,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 进行一个 HTTP 客户端请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](../drivers/index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](../drivers/index.md#Response)
|
||||
|
||||
### _method_ `websocket(setup)` {#Adapter-websocket}
|
||||
@@ -128,21 +116,17 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 建立一个 WebSocket 客户端连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](../drivers/index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](../drivers/index.md#WebSocket), None]
|
||||
|
||||
### _method_ `on_ready(func)` {#Adapter-on-ready}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
## _abstract class_ `Bot(adapter, self_id)` {#Bot}
|
||||
@@ -154,7 +138,6 @@ description: nonebot.adapters 模块
|
||||
用于处理上报消息,并提供 API 调用接口。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` ([Adapter](#Adapter)): 协议适配器实例
|
||||
|
||||
- `self_id` (str): 机器人 ID
|
||||
@@ -188,13 +171,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 调用机器人 API 接口,可以通过该函数或直接通过 bot 属性进行调用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `api` (str): API 名称
|
||||
|
||||
- `**data` (Any): API 数据
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
- **用法**
|
||||
@@ -209,7 +190,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 调用机器人基础发送消息接口
|
||||
|
||||
- **参数**
|
||||
|
||||
- `event` ([Event](#Event)): 上报事件
|
||||
|
||||
- `message` (str | [Message](#Message) | [MessageSegment](#MessageSegment)): 要发送的消息
|
||||
@@ -217,7 +197,6 @@ description: nonebot.adapters 模块
|
||||
- `**kwargs` (Any): 任意额外参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _classmethod_ `on_calling_api(func)` {#Bot-on-calling-api}
|
||||
@@ -227,17 +206,14 @@ description: nonebot.adapters 模块
|
||||
调用 api 预处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- api: 调用的 api 名称
|
||||
- data: api 调用的参数字典
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_CallingAPIHook](../typing.md#T-CallingAPIHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_CallingAPIHook](../typing.md#T-CallingAPIHook)
|
||||
|
||||
### _classmethod_ `on_called_api(func)` {#Bot-on-called-api}
|
||||
@@ -247,7 +223,6 @@ description: nonebot.adapters 模块
|
||||
调用 api 后处理。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前 bot 对象
|
||||
- exception: 调用 api 时发生的错误
|
||||
- api: 调用的 api 名称
|
||||
@@ -255,11 +230,9 @@ description: nonebot.adapters 模块
|
||||
- result: api 调用的返回
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_CalledAPIHook](../typing.md#T-CalledAPIHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_CalledAPIHook](../typing.md#T-CalledAPIHook)
|
||||
|
||||
## _abstract class_ `Event(<auto>)` {#Event}
|
||||
@@ -279,7 +252,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_event_name()` {#Event-get-event-name}
|
||||
@@ -291,7 +263,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_event_description()` {#Event-get-event-description}
|
||||
@@ -303,7 +274,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `get_log_string()` {#Event-get-log-string}
|
||||
@@ -320,11 +290,9 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
- **异常**
|
||||
|
||||
- NoLogException: 希望 NoneBot 隐藏该事件日志
|
||||
|
||||
### _abstract method_ `get_user_id()` {#Event-get-user-id}
|
||||
@@ -336,7 +304,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_session_id()` {#Event-get-session-id}
|
||||
@@ -348,7 +315,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `get_message()` {#Event-get-message}
|
||||
@@ -360,7 +326,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Message](#Message)
|
||||
|
||||
### _method_ `get_plaintext()` {#Event-get-plaintext}
|
||||
@@ -376,7 +341,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract method_ `is_tome()` {#Event-is-tome}
|
||||
@@ -388,7 +352,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _abstract class_ `Message(<auto>)` {#Message}
|
||||
@@ -396,7 +359,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 消息序列
|
||||
|
||||
- **参数**
|
||||
|
||||
- `message`: 消息内容
|
||||
|
||||
### _classmethod_ `template(format_string)` {#Message-template}
|
||||
@@ -410,11 +372,9 @@ description: nonebot.adapters 模块
|
||||
可以通过该消息类型的 `MessageSegment` 工厂方法创建消息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str | TM): 格式化模板
|
||||
|
||||
- **返回**
|
||||
|
||||
- [MessageTemplate](#MessageTemplate)[Self]: 消息格式化器
|
||||
|
||||
### _abstract classmethod_ `get_segment_class()` {#Message-get-segment-class}
|
||||
@@ -426,7 +386,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[TMS]
|
||||
|
||||
### _abstract staticmethod_ `_construct(msg)` {#Message--construct}
|
||||
@@ -434,11 +393,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 构造消息数组
|
||||
|
||||
- **参数**
|
||||
|
||||
- `msg` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Iterable[TMS]
|
||||
|
||||
### _method_ `__getitem__(args)` {#Message---getitem--}
|
||||
@@ -446,53 +403,38 @@ description: nonebot.adapters 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (str): 消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 所有类型为 `args` 的消息段
|
||||
|
||||
**2.** `(args) -> TMS`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (tuple[str, int]): 消息段类型和索引
|
||||
|
||||
- **返回**
|
||||
|
||||
- TMS: 类型为 `args[0]` 的消息段第 `args[1]` 个
|
||||
|
||||
**3.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (tuple[str, slice]): 消息段类型和切片
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 类型为 `args[0]` 的消息段切片 `args[1]`
|
||||
|
||||
**4.** `(args) -> TMS`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (int): 索引
|
||||
|
||||
- **返回**
|
||||
|
||||
- TMS: 第 `args` 个消息段
|
||||
|
||||
**5.** `(args) -> Self`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `args` (slice): 切片
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 消息切片 `args`
|
||||
|
||||
### _method_ `__contains__(value)` {#Message---contains--}
|
||||
@@ -500,11 +442,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 检查消息段是否存在
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 消息内是否存在给定消息段或给定类型的消息段
|
||||
|
||||
### _method_ `has(value)` {#Message-has}
|
||||
@@ -512,11 +452,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 与 [`__contains__`](#Message---contains--) 相同
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
### _method_ `index(value, *args)` {#Message-index}
|
||||
@@ -524,7 +462,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 索引消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或者消息段类型
|
||||
|
||||
- `*args` (SupportsIndex)
|
||||
@@ -532,11 +469,9 @@ description: nonebot.adapters 模块
|
||||
- `arg`: start 与 end
|
||||
|
||||
- **返回**
|
||||
|
||||
- int: 索引 index
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 消息段不存在
|
||||
|
||||
### _method_ `get(type_, count=None)` {#Message-get}
|
||||
@@ -544,13 +479,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 获取指定类型的消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (str): 消息段类型
|
||||
|
||||
- `count` (int | None): 获取个数
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 构建的新消息
|
||||
|
||||
### _method_ `count(value)` {#Message-count}
|
||||
@@ -558,11 +491,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 计算指定消息段的个数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- int: 个数
|
||||
|
||||
### _method_ `only(value)` {#Message-only}
|
||||
@@ -570,11 +501,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 检查消息中是否仅包含指定消息段
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (TMS | str): 指定消息段或消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool: 是否仅包含指定消息段
|
||||
|
||||
### _method_ `append(obj)` {#Message-append}
|
||||
@@ -582,11 +511,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 添加一个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (str | TMS): 要添加的消息段
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `extend(obj)` {#Message-extend}
|
||||
@@ -594,11 +521,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 拼接一个消息数组或多个消息段到消息数组末尾。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `obj` (Self | Iterable[TMS]): 要添加的消息数组
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `join(iterable)` {#Message-join}
|
||||
@@ -606,11 +531,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 将多个消息连接并将自身作为分割
|
||||
|
||||
- **参数**
|
||||
|
||||
- `iterable` (Iterable[TMS | Self]): 要连接的消息
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 连接后的消息
|
||||
|
||||
### _method_ `copy()` {#Message-copy}
|
||||
@@ -622,7 +545,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `include(*types)` {#Message-include}
|
||||
@@ -630,11 +552,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 过滤消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (str): 包含的消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 新构造的消息
|
||||
|
||||
### _method_ `exclude(*types)` {#Message-exclude}
|
||||
@@ -642,11 +562,9 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 过滤消息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*types` (str): 不包含的消息段类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self: 新构造的消息
|
||||
|
||||
### _method_ `extract_plain_text()` {#Message-extract-plain-text}
|
||||
@@ -658,7 +576,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
## _abstract class_ `MessageSegment(<auto>)` {#MessageSegment}
|
||||
@@ -690,7 +607,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[TM]
|
||||
|
||||
### _abstract method_ `__str__()` {#MessageSegment---str--}
|
||||
@@ -702,29 +618,24 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _method_ `__add__(other)` {#MessageSegment---add--}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `other` (str | Self | Iterable[Self])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TM
|
||||
|
||||
### _method_ `get(key, default=None)` {#MessageSegment-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `key` (str)
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `keys()` {#MessageSegment-keys}
|
||||
@@ -734,7 +645,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `values()` {#MessageSegment-values}
|
||||
@@ -744,7 +654,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `items()` {#MessageSegment-items}
|
||||
@@ -754,17 +663,14 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `join(iterable)` {#MessageSegment-join}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `iterable` (Iterable[Self | TM])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TM
|
||||
|
||||
### _method_ `copy()` {#MessageSegment-copy}
|
||||
@@ -774,7 +680,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _abstract method_ `is_text()` {#MessageSegment-is-text}
|
||||
@@ -786,7 +691,6 @@ description: nonebot.adapters 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bool
|
||||
|
||||
## _class_ `MessageTemplate(template, factory=str, private_getattr=False)` {#MessageTemplate}
|
||||
@@ -794,7 +698,6 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 消息模板格式化实现类。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `template` (str | TM): 模板
|
||||
|
||||
- `factory` (type[str] | type[TM]): 消息类型工厂,默认为 `str`
|
||||
@@ -804,13 +707,11 @@ description: nonebot.adapters 模块
|
||||
### _method_ `add_format_spec(spec, name=None)` {#MessageTemplate-add-format-spec}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `spec` (FormatSpecFunc_T)
|
||||
|
||||
- `name` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- FormatSpecFunc_T
|
||||
|
||||
### _method_ `format(*args, **kwargs)` {#MessageTemplate-format}
|
||||
@@ -818,13 +719,11 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 根据传入参数和模板生成消息对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `format_map(mapping)` {#MessageTemplate-format-map}
|
||||
@@ -832,17 +731,14 @@ description: nonebot.adapters 模块
|
||||
- **说明:** 根据传入字典和模板生成消息对象, 在传入字段名不是有效标识符时有用
|
||||
|
||||
- **参数**
|
||||
|
||||
- `mapping` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `vformat(format_string, args, kwargs)` {#MessageTemplate-vformat}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `format_string` (str)
|
||||
|
||||
- `args` (Sequence[Any])
|
||||
@@ -850,13 +746,11 @@ description: nonebot.adapters 模块
|
||||
- `kwargs` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- TF
|
||||
|
||||
### _method_ `get_field(field_name, args, kwargs)` {#MessageTemplate-get-field}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field_name` (str)
|
||||
|
||||
- `args` (Sequence[Any])
|
||||
@@ -864,17 +758,14 @@ description: nonebot.adapters 模块
|
||||
- `kwargs` (Mapping[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Any, int | str]
|
||||
|
||||
### _method_ `format_field(value, format_spec)` {#MessageTemplate-format-field}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- `format_spec` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
@@ -36,7 +36,6 @@ description: nonebot.compat 模块
|
||||
- **说明:** FieldInfo class with extra property for compatibility with pydantic v1
|
||||
|
||||
- **参数**
|
||||
|
||||
- `default` (Any)
|
||||
|
||||
- `**kwargs` (Any)
|
||||
@@ -82,7 +81,6 @@ description: nonebot.compat 模块
|
||||
- **说明:** Construct a ModelField from given infos.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `annotation` (Any)
|
||||
@@ -90,7 +88,6 @@ description: nonebot.compat 模块
|
||||
- `field_info` (FieldInfo | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Self
|
||||
|
||||
### _method_ `get_default()` {#ModelField-get-default}
|
||||
@@ -102,7 +99,6 @@ description: nonebot.compat 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
### _method_ `validate_value(value)` {#ModelField-validate-value}
|
||||
@@ -110,11 +106,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate the value pass to the field.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `extract_field_info(field_info)` {#extract-field-info}
|
||||
@@ -122,11 +116,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get FieldInfo init kwargs from a FieldInfo instance.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field_info` (BaseFieldInfo)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `model_fields(model)` {#model-fields}
|
||||
@@ -134,11 +126,9 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get field list of a model.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (type[BaseModel])
|
||||
|
||||
- **返回**
|
||||
|
||||
- list[ModelField]
|
||||
|
||||
## _def_ `model_config(model)` {#model-config}
|
||||
@@ -146,17 +136,14 @@ description: nonebot.compat 模块
|
||||
- **说明:** Get config of a model.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (type[BaseModel])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `model_dump(model, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False)` {#model-dump}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `model` (BaseModel)
|
||||
|
||||
- `include` (set[str] | None)
|
||||
@@ -172,7 +159,6 @@ description: nonebot.compat 模块
|
||||
- `exclude_none` (bool)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
## _def_ `type_validate_python(type_, data)` {#type-validate-python}
|
||||
@@ -180,13 +166,11 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate data with given type.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[T])
|
||||
|
||||
- `data` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T
|
||||
|
||||
## _def_ `type_validate_json(type_, data)` {#type-validate-json}
|
||||
@@ -194,13 +178,11 @@ description: nonebot.compat 模块
|
||||
- **说明:** Validate JSON with given type.
|
||||
|
||||
- **参数**
|
||||
|
||||
- `type_` (type[T])
|
||||
|
||||
- `data` (str | bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- T
|
||||
|
||||
## _def_ `custom_validation(class_)` {#custom-validation}
|
||||
@@ -208,9 +190,7 @@ description: nonebot.compat 模块
|
||||
- **说明:** Use pydantic v1 like validator generator in pydantic v2
|
||||
|
||||
- **参数**
|
||||
|
||||
- `class_` (type[CVC])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[CVC]
|
||||
|
||||
@@ -24,7 +24,6 @@ NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及
|
||||
将会从 **环境变量** > **dotenv 配置文件** 的优先级读取环境信息。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
@@ -55,7 +54,6 @@ NoneBot 使用 [`pydantic`](https://pydantic-docs.helpmanual.io/) 以及
|
||||
配置方法参考: [配置](https://nonebot.dev/docs/appendices/config)
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None)
|
||||
|
||||
- `_env_file_encoding` (str | None)
|
||||
|
||||
@@ -18,7 +18,6 @@ description: nonebot.dependencies 模块
|
||||
继承自 `pydantic.fields.FieldInfo`,用于描述参数信息(不包括参数名)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `validate` (bool)
|
||||
@@ -30,7 +29,6 @@ description: nonebot.dependencies 模块
|
||||
- **说明:** 依赖注入容器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call`: 依赖注入的可调用对象,可以是任何 Callable 对象
|
||||
|
||||
- `pre_checkers`: 依赖注入解析前的参数检查
|
||||
@@ -44,31 +42,26 @@ description: nonebot.dependencies 模块
|
||||
### _staticmethod_ `parse_params(call, allow_types)` {#Dependent-parse-params}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` (\_DependentCallable[R])
|
||||
|
||||
- `allow_types` (tuple[type[Param], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[[ModelField](../compat.md#ModelField), ...]
|
||||
|
||||
### _staticmethod_ `parse_parameterless(parameterless, allow_types)` {#Dependent-parse-parameterless}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `parameterless` (tuple[Any, ...])
|
||||
|
||||
- `allow_types` (tuple[type[Param], ...])
|
||||
|
||||
- **返回**
|
||||
|
||||
- tuple[Param, ...]
|
||||
|
||||
### _classmethod_ `parse(*, call, parameterless=None, allow_types)` {#Dependent-parse}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` (\_DependentCallable[R])
|
||||
|
||||
- `parameterless` (Iterable[Any] | None)
|
||||
@@ -76,25 +69,20 @@ description: nonebot.dependencies 模块
|
||||
- `allow_types` (Iterable[type[Param]])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Dependent[R]
|
||||
|
||||
### _async method_ `check(**params)` {#Dependent-check}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `solve(**params)` {#Dependent-solve}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `**params` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, Any]
|
||||
|
||||
@@ -12,11 +12,9 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 获取可调用对象签名
|
||||
|
||||
- **参数**
|
||||
|
||||
- `call` ((...) -> Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- inspect.Signature
|
||||
|
||||
## _def_ `get_typed_annotation(param, globalns)` {#get-typed-annotation}
|
||||
@@ -24,13 +22,11 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 获取参数的类型注解
|
||||
|
||||
- **参数**
|
||||
|
||||
- `param` (inspect.Parameter)
|
||||
|
||||
- `globalns` (dict[str, Any])
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
## _def_ `check_field_type(field, value)` {#check-field-type}
|
||||
@@ -38,11 +34,9 @@ description: nonebot.dependencies.utils 模块
|
||||
- **说明:** 检查字段类型是否匹配
|
||||
|
||||
- **参数**
|
||||
|
||||
- `field` ([ModelField](../compat.md#ModelField))
|
||||
|
||||
- `value` (Any)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any
|
||||
|
||||
@@ -22,7 +22,6 @@ pip install nonebot2[aiohttp]
|
||||
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -38,23 +37,19 @@ pip install nonebot2[aiohttp]
|
||||
### _async method_ `request(setup)` {#Session-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `stream_request(setup, *, chunk_size=1024)` {#Session-stream-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- `chunk_size` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[Response](index.md#Response), None]
|
||||
|
||||
### _async method_ `setup()` {#Session-setup}
|
||||
@@ -64,7 +59,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close()` {#Session-close}
|
||||
@@ -74,7 +68,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -88,39 +81,32 @@ pip install nonebot2[aiohttp]
|
||||
### _async method_ `request(setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `stream_request(setup, *, chunk_size=1024)` {#Mixin-stream-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- `chunk_size` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[Response](index.md#Response), None]
|
||||
|
||||
### _method_ `websocket(setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
|
||||
|
||||
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -134,7 +120,6 @@ pip install nonebot2[aiohttp]
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Session
|
||||
|
||||
## _class_ `WebSocket(*, request, session, websocket)` {#WebSocket}
|
||||
@@ -142,7 +127,6 @@ pip install nonebot2[aiohttp]
|
||||
- **说明:** AIOHTTP Websocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` ([Request](index.md#Request))
|
||||
|
||||
- `session` (aiohttp.ClientSession)
|
||||
@@ -156,19 +140,16 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -178,7 +159,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -188,7 +168,6 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -198,33 +177,27 @@ pip install nonebot2[aiohttp]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -92,7 +92,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** FastAPI 驱动框架。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` (NoneBotConfig)
|
||||
@@ -124,21 +123,17 @@ pip install nonebot2[fastapi]
|
||||
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
|
||||
@@ -146,7 +141,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** 使用 `uvicorn` 启动 FastAPI
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
@@ -158,7 +152,6 @@ pip install nonebot2[fastapi]
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `FastAPIWebSocket(*, request, websocket)` {#FastAPIWebSocket}
|
||||
@@ -166,7 +159,6 @@ pip install nonebot2[fastapi]
|
||||
- **说明:** FastAPI WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (BaseRequest)
|
||||
|
||||
- `websocket` ([WebSocket](index.md#WebSocket))
|
||||
@@ -178,19 +170,16 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close(code=status.WS_1000_NORMAL_CLOSURE, reason="")` {#FastAPIWebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `receive()` {#FastAPIWebSocket-receive}
|
||||
@@ -200,7 +189,6 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#FastAPIWebSocket-receive-text}
|
||||
@@ -210,7 +198,6 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#FastAPIWebSocket-receive-bytes}
|
||||
@@ -220,25 +207,20 @@ pip install nonebot2[fastapi]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#FastAPIWebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#FastAPIWebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
@@ -22,7 +22,6 @@ pip install nonebot2[httpx]
|
||||
## _class_ `Session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -38,23 +37,19 @@ pip install nonebot2[httpx]
|
||||
### _async method_ `request(setup)` {#Session-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `stream_request(setup, *, chunk_size=1024)` {#Session-stream-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- `chunk_size` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[Response](index.md#Response), None]
|
||||
|
||||
### _async method_ `setup()` {#Session-setup}
|
||||
@@ -64,7 +59,6 @@ pip install nonebot2[httpx]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `close()` {#Session-close}
|
||||
@@ -74,7 +68,6 @@ pip install nonebot2[httpx]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -88,29 +81,24 @@ pip install nonebot2[httpx]
|
||||
### _async method_ `request(setup)` {#Mixin-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](index.md#Response)
|
||||
|
||||
### _method_ `stream_request(setup, *, chunk_size=1024)` {#Mixin-stream-request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- `chunk_size` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[Response](index.md#Response), None]
|
||||
|
||||
### _method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Mixin-get-session}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -124,13 +112,11 @@ pip install nonebot2[httpx]
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- Session
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -40,11 +40,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 设置一个 HTTP 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract method_ `setup_websocket_server(setup)` {#ASGIMixin-setup-websocket-server}
|
||||
@@ -52,23 +50,19 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 设置一个 WebSocket 服务器路由配置
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Cookies(cookies=None)` {#Cookies}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (CookieTypes)
|
||||
|
||||
### _method_ `set(name, value, domain="", path="/")` {#Cookies-set}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `value` (str)
|
||||
@@ -78,13 +72,11 @@ description: nonebot.drivers 模块
|
||||
- `path` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `get(name, default=None, domain=None, path=None)` {#Cookies-get}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `default` (str | None)
|
||||
@@ -94,13 +86,11 @@ description: nonebot.drivers 模块
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | None
|
||||
|
||||
### _method_ `delete(name, domain=None, path=None)` {#Cookies-delete}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str)
|
||||
|
||||
- `domain` (str | None)
|
||||
@@ -108,39 +98,32 @@ description: nonebot.drivers 模块
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `clear(domain=None, path=None)` {#Cookies-clear}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `domain` (str | None)
|
||||
|
||||
- `path` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `update(cookies=None)` {#Cookies-update}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `cookies` (CookieTypes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `as_header(request)` {#Cookies-as-header}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (Request)
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, str]
|
||||
|
||||
## _abstract class_ `Driver(env, config)` {#Driver}
|
||||
@@ -152,7 +135,6 @@ description: nonebot.drivers 模块
|
||||
驱动器控制框架的启动和停止,适配器的注册,以及机器人生命周期管理。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env)): 包含环境信息的 Env 对象
|
||||
|
||||
- `config` ([Config](../config.md#Config)): 包含配置信息的 Config 对象
|
||||
@@ -180,13 +162,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个协议适配器
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter` (type[[Adapter](../adapters/index.md#Adapter)]): 适配器类
|
||||
|
||||
- `**kwargs`: 其他传递给适配器的参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract property_ `type` {#Driver-type}
|
||||
@@ -206,13 +186,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 启动驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `on_startup(func)` {#Driver-on-startup}
|
||||
@@ -220,11 +198,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个启动时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
### _method_ `on_shutdown(func)` {#Driver-on-shutdown}
|
||||
@@ -232,11 +208,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 注册一个停止时执行的函数
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` (LIFESPAN_FUNC)
|
||||
|
||||
- **返回**
|
||||
|
||||
- LIFESPAN_FUNC
|
||||
|
||||
### _classmethod_ `on_bot_connect(func)` {#Driver-on-bot-connect}
|
||||
@@ -246,15 +220,12 @@ description: nonebot.drivers 模块
|
||||
装饰一个函数使他在 bot 连接成功时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_BotConnectionHook](../typing.md#T-BotConnectionHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_BotConnectionHook](../typing.md#T-BotConnectionHook)
|
||||
|
||||
### _classmethod_ `on_bot_disconnect(func)` {#Driver-on-bot-disconnect}
|
||||
@@ -264,15 +235,12 @@ description: nonebot.drivers 模块
|
||||
装饰一个函数使他在 bot 连接断开时执行。
|
||||
|
||||
钩子函数参数:
|
||||
|
||||
- bot: 当前连接上的 Bot 对象
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ([T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [T_BotDisconnectionHook](../typing.md#T-BotDisconnectionHook)
|
||||
|
||||
## _var_ `ForwardDriver` {#ForwardDriver}
|
||||
@@ -306,11 +274,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一个 HTTP 请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Response](#Response)
|
||||
|
||||
### _abstract method_ `stream_request(setup, *, chunk_size=1024)` {#HTTPClientMixin-stream-request}
|
||||
@@ -318,13 +284,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一个 HTTP 流式请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](#Request))
|
||||
|
||||
- `chunk_size` (int)
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[Response](#Response), None]
|
||||
|
||||
### _abstract method_ `get_session(params=None, headers=None, cookies=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#HTTPClientMixin-get-session}
|
||||
@@ -332,7 +296,6 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 获取一个 HTTP 会话
|
||||
|
||||
- **参数**
|
||||
|
||||
- `params` (QueryTypes)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -346,7 +309,6 @@ description: nonebot.drivers 模块
|
||||
- `proxy` (str | None)
|
||||
|
||||
- **返回**
|
||||
|
||||
- HTTPClientSession
|
||||
|
||||
## _class_ `HTTPServerSetup(<auto>)` {#HTTPServerSetup}
|
||||
@@ -362,7 +324,6 @@ description: nonebot.drivers 模块
|
||||
- **参数**
|
||||
|
||||
auto
|
||||
|
||||
- `H10: '1.0'`
|
||||
|
||||
- `H11: '1.1'`
|
||||
@@ -386,7 +347,6 @@ description: nonebot.drivers 模块
|
||||
## _class_ `Request(method, url, *, params=None, headers=None, cookies=None, content=None, data=None, json=None, files=None, version=HTTPVersion.H11, timeout=None, proxy=None)` {#Request}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `method` (str | bytes)
|
||||
|
||||
- `url` (URL | str | RawURL)
|
||||
@@ -414,7 +374,6 @@ description: nonebot.drivers 模块
|
||||
## _class_ `Response(status_code, *, headers=None, content=None, request=None)` {#Response}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `status_code` (int)
|
||||
|
||||
- `headers` (HeaderTypes)
|
||||
@@ -452,7 +411,6 @@ description: nonebot.drivers 模块
|
||||
## _abstract class_ `WebSocket(*, request)` {#WebSocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (Request)
|
||||
|
||||
### _abstract property_ `closed` {#WebSocket-closed}
|
||||
@@ -470,7 +428,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
@@ -478,13 +435,11 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 关闭 WebSocket 连接请求
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -496,7 +451,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _abstract async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -508,7 +462,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _abstract async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -520,7 +473,6 @@ description: nonebot.drivers 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send(data)` {#WebSocket-send}
|
||||
@@ -528,11 +480,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket text/bytes 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str | bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
@@ -540,11 +490,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket text 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _abstract async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
@@ -552,11 +500,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发送一条 WebSocket binary 信息
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _abstract class_ `WebSocketClientMixin(<auto>)` {#WebSocketClientMixin}
|
||||
@@ -572,11 +518,9 @@ description: nonebot.drivers 模块
|
||||
- **说明:** 发起一个 WebSocket 连接
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](#WebSocket), None]
|
||||
|
||||
## _class_ `WebSocketServerSetup(<auto>)` {#WebSocketServerSetup}
|
||||
@@ -594,19 +538,14 @@ description: nonebot.drivers 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(driver) -> type[D]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (type[D])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[D]
|
||||
|
||||
**2.** `(driver, __m, /, *mixins) -> type[CombinedDriver]`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `driver` (type[D])
|
||||
|
||||
- `__m` (type[[Mixin](#Mixin)])
|
||||
@@ -614,5 +553,4 @@ description: nonebot.drivers 模块
|
||||
- `*mixins` (type[[Mixin](#Mixin)])
|
||||
|
||||
- **返回**
|
||||
|
||||
- type[CombinedDriver]
|
||||
|
||||
@@ -18,7 +18,6 @@ None 驱动适配
|
||||
- **说明:** None 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
@@ -40,13 +39,11 @@ None 驱动适配
|
||||
- **说明:** 启动 none driver
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args`
|
||||
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `exit(force=False)` {#Driver-exit}
|
||||
@@ -54,9 +51,7 @@ None 驱动适配
|
||||
- **说明:** 退出 none driver
|
||||
|
||||
- **参数**
|
||||
|
||||
- `force` (bool): 强制退出
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
@@ -68,7 +68,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** Quart 驱动框架
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` (NoneBotConfig)
|
||||
@@ -100,21 +99,17 @@ pip install nonebot2[quart]
|
||||
### _method_ `setup_http_server(setup)` {#Driver-setup-http-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([HTTPServerSetup](index.md#HTTPServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _method_ `setup_websocket_server(setup)` {#Driver-setup-websocket-server}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([WebSocketServerSetup](index.md#WebSocketServerSetup))
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _method_ `run(host=None, port=None, *args, app=None, **kwargs)` {#Driver-run}
|
||||
@@ -122,7 +117,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** 使用 `uvicorn` 启动 Quart
|
||||
|
||||
- **参数**
|
||||
|
||||
- `host` (str | None)
|
||||
|
||||
- `port` (int | None)
|
||||
@@ -134,7 +128,6 @@ pip install nonebot2[quart]
|
||||
- `**kwargs`
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket_ctx)` {#WebSocket}
|
||||
@@ -142,7 +135,6 @@ pip install nonebot2[quart]
|
||||
- **说明:** Quart WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` (BaseRequest)
|
||||
|
||||
- `websocket_ctx` (WebsocketContext)
|
||||
@@ -154,19 +146,16 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -176,7 +165,6 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -186,7 +174,6 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -196,25 +183,20 @@ pip install nonebot2[quart]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
@@ -22,11 +22,9 @@ pip install nonebot2[websockets]
|
||||
## _def_ `catch_closed(func)` {#catch-closed}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `func` ((P) -> CoroutineType[Any, Any, T])
|
||||
|
||||
- **返回**
|
||||
|
||||
- (P) -> CoroutineType[Any, Any, T]
|
||||
|
||||
## _class_ `Mixin(<auto>)` {#Mixin}
|
||||
@@ -40,11 +38,9 @@ pip install nonebot2[websockets]
|
||||
### _method_ `websocket(setup)` {#Mixin-websocket}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `setup` ([Request](index.md#Request))
|
||||
|
||||
- **返回**
|
||||
|
||||
- AsyncGenerator[[WebSocket](index.md#WebSocket), None]
|
||||
|
||||
## _class_ `WebSocket(*, request, websocket)` {#WebSocket}
|
||||
@@ -52,7 +48,6 @@ pip install nonebot2[websockets]
|
||||
- **说明:** Websockets WebSocket Wrapper
|
||||
|
||||
- **参数**
|
||||
|
||||
- `request` ([Request](index.md#Request))
|
||||
|
||||
- `websocket` (ClientConnection)
|
||||
@@ -64,19 +59,16 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `close(code=1000, reason="")` {#WebSocket-close}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `code` (int)
|
||||
|
||||
- `reason` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
### _async method_ `receive()` {#WebSocket-receive}
|
||||
@@ -86,7 +78,6 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str | bytes
|
||||
|
||||
### _async method_ `receive_text()` {#WebSocket-receive-text}
|
||||
@@ -96,7 +87,6 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- str
|
||||
|
||||
### _async method_ `receive_bytes()` {#WebSocket-receive-bytes}
|
||||
@@ -106,33 +96,27 @@ pip install nonebot2[websockets]
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- bytes
|
||||
|
||||
### _async method_ `send_text(data)` {#WebSocket-send-text}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (str)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
### _async method_ `send_bytes(data)` {#WebSocket-send-bytes}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `data` (bytes)
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
## _class_ `Driver(env, config)` {#Driver}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `env` ([Env](../config.md#Env))
|
||||
|
||||
- `config` ([Config](../config.md#Config))
|
||||
|
||||
@@ -62,7 +62,6 @@ NoneBotException
|
||||
- **说明:** 指示 NoneBot 应该忽略该事件。可由 PreProcessor 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `reason`: 忽略事件的原因
|
||||
|
||||
## _class_ `SkippedException(<auto>)` {#SkippedException}
|
||||
@@ -101,7 +100,6 @@ NoneBotException
|
||||
- **说明:** 指示 NoneBot 阻止本次 API 调用或修改本次调用返回值,并返回自定义内容。 可由 api hook 抛出。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `result`: 返回的内容
|
||||
|
||||
## _class_ `StopPropagation(<auto>)` {#StopPropagation}
|
||||
@@ -200,7 +198,6 @@ NoneBotException
|
||||
- **说明:** 代表 `Adapter` 抛出的异常,所有的 `Adapter` 都要在内部继承自这个 `Exception`。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `adapter_name`: 标识 adapter
|
||||
|
||||
## _class_ `NoLogException(<auto>)` {#NoLogException}
|
||||
|
||||
@@ -60,11 +60,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Driver](drivers/index.md#Driver): 全局 [Driver](drivers/index.md#Driver) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -80,27 +78,20 @@ description: nonebot 模块
|
||||
- **重载**
|
||||
|
||||
**1.** `(name) -> Adapter`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (str): 适配器名称
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Adapter](adapters/index.md#Adapter): 指定名称的 [Adapter](adapters/index.md#Adapter) 对象
|
||||
|
||||
**2.** `(name) -> A`
|
||||
|
||||
- **参数**
|
||||
|
||||
- `name` (type[A]): 适配器类型
|
||||
|
||||
- **返回**
|
||||
|
||||
- A: 指定类型的 [Adapter](adapters/index.md#Adapter) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 指定的 [Adapter](adapters/index.md#Adapter) 未注册
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -121,11 +112,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, [Adapter](adapters/index.md#Adapter)]: 所有 [Adapter](adapters/index.md#Adapter) 实例字典
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -143,11 +132,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: Server App 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- AssertionError: 全局 Driver 对象不是 [ASGIMixin](drivers/index.md#ASGIMixin) 类型
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -167,11 +154,9 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- Any: ASGI 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- AssertionError: 全局 Driver 对象不是 [ASGIMixin](drivers/index.md#ASGIMixin) 类型
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
@@ -192,15 +177,12 @@ description: nonebot 模块
|
||||
当不提供时,返回一个 [Bot](adapters/index.md#Bot)。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `self_id` (str | None): 用来识别 [Bot](adapters/index.md#Bot) 的 [Bot.self_id](adapters/index.md#Bot-self-id) 属性
|
||||
|
||||
- **返回**
|
||||
|
||||
- [Bot](adapters/index.md#Bot): [Bot](adapters/index.md#Bot) 对象
|
||||
|
||||
- **异常**
|
||||
|
||||
- KeyError: 对应 self_id 的 Bot 不存在
|
||||
|
||||
- ValueError: 没有传入 self_id 且没有 Bot 可用
|
||||
@@ -224,13 +206,11 @@ description: nonebot 模块
|
||||
empty
|
||||
|
||||
- **返回**
|
||||
|
||||
- dict[str, [Bot](adapters/index.md#Bot)]: 一个以 [Bot.self_id](adapters/index.md#Bot-self-id) 为键
|
||||
|
||||
[Bot](adapters/index.md#Bot) 对象为值的字典
|
||||
|
||||
- **异常**
|
||||
|
||||
- ValueError: 全局 [Driver](drivers/index.md#Driver) 对象尚未初始化 ([nonebot.init](#init) 尚未调用)
|
||||
|
||||
- **用法**
|
||||
@@ -250,13 +230,11 @@ description: nonebot 模块
|
||||
也可以传入自定义的 `_env_file` 来指定 NoneBot 从该文件读取配置。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `_env_file` (DOTENV_TYPE | None): 配置文件名,默认从 `.env.{env_name}` 中读取配置
|
||||
|
||||
- `**kwargs` (Any): 任意变量,将会存储到 [Driver.config](drivers/index.md#Driver-config) 对象里
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
@@ -270,13 +248,11 @@ description: nonebot 模块
|
||||
- **说明:** 启动 NoneBot,即运行全局 [Driver](drivers/index.md#Driver) 对象。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `*args` (Any): 传入 [Driver.run](drivers/index.md#Driver-run) 的位置参数
|
||||
|
||||
- `**kwargs` (Any): 传入 [Driver.run](drivers/index.md#Driver-run) 的命名参数
|
||||
|
||||
- **返回**
|
||||
|
||||
- None
|
||||
|
||||
- **用法**
|
||||
|
||||
@@ -25,7 +25,6 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
NoneBot 日志记录器对象。
|
||||
|
||||
默认信息:
|
||||
|
||||
- 格式: `[%(asctime)s %(name)s] %(levelname)s: %(message)s`
|
||||
- 等级: `INFO` ,根据 `config.log_level` 配置改变
|
||||
- 输出: 输出至 stdout
|
||||
@@ -47,11 +46,9 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
### _method_ `emit(record)` {#LoguruHandler-emit}
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (logging.LogRecord)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _def_ `default_filter(record)` {#default-filter}
|
||||
@@ -59,11 +56,9 @@ NoneBot 使用 [`loguru`][loguru] 来记录日志信息。
|
||||
- **说明:** 默认的日志过滤器,根据 `config.log_level` 配置改变日志等级。
|
||||
|
||||
- **参数**
|
||||
|
||||
- `record` (Record)
|
||||
|
||||
- **返回**
|
||||
|
||||
- untyped
|
||||
|
||||
## _var_ `default_format` {#default-format}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user