Skip to content

Commit 001c6fa

Browse files
committed
📝 update server.md
1 parent 56f8d46 commit 001c6fa

File tree

1 file changed

+179
-2
lines changed

1 file changed

+179
-2
lines changed

tutorial/entari/server.md

Lines changed: 179 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ next: 数据库插件
1010
## 安装
1111

1212
::: code-group
13+
```bash:no-line-numbers [entari-cli]
14+
entari add server
15+
```
16+
1317
```bash:no-line-numbers [pdm]
1418
pdm add entari-plugin-server
1519
```
@@ -23,14 +27,33 @@ pip install entari-plugin-server
2327
```
2428
:::
2529

30+
## 配置项
31+
- `adapters`: 适配器配置列表。
32+
每个适配器配置项均为一个字典,必须包含 `$path` 键,表示适配器的路径。
33+
其他键值对将作为适配器的配置项传递给适配器类的构造函数。
34+
已知适配器请参考下方的官方适配器和社区适配器部分。
35+
- `direct_adapter`: 是否使用直连适配器。
36+
直连适配器的情况下,App 将直接与 Server 插件通信,而不通过网络请求。
37+
也就是说,不再需要填写基础配置项 `network`
38+
- `transfer_client`: 是否将 Entari 客户端收到的事件转发给连接到 server 的其他 Satori 客户端。
39+
开启转发的情况下,Server 插件将作为一个中继,转发事件给所有连接的客户端。
40+
并且客户端的响应调用,Server 插件也将一并转发回上游。
41+
- `host`: 服务器主机地址,默认为 `127.0.0.1`
42+
- `port`: 服务器端口,默认为 `5140`
43+
- `path`: 服务器部署路径,默认为空字符串 `""`
44+
- `version`: 服务器使用的协议版本,默认为 `v1`
45+
- `token`: 服务器访问令牌,如果为 `None` 则不启用令牌验证,默认为 `None`
46+
- `options`: Uvicorn 的其他配置项,默认为 `None`。此处参考 [Uvicorn 配置项](https://www.uvicorn.org/settings/)
47+
- `stream_threshold`: 流式传输阈值,超过此大小将使用流式传输,默认为 `16 * 1024 * 1024` (16MB)
48+
- `stream_chunk_size`: 流式传输分块大小,流式传输时每次发送的数据大小,默认为 `64 * 1024` (64KB)
49+
50+
2651
## 适配器
2752

2853
`entari-plugin-server` 支持加载适配器,适配器用于将不同的协议转换为 Satori 协议,从而使 Entari 能够与更多的服务进行交互。
2954

3055
适配器需要单独安装,安装后即可在配置文件中使用。
3156

32-
`direct_adapter` 配置为 `true`,则表示 Entari 将直接使用适配器进行通信,而不经过 Satori 服务器。此时你不需要声明基础配置的 `network` 字段。
33-
3457
### Satori适配器
3558

3659
**安装**
@@ -58,6 +81,16 @@ pip install satori-python-adapter-satori
5881
- `token`: 对接的 Satori Server 的访问令牌,默认为空
5982
- `post_update`: 是否接管资源上传接口,默认为`False`
6083

84+
```yaml:no-line-numbers
85+
adapters:
86+
- $path: @satori
87+
host: localhost
88+
port: 5140
89+
path: "satori"
90+
token: "your_token"
91+
post_update: true
92+
```
93+
6194
### OneBot V11适配器
6295

6396
**安装**
@@ -80,12 +113,29 @@ pip install satori-python-adapter-onebot11
80113
**配置(正向)**
81114
- `endpoint`: 连接 OneBot V11协议端的路径
82115
- `access_token`: OneBot V11协议的访问令牌, 默认为空
116+
- `timeout`: 发送请求的超时时间,默认为 30 秒
117+
118+
```yaml:no-line-numbers
119+
adapters:
120+
- $path: @onebot11.forward
121+
endpoint: "http://localhost:8081"
122+
access_token: "your_token"
123+
```
83124

84125
**配置(反向)**
85126
- `prefix`: 反向适配器于 Server 的路径前缀, 默认为 `/`
86127
- `path`: 反向适配器于 Server 的路径, 默认为 `onebot/v11`
87128
- `endpoint`: 反向适配器于 Server 的路径端点, 默认为 `ws` (完整路径即为 `/onebot/v11/ws`)
88129
- `access_token`: 反向适配器的访问令牌, 默认为空
130+
- `timeout`: 发送请求的超时时间,默认为 30 秒
131+
132+
```yaml:no-line-numbers
133+
adapters:
134+
- $path: @onebot11.reverse
135+
path: "onebot/v11"
136+
endpoint: "ws"
137+
access_token: "your_token"
138+
```
89139

90140
### Console适配器
91141

@@ -108,6 +158,133 @@ pip install satori-python-adapter-console
108158

109159
**配置**:参考 [`ConsoleSetting`](https://github.com/nonebot/nonechat/blob/main/nonechat/setting.py)
110160

161+
```yaml:no-line-numbers
162+
adapters:
163+
- $path: @console
164+
title: "控制台"
165+
user_name: "用户"
166+
bot_name: "机器人"
167+
# 其他配置项参考 ConsoleSetting
168+
```
169+
170+
### Milky 适配器
171+
172+
**安装**
173+
174+
:::code-group
175+
```bash:no-line-numbers [pdm]
176+
pdm add satori-python-adapter-milky
177+
```
178+
179+
```bash:no-line-numbers [uv]
180+
uv add satori-python-adapter-milky
181+
```
182+
183+
```bash:no-line-numbers [pip]
184+
pip install satori-python-adapter-milky
185+
```
186+
:::
187+
188+
**路径(`$path`)**`@milky.main``@milky.webhook` (websocket 或 webhook 适配器)
189+
190+
**配置(Websocket)**
191+
- `endpoint`: 连接 Milky 协议端的路径
192+
- `token`: Milky 协议的访问令牌, 默认为空
193+
- `token_in_query`: 是否将 token 放在查询参数中, 默认为`False`
194+
- `headers`: 连接时使用的自定义请求头, 默认为空字典
195+
196+
```yaml:no-line-numbers
197+
adapters:
198+
- $path: @milky.main
199+
endpoint: "ws://localhost:8082/milky"
200+
token: "your_token"
201+
```
202+
203+
**配置(Webhook)**
204+
- `endpoint`: 连接 Milky 协议端的路径 (用于发送请求)
205+
- `token`: Milky 协议的访问令牌, 默认为空
206+
- `headers`: 连接时使用的自定义请求头, 默认为空字典
207+
- `path`: Webhook 适配器于 Server 的路径, 默认为 `/milky`
208+
- `self_token`: Webhook 适配器的访问令牌, 默认为空
209+
210+
```yaml:no-line-numbers
211+
adapters:
212+
- $path: @milky.webhook
213+
endpoint: "http://localhost:8082/milky"
214+
token: "your_token"
215+
self_token: "milky_webhook_token"
216+
```
217+
218+
### QQ 适配器
219+
220+
**安装**
221+
222+
:::code-group
223+
224+
```bash:no-line-numbers [pdm]
225+
pdm add satori-python-adapter-qq
226+
```
227+
228+
```bash:no-line-numbers [uv]
229+
uv add satori-python-adapter-qq
230+
```
231+
232+
```bash
233+
pip install satori-python-adapter-qq
234+
```
235+
236+
:::
237+
238+
**路径(`$path`)**`@qq.main``@qq.websocket` (webhook 适配器或 websocket 适配器)
239+
240+
**配置(Webhook)**
241+
- `secrets`: QQ 机器人的 app_id 和 app_secret 的映射字典,格式为 `{app_id: app_secret}`
242+
- `path`: Webhook 适配器于 Server 的路径, 默认为 `/qqbot`
243+
- `certfile`: SSL 证书文件路径,默认为空 (等同于设置本插件的配置项 `options` 中的 `ssl_certfile`)
244+
- `keyfile`: SSL 密钥文件路径,默认为空 (等同于设置本插件的配置项 `options` 中的 `ssl_keyfile`)
245+
- `verify_payload`: 是否验证请求负载的签名,默认为`True`
246+
- `is_sandbox`: 是否连接到 QQ 机器人的沙箱环境,默认为`False`
247+
248+
```yaml:no-line-numbers
249+
adapters:
250+
- $path: @qq.main
251+
secrets:
252+
"10xxxxxxx": xxxxxxxx
253+
path: "/qq"
254+
certfile: "/path/to/domain.crt"
255+
keyfile: "/path/to/domain.key"
256+
verify_payload: true
257+
```
258+
259+
**配置(Websocket)**
260+
- `app_id`: QQ 机器人的应用 ID
261+
- `secret`: QQ 机器人的应用密钥
262+
- `token`: 连接 QQ 机器人的访问令牌
263+
- `shard`: 分片信息,格式为 `(shard_id, shard_count)`,默认为空
264+
- `intent`: 该 QQ 机器人的事件订阅掩码,具体请参考 [QQ 机器人文档](https://bot.q.qq.com/wiki/develop/api-v2/dev-prepare/interface-framework/event-emit.html#%E4%BA%8B%E4%BB%B6%E8%AE%A2%E9%98%85intents):
265+
- `guilds`: 频道和子频道相关事件,默认开启
266+
- `guild_members`: 频道成员相关事件,默认开启
267+
- `guild_messages`: 私域机器人下的频道消息事件,默认**关闭**
268+
- `guild_message_reactions`: 频道消息表态事件,默认**开启**
269+
- `direct_message`: 频道私信事件,默认**关闭**
270+
- `c2c_group_at_messages`: 单聊和群聊事件 (单聊消息、群 @ 消息等),默认**关闭**
271+
- `interaction`: 按钮互动事件,默认**关闭**
272+
- `message_audit`: 频道消息审核事件,默认**开启**
273+
- `forum_event`: 论坛频道相关事件,仅 *私域* 机器人能够设置此 intents,默认**关闭**
274+
- `audio_action`: 语音频道相关事件,默认**关闭**
275+
- `at_messages`: 公域机器人下的频道消息事件,默认**开启**
276+
- `is_sandbox`: 是否连接到 QQ 机器人的沙箱环境,默认为`False`
277+
278+
```yaml:no-line-numbers
279+
adapters:
280+
- $path: @qq.websocket
281+
app_id: "10xxxxxxx"
282+
secret: "xxxxxxxx"
283+
token: "your_token"
284+
intent:
285+
guild_messages: true
286+
at_messages: false
287+
```
111288

112289
### Lagrange适配器
113290

0 commit comments

Comments
 (0)