Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 5eede12

Browse files
authored
Merge pull request #20 from anka-afk/v2
update: 补全部分文档
2 parents 533f8ce + bd84c7a commit 5eede12

6 files changed

Lines changed: 85 additions & 8 deletions

File tree

.vitepress/config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,13 @@ export default defineConfig({
196196
collapsed: true,
197197
items: [
198198
{ text: "AstrMessageEvent", link: "/astr_message_event" },
199+
{ text: "AstrBotMessage", link: "/astrbot_message" },
200+
{ text: "MessageType", link: "/message_type" },
201+
{ text: "MessageMember", link: "/message_member" },
199202
{ text: "Context", link: "/context" },
200203
{ text: "Star", link: "/star" },
201204
{ text: "StarMetadata", link: "/star_metadata" },
205+
{ text: "PlatformMetadata", link: "/platform_metadata" },
202206
],
203207
},
204208
],

dev/star/resources/astr_message_event.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ async def helloworld(self, event: AstrMessageEvent):
2020
#### 消息
2121

2222
1. `message_str(str)`: 纯文本消息, 例如收到消息事件"你好", `event.message_str`将会是`"你好"`
23-
2. `message_obj(AstrBotMessage)`: 消息对象, 参考: [AstrBotMessage(施工中)]
23+
2. `message_obj(AstrBotMessage)`: 消息对象, 参考: [AstrBotMessage](./astrbot_message.md)
2424
3. `is_at_or_wake_command(bool)`: 是否@了机器人/消息带有唤醒词/为私聊(插件注册的事件监听器会让 is_wake 设为 True, 但是不会让这个属性置为 True)
2525

2626
#### 消息来源
2727

28-
4. `role(str)`: 用户是否为管理员, 两个可选选项:`"member" of "admin"`
29-
5. `platform_meta(PlatformMetadata)`: 消息平台的信息, 参考: [PlatformMetadata(施工中)]
30-
6. `session_id(str)`: 会话 id, 格式为 `platform_name:message_type:session_id`, 建议直接使用 9 中的`unified_msg_origin`作为代替
31-
7. `session(MessageSesion)`: 会话 id, 用于唯一识别一个会话, `session_id``unified_msg_origin`是它的字符串表示
32-
8. `unified_msg_origin(str)`: 会话 id, 等同于 6 中的`session_id`, 建议使用
28+
4. `role(str)`: 用户是否为管理员, 两个可选选项:`"member" or "admin"`
29+
5. `platform_meta(PlatformMetadata)`: 消息平台的信息, 参考: [PlatformMetadata](./platform_metadata.md)
30+
6. `session_id(str)`: 不包含平台的会话 id, 以 qq 平台为例, 在私聊中它是对方 qq 号, 在群聊中它是群号, 它无法标记具体平台, 建议直接使用 9 中的`unified_msg_origin`作为代替
31+
7. `session(MessageSession)`: 会话对象, 用于唯一识别一个会话, `unified_msg_origin`是它的字符串表示, `session_id`等价于`session.session_id`
32+
8. `unified_msg_origin(str)`: 会话 id, 格式为: `platform_name:message_type:session_id`, 建议使用
3333

3434
#### 事件控制
3535

@@ -71,7 +71,7 @@ get_messages() -> List[BaseMessageComponent]
7171
get_message_type() -> MessageType
7272
```
7373

74-
该方法用于获取消息类型, 消息类型参考: [MessageType(施工中)]
74+
该方法用于获取消息类型, 消息类型参考: [MessageType](./message_type.md)
7575

7676
5. is_private_chat
7777

@@ -142,7 +142,7 @@ get_group_id() -> str
142142

143143
```Python
144144
get_session_id() -> str
145-
# 等同于self.session_id或self.unified_msg_origin
145+
# 等同于self.session_id或self.session.session_id
146146
```
147147

148148
该方法用于获取当前会话 id, 格式为 `platform_name:message_type:session_id`
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# AstrBotMessage
6+
7+
AstrBot 消息对象, 它是一个消息的容器, 所有平台的消息在接收时都被转换为该类型的对象, 以实现不同平台的统一处理。
8+
9+
对于每个事件, 一定都有一个驱动该事件的 AstrBotMessage 对象。
10+
11+
```mermaid
12+
平台发来的消息 --> AstrBotMessage --> AstrBot 事件
13+
```
14+
15+
### 属性
16+
17+
1. `type(MessageType)`: 消息类型, 参考: [MessageType](./message_type.md)
18+
2. `self_id(str)`: 机器人自身 id, 例如在 aiocqhttp 平台, 它是机器人自身的 qq 号
19+
3. `session_id(str)`: 不包含平台的会话 id, 以 qq 平台为例, 在私聊中它是对方 qq 号, 在群聊中它是群号
20+
4. `message_id(str)`: 消息 id, 消息的唯一标识符, 用于引用或获取某一条消息
21+
5. `group_id(str)`: 群组 id, 如果为私聊, 则为空字符串
22+
6. `sender(MessageMember)`: 消息发送者, 参考: [MessageMember](./message_member.md)
23+
7. `message(List[BaseMessageComponent])`: 消息链(Nakuru 格式), 包含该事件中的所有消息内容, 参考: [BaseMessageComponent(施工中)]
24+
8. `message_str(str)`: 纯文本消息字符串, 相当于把消息链转换为纯文本(会丢失信息!)
25+
9. `raw_message(object)`: 原始消息对象, 包含所有消息的原始数据(平台适配器发来的)
26+
10. `timestamp(int)`: 消息的时间戳(会自动初始化)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# MessageMember
6+
7+
消息发送者对象, 用于标记一个消息发送者的最基本信息
8+
9+
### 属性
10+
11+
1. `user_id(str)`: 消息发送者 id, 唯一, 例如在 aiocqhttp 平台, 它是发送者的 qq 号
12+
2. `nickname(str)`: 昵称, 例如在 aiocqhttp 平台, 它是发送者的 qq 昵称, 它会被自动初始化

dev/star/resources/message_type.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# MessageType
6+
7+
消息类型, 用于区分消息是私聊还是群聊消息, 继承自`Enum`枚举类型
8+
9+
使用方法如下:
10+
11+
```Python
12+
from astrbot.api import MessageType
13+
print(MessageType.GROUP_MESSAGE)
14+
```
15+
16+
### 内容
17+
18+
1. `GROUP_MESSAGE`: 群聊消息
19+
2. `FRIEND_MESSAGE`: 私聊消息
20+
3. `OTHER_MESSAGE`: 其他消息, 例如系统消息等
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# PlatformMetadata
6+
7+
平台元数据, 包含了平台的基本信息, 例如平台名称, 平台类型等.
8+
9+
### 属性
10+
11+
1. `name(str)`: 平台的名称
12+
2. `description(str)`: 平台的描述
13+
3. `id(str)`: 平台的唯一标识符, 用于区分不同的平台
14+
4. `default_config_tmpl(dict)`: 平台的默认配置模板, 用于生成平台的默认配置文件
15+
5. `adapter_display_name(str)`: 显示在 WebUI 中的平台名称, 默认为 `name`(可以更改)

0 commit comments

Comments
 (0)