Skip to content

Commit 80beaed

Browse files
committed
Update route.mdx
1 parent 885111c commit 80beaed

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

content/docs/development/route.mdx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 路由系统
3-
description: 熟悉的内容,爱来自 axum & tower。
3+
description: sithra 的路由系统,灵感源自 axum tower,专为 ChatBot 消息和事件处理设计
44
---
55

66
import { Callout } from "fumadocs-ui/components/callout";
@@ -9,23 +9,17 @@ import { Bot, Code, Puzzle, ArrowDown, Terminal, Workflow, Layers, Database } fr
99

1010
<Callout type="info" icon={<Bot />}>
1111

12-
## 重要内容
12+
## 重要提示
1313

14-
路由系统是 sithra 分发消息和事件的核心,
15-
16-
是插件处理消息和事件的核心与前置知识。
17-
18-
本节请务必,请务必,请务必认真阅读!
14+
路由系统是 sithra 分发消息和事件的核心机制,也是插件处理消息和事件的基础。请务必认真阅读本节内容。
1915

2016
</Callout>
2117

2218
## 路由系统概述
2319

24-
sithra-server 是一个基于 Tokio 和 Tower 的 sithra-rs 子模块,它主要负责为插件开发者提供
20+
sithra-server 是 sithra-rs 的一个子模块,基于 Tokio 和 Tower 构建。它主要为插件开发者提供处理消息和事件的高级路由封装。
2521

26-
处理消息和事件的路由的高阶封装。
27-
28-
其主要部分与 axum 实现相似,但其是专为 sithra 设计的,以满足 ChatBot 的某些特定需求。
22+
其实现方式与 axum 相似,但专为 sithra 设计,以满足 ChatBot 的特定需求。
2923

3024
### 1. 路由形式 (Routing Forms)
3125

@@ -113,7 +107,7 @@ let plugin = plugin.map(move |r| {
113107

114108
<Callout>
115109

116-
与手动发送请求/相应数据包不同的是,端点返回值会自动与请求来自的频道、关联 ID、 BotId 进行关联。
110+
与手动发送响应/请求数据包不同的是,端点返回值会自动与请求来自的频道、关联 ID、 BotId 进行关联。
117111

118112
有时,您可能需要手动发送响应/请求,例如在处理错误时。如果您发现手动发送相应无效,且作为返回值正常。
119113

@@ -136,9 +130,9 @@ let plugin = plugin.map(move |r| {
136130
- `Infallible` (后面可能修改为 never)
137131
- `()` (空响应)
138132
- 某些请求的负载,比如说 `SendMessage` (响应转换为发送消息的请求)
139-
- 套娃使用,比如最常用的 `Option<SendMessage>` 表示响应可能发送消息
140-
- 套娃套娃使用,比如说可能发送 10 个分别可能错误的消息 `Option<[Result<SendMessage, Error>; 10]>`
141-
- 套娃套娃套娃使用……
133+
- `Option<SendMessage>`: 例如表示响应可能发送消息
134+
- `Option<[Result<SendMessage, Error>; 10]>`: 例如,表示可能发送一个包含10条消息的数组,每条消息都可能成功或失败。
135+
- 其他复杂组合:只要最终类型实现了 `IntoResponse`,您就可以根据业务逻辑自由组合。
142136
- 其他自定义结构体,只要实现了 `IntoResponse` Trait
143137

144138
**示例:**
@@ -166,6 +160,7 @@ async fn maybe_send_msg() -> Option<SendMessage> {
166160
- **`Context<T, S>`**: 缝合了 `Payload<T>` & `State<S>` & `BotId` & `Correlation` 以提供一些易用的高级功能,某些情况下非常好用☝️🤓。(通过它发送的请求会自动与当前处理的请求关联,与将请求作为响应返回的行为基本一致)
167161

168162
**综合示例:**
163+
169164
```rust
170165
use sithra_kit::{
171166
matchopt, plugin,
@@ -211,4 +206,4 @@ async fn echo(Payload(msg): Payload<Message<H>>) -> Option<SendMessage> {
211206
- [management-tools](https://github.com/SithraBot/sithra-rs/blob/main/plugins/management-tools/src/main.rs): 使用 `Context` 提取器的例子
212207
- [mc-tools](https://github.com/SithraBot/sithra-rs/blob/main/plugins/mc-tools/src/main.rs): 单路由路径多端点的例子
213208

214-
通过这些特性,sithra 提供了一个强大而富有表现力的路由系统,使得构建健壮的 ChatBot 变得简单而高效。
209+
通过这些特性,sithra 提供了一个强大而富有表现力的路由系统,使得构建健壮的 ChatBot 变得简单而高效。

0 commit comments

Comments
 (0)