Skip to content

Commit ef8c13e

Browse files
committed
docs: sync current api documentation
1 parent dd8ba7d commit ef8c13e

69 files changed

Lines changed: 363 additions & 398 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "botrs"
33
version = "0.13.0"
44
edition = "2024"
55
authors = ["YinMo19"]
6-
description = "A Rust QQ Bot framework based on QQ Guild Bot API"
6+
description = "A Rust QQ bot framework for QQ gateway events and bot OpenAPI"
77
license = "MIT"
88
repository = "https://github.com/YinMo19/botrs"
99
keywords = ["qq", "bot", "guild", "api", "async"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# BotRS - Rust QQ Guild Bot Framework
1+
# BotRS - Rust QQ Bot Framework
22
## Author: YinMo19
33

44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5-
[![Rust](https://img.shields.io/badge/rust-1.70+-blue.svg)](https://www.rust-lang.org)
5+
[![Rust](https://img.shields.io/badge/rust-1.85+-blue.svg)](https://www.rust-lang.org)
66
[![GitHub](https://img.shields.io/badge/github-YinMo19-blue.svg)](https://github.com/YinMo19)
77
[![Crates.io](https://img.shields.io/crates/v/botrs.svg)](https://crates.io/crates/botrs)
88

99
> 本实现不是 qqbot 的官方 rust 版本实现。
1010
11-
BotRS 是一个用 Rust 实现的 QQ 频道机器人框架,基于 [QQ 频道机器人 API](https://bot.q.qq.com/wiki/develop/api/)。它提供了类型安全、高性能、易于使用的接口来开发 QQ 频道机器人
11+
BotRS 是一个用 Rust 实现的 QQ 机器人框架,基于 [QQ 频道机器人 API](https://bot.q.qq.com/wiki/develop/api/) 与当前开放平台接口,覆盖频道、私信、群和 C2C 消息场景。它提供类型安全、异步、session-first 的接口来开发 QQ 机器人
1212

1313
## 快速开始
1414

docs/.vitepress/config.mts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from "vitepress";
33
// https://vitepress.dev/reference/site-config
44
export default defineConfig({
55
title: "BotRS",
6-
description: "A Rust QQ Bot framework based on QQ Guild Bot API",
6+
description: "A Rust QQ bot framework for QQ gateway events and bot OpenAPI",
77
head: [
88
["link", { rel: "icon", href: "/favicon.ico" }],
99
["meta", { name: "theme-color", content: "#646cff" }],
@@ -17,7 +17,7 @@ export default defineConfig({
1717
label: "English",
1818
lang: "en",
1919
title: "BotRS",
20-
description: "A Rust QQ Bot framework based on QQ Guild Bot API",
20+
description: "A Rust QQ bot framework for QQ gateway events and bot OpenAPI",
2121
themeConfig: {
2222
nav: [
2323
{ text: "Guide", link: "/guide/introduction" },
@@ -101,12 +101,12 @@ export default defineConfig({
101101
text: "Performance and Security",
102102
items: [
103103
{
104-
text: "Performace",
105-
link: "/guide/performance.md",
104+
text: "Performance",
105+
link: "/guide/performance",
106106
},
107107
{
108108
text: "Security",
109-
link: "/guide/security.md",
109+
link: "/guide/security",
110110
},
111111
],
112112
},
@@ -256,7 +256,7 @@ export default defineConfig({
256256
label: "简体中文",
257257
lang: "zh-CN",
258258
title: "BotRS",
259-
description: "基于 QQ 频道机器人 API 的 Rust QQ 机器人框架",
259+
description: "面向 QQ 网关事件与机器人 OpenAPI 的 Rust QQ 机器人框架",
260260
themeConfig: {
261261
nav: [
262262
{ text: "指南", link: "/zh/guide/introduction" },
@@ -341,11 +341,11 @@ export default defineConfig({
341341
items: [
342342
{
343343
text: "高性能指南",
344-
link: "/zh/guide/performance.md",
344+
link: "/zh/guide/performance",
345345
},
346346
{
347347
text: "安全指南",
348-
link: "/zh/guide/security.md",
348+
link: "/zh/guide/security",
349349
},
350350
],
351351
},

docs/README.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,8 @@ docs/
99
├── .vitepress/ # VitePress configuration
1010
│ └── config.mts # Site configuration
1111
├── guide/ # English guides
12-
│ ├── introduction.md
13-
│ ├── installation.md
14-
│ ├── quick-start.md
15-
│ └── configuration.md
1612
├── api/ # English API reference
17-
│ ├── client.md
18-
│ └── event-handler.md
1913
├── examples/ # English examples
20-
│ └── getting-started.md
2114
├── zh/ # Chinese documentation
2215
│ ├── guide/ # Chinese guides
2316
│ ├── api/ # Chinese API reference
@@ -36,31 +29,31 @@ docs/
3629

3730
### Prerequisites
3831

39-
- Node.js 16+
40-
- npm 7+
32+
- Node.js 22 (same as CI)
33+
- pnpm 9
4134

4235
### Local Development
4336

4437
```bash
4538
# Install dependencies
46-
npm install
39+
pnpm install
4740

4841
# Start development server
49-
npm run docs:dev
42+
pnpm docs:dev
5043

5144
# Build for production
52-
npm run docs:build
45+
pnpm docs:build
5346

5447
# Preview production build
55-
npm run docs:preview
48+
pnpm docs:preview
5649
```
5750

5851
### Available Scripts
5952

60-
- `npm run docs:dev` - Start development server with hot reload
61-
- `npm run docs:build` - Build static site for production
62-
- `npm run docs:preview` - Preview production build locally
63-
- `npm run docs:serve` - Serve built documentation
53+
- `pnpm docs:dev` - Start development server with hot reload
54+
- `pnpm docs:build` - Build static site for production
55+
- `pnpm docs:preview` - Preview production build locally
56+
- `pnpm docs:serve` - Serve built documentation
6457

6558
## Documentation Guidelines
6659

@@ -145,15 +138,13 @@ VitePress supports extended markdown features:
145138
- Syntax highlighting with line numbers
146139
- Custom containers (info, tip, warning, danger)
147140
- Code group tabs
148-
- Math expressions
149-
- Mermaid diagrams
150141

151142
## Deployment
152143

153144
The documentation is automatically deployed when changes are pushed to the main branch. The build process:
154145

155-
1. Installs dependencies
156-
2. Runs `npm run docs:build`
146+
1. Installs dependencies with pnpm
147+
2. Runs `pnpm docs:build`
157148
3. Deploys to the hosting platform
158149

159150
## Maintenance

docs/api/bot-api.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BotApi
22

3-
`BotApi` is the stateless REST client used by a bot while handling events. After a gateway event arrives, handlers usually call it through the event session to send replies, recall channel messages, upload group/C2C files, manage announcements, schedules and pins, inspect reaction users, or create API permission requests.
3+
`BotApi` is the shared typed REST client used by a bot while handling events. After a gateway event arrives, handlers usually call it through the event session to send replies, recall messages, upload group/C2C files, manage guild/channel resources, announcements, schedules, pins, reactions, permissions, roles, mute state, or audio controls.
44

55
When your bot is driven by `Client`, you normally do not construct `BotApi` yourself. Every event callback receives a session that exposes the shared API client:
66

@@ -26,15 +26,19 @@ let me = api.get_bot_info().await?;
2626
| Area | Methods |
2727
| --- | --- |
2828
| Bot identity and gateway discovery | `get_bot_info`, `get_gateway` |
29-
| Guild channel messages | `send_message`, `recall_message` |
30-
| Group and C2C messages | `send_group_message`, `send_c2c_message` |
31-
| Direct messages | `create_direct_message`, `send_direct_message` |
29+
| Guilds and channels | `get_guild`, `list_bot_guilds`, `get_channel`, `list_channels`, `create_channel`, `update_channel`, `delete_channel`, `create_private_channel` |
30+
| Members, roles, and mute | `get_guild_member`, `list_guild_members`, `delete_guild_member`, `list_roles`, `create_role`, `update_role`, `delete_role`, `add_member_role`, `delete_member_role`, `mute_guild`, `mute_member`, `mute_members` |
31+
| Channel permissions and voice members | `get_channel_permissions`, `update_channel_permissions`, `get_channel_role_permissions`, `update_channel_role_permissions`, `list_voice_channel_members` |
32+
| Guild channel messages | `get_message`, `list_messages`, `send_message`, `update_message`, `recall_message`, `send_setting_guide` |
33+
| Group and C2C messages | `send_group_message`, `send_c2c_message`, `recall_group_message`, `recall_c2c_message` |
34+
| Direct messages | `create_direct_message`, `send_direct_message`, `recall_direct_message`, `send_direct_setting_guide` |
3235
| Group/C2C files | `post_group_file`, `post_c2c_file` |
33-
| Announcements | `create_announce`, `create_recommend_announce`, `delete_announce` |
36+
| Announcements | `create_channel_announce`, `delete_channel_announce`, `create_announce`, `create_recommend_announce`, `delete_announce` |
3437
| Schedules | `get_schedules`, `get_schedule`, `create_schedule`, `update_schedule`, `delete_schedule` |
3538
| API permissions | `get_api_permissions`, `post_permission_demand` |
3639
| Reactions | `put_reaction`, `delete_reaction`, `get_reaction_users` |
37-
| Pins | `put_pin`, `delete_pin`, `get_pins` |
40+
| Pins | `put_pin`, `delete_pin`, `clean_pins`, `get_pins` |
41+
| Audio controls | `post_audio`, `put_mic`, `delete_mic` |
3842

3943
## Sending Messages
4044

@@ -48,7 +52,9 @@ let params = GroupMessageParams::new_text("hello group");
4852
group_session.send_message(params).await?;
4953
```
5054

51-
Guild channel messages and DMs use `MessageParams` / `DirectMessageParams`. Group and C2C messages use `GroupMessageParams` / `C2CMessageParams`, matching QQ's open-message shape. For ark, embed, markdown, keyboard, or media payloads, set the corresponding field on the parameter struct.
55+
Guild channel messages and DMs use `MessageParams` / `DirectMessageParams`. Group and C2C messages use `GroupMessageParams` / `C2CMessageParams`, matching QQ's open-message shape.
56+
57+
Inside event handlers, prefer the session helpers when they fit: `send_text_message`, `send_markdown_message`, `send_ark_message`, `send_embed_message`, `send_keyboard_message`, and group/C2C `send_media_message`. For lower-level API calls, use params constructors such as `new_markdown`, `new_ark`, `new_embed`, `new_keyboard`, and `new_media`; they fill the protocol message type for you.
5258

5359
## Files and Media
5460

@@ -59,10 +65,7 @@ let media = session
5965
.post_file(1, "https://example.com/image.png", None)
6066
.await?;
6167

62-
let mut params = GroupMessageParams::default();
63-
params.msg_type = 7;
64-
params.media = Some(media);
65-
session.send_message(params).await?;
68+
session.send_media_message(media).await?;
6669
```
6770

6871
When `srv_send_msg` is `Some(true)`, the platform sends the uploaded file directly, so you usually do not need a separate media message.
@@ -73,7 +76,7 @@ These APIs are direct wrappers around their protocol payloads:
7376

7477
- Announcements can be created from an existing message or from a list of recommended channels.
7578
- Schedules support listing, fetching one item, creating, updating, and deleting.
76-
- Pins support pinning one message, unpinning one message, and listing pinned message ids.
79+
- Pins support pinning one message, unpinning one message, clearing all pins, and listing pinned message ids.
7780
- API permission requests take `channel_id`, `APIPermissionDemandIdentify`, and a description.
7881

7982
```rust

docs/api/client.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let mut client = Client::new(token, intents, MyHandler, /* is_sandbox: */ false)
1010
client.start().await?;
1111
```
1212

13-
`Client::new` returns `Result<Client<H>>` because it constructs the underlying `HttpClient` and may fail if TLS / DNS configuration is invalid.
13+
`Client::new` returns `Result<Client<H>>` because it validates the token and constructs the underlying `HttpClient`.
1414

1515
## Constructors
1616

@@ -21,14 +21,14 @@ client.start().await?;
2121

2222
## Lifecycle
2323

24-
- `start().await`connects, identifies, and runs the event loop. Returns once the loop terminates (gracefully or via fatal error).
24+
- `start().await`performs startup REST calls, starts gateway sessions, and runs the event loop until the event channel closes.
2525
Dropping the running `Client` task closes the gateway connection.
2626

2727
There are no `stop` / `is_connected` / `get_session_info` methods — the framework intentionally exposes a small surface and pushes session details into events instead. Use `EventHandler::ready` and `EventHandler::resumed` to observe lifecycle changes.
2828

2929
## Reconnect behaviour
3030

31-
`start()` reconnects automatically on transient gateway failures, applying the throttling described in the [gateway guide](../guide/gateway.md). When a fatal failure (invalid token, unrecoverable handshake) is detected, `start()` resolves with the propagated `BotError`.
31+
`start()` propagates startup failures from token validation, `get_bot_info`, and `get_gateway`. After gateway sessions are spawned, transient gateway failures are retried with the throttling described in the [gateway guide](../guide/gateway.md); unrecoverable identify failures stop that shard's reconnect loop and are logged by the session manager.
3232

3333
## Graceful shutdown
3434

docs/api/context.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ async fn ready(&self, session: ReadySession) {
2222

2323
async fn message_create(&self, mut session: ChannelReplySession) {
2424
let message = session.message().clone();
25-
if message.content.as_deref() == Some("!ping") {
25+
if message.author.bot {
26+
return;
27+
}
28+
29+
if message.content.trim() == "!ping" {
2630
let _ = session.reply("pong").await;
2731
}
2832
}

docs/api/error-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub type Result<T> = std::result::Result<T, BotError>;
2323
| `MethodNotAllowed(String)` | 405. |
2424
| `Forbidden(String)` | 403 / permission denied. |
2525
| `RateLimit { retry_after: u64 }` | 429 with parsed `Retry-After` (in seconds). |
26-
| `SequenceNumber(String)` | Gateway sequence skew that demands resume / reconnect. |
27-
| `Server(String)` | 5xx responses without structured codes. |
26+
| `SequenceNumber(String)` | Reserved sequence/order error from the low-level mapper. |
27+
| `Server(String)` | 5xx responses with the parsed platform diagnostic. |
2828
| `Auth(String)` | Higher-level authentication / session issue. |
2929
| `Connection(String)` | Gateway lifecycle / heartbeat failure. |
3030
| `Config(String)` | Invalid configuration before requests run. |
@@ -83,4 +83,4 @@ Constants for these codes are exposed from `botrs::error`, for example `botrs::e
8383

8484
- [Bot API](./bot-api.md) — every route that can produce these errors.
8585
- [Token](./token.md) — credential refresh logic that surfaces `Auth` errors.
86-
- [Gateway guide](../guide/gateway.md) — how the framework reacts to `Connection` / `SequenceNumber` errors.
86+
- [Gateway guide](../guide/gateway.md) — how the framework handles gateway connection failures.

docs/api/event-handler.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ impl EventHandler for MyBot {
9494

9595
async fn message_create(&self, mut session: ChannelReplySession) {
9696
let message = session.message().clone();
97-
if message.author.as_ref().and_then(|author| author.bot).unwrap_or_default() { return; }
98-
if let Some(content) = &message.content {
99-
if content.trim() == "!ping" {
100-
let _ = session.reply("Pong!").await;
101-
}
97+
if message.author.bot {
98+
return;
99+
}
100+
101+
if message.content.trim() == "!ping" {
102+
let _ = session.reply("Pong!").await;
102103
}
103104
}
104105
}

docs/api/models/messages.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Group and C2C messages have their own models:
1111
- `GroupMessage` maps to `GROUP_AT_MESSAGE_CREATE`; the key routing field is `group_openid`.
1212
- `C2CMessage` maps to `C2C_MESSAGE_CREATE`; the key routing field usually comes from `author.user_openid`.
1313

14-
These event models retain platform-provided message id, content, attachments, mentions, timestamp, references, and internal `event_id`. For plain replies, prefer `session.reply(...)` from the matching reply session. For richer replies, build the matching parameter struct manually.
14+
These event models retain platform-provided message id, content, attachments, mentions, timestamp, references, and internal `event_id`. Message id, content, author, routing id, and timestamp are required fields on normal message events; group/C2C messages also carry the required open-message `message_type`. Optional protocol fields stay optional.
15+
16+
Attachments use `MessageAttachment`. When an attachment appears, the filename, content type, size, and URL are plain fields. `id` stays optional because open-message attachment payloads may omit it, while `width` and `height` default to `0` for non-image or payloads that do not include dimensions.
1517

1618
```rust
1719
let message = session.message();
18-
if let Some(content) = &message.content {
19-
if content.trim() == "/ping" {
20-
session.reply("pong").await?;
21-
}
20+
if !message.author.bot && message.content.trim() == "/ping" {
21+
session.reply("pong").await?;
2222
}
2323
```
2424

@@ -33,14 +33,22 @@ Outbound sending uses four parameter types:
3333
| `GroupMessageParams` | Group messages |
3434
| `C2CMessageParams` | C2C messages |
3535

36-
The most common helpers are `new_text` and `with_reply`:
36+
Use session helpers inside reply-capable handlers:
37+
38+
```rust
39+
session.reply("pong").await?;
40+
session.send_markdown_message("# hello").await?;
41+
session.send_embed_message(embed).await?;
42+
```
43+
44+
For direct `BotApi` calls or custom fields, use params constructors:
3745

3846
```rust
3947
let params = MessageParams::new_text("pong").with_reply(message_id);
4048
session.send_message(params).await?;
4149
```
4250

43-
For complex messages, set fields directly:
51+
The rich constructors are `new_markdown`, `new_ark`, `new_embed`, `new_keyboard`, and, for group/C2C messages, `new_media`. Set fields directly only when you need a protocol field not covered by those constructors:
4452

4553
- `embed` for embed messages.
4654
- `ark` for ark templates.
@@ -64,9 +72,9 @@ let params = DirectMessageParams::new_text("hello");
6472
session.send_direct_message(&dm_session.guild_id, params).await?;
6573
```
6674

67-
## Open Message msg_type
75+
## Open Message Types
6876

69-
Group and C2C messages use the platform's numeric `msg_type`. Text generally keeps the default value 0; media uses 7; markdown, ark, embed, and other types follow the platform's protocol values. Guild channel messages use the Rust-modeled `MessageCreateType`.
77+
Group and C2C messages still serialize to the platform's open-message type codes, but normal user code should use session helpers or params constructors instead of setting the numeric value by hand. Guild channel and direct-message params use `MessageCreateType` internally.
7078

7179
## See Also
7280

0 commit comments

Comments
 (0)