Skip to content

Commit

Permalink
docs: message-and-event
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyElaina committed Jul 26, 2023
1 parent 6a55cf7 commit 0b7fa76
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/avilla/NAV.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
- [协议配置](basic/hello-avilla/protocol-config.md)
- [事件监听器](basic/hello-avilla/listen.md)
- [上下文对象 Context](basic/hello-avilla/context-basic.md)
- [消息与消息事件](basic/hello-avilla/message-and-event.md)
- [发送消息](basic/hello-avilla/message-send.md)
- [消息与消息事件](basic/hello-avilla/message-and-event.md)
- [选择器对象 Selector](basic/hello-avilla/selector-basic.md)
- [消息链对象 MessageChain](basic/hello-avilla/mesasge-chain.md)
- [文本元素 Text](basic/hello-avilla/element-text.md)
Expand Down
53 changes: 53 additions & 0 deletions docs/avilla/basic/hello-avilla/message-and-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
消息(Message) 是 Avilla 着重支持的交互形式,我们提供了完善的抽象来处理不同平台上的这一行为。

```python
from avilla.core.message import Message
from avilla.standard.core.message import MessageReceived

@broadcast.receiver(MessageReceived)
async def on_message_received(message: Message):
...
```

Avilla 在标准化模块(`avilla.standard.core`)中包含了以下事件声明,你可以直接从该模块导入,并通过文档中提供的 API Reference 获取其详情:

- `MessageReceived`: 接收到消息。
- `MessageSent`: 消息发送,可能获取到其他客户端的同步事件。
- `MessageEdited`: 消息被编辑,可能获取到其他客户端的同步事件。
- `MessageRevoked`: 消息被撤回/删除。**无法获取 Message 对象**

消息 (Message) 对象的字段定义如下所示。

```python
class Message(
id: str,
scene: Selector, # 消息所处的场景。
sender: Selector, # 消息的发送者,通常也在 scene 范围内。
content: MessageChain, # 消息的内容,以 MessageChain 表示。
time: datetime, # 消息发送的时刻。
reply: Selector | None = None # 消息的回复对象,可选。
)
```

注意,消息对象是可以被转换为选择器形式的 (`Selectable`,具备 `to_selector` 方法),请参考以下示例:

```python
msg = Message(
id="message-test",
scene=Selector().land(...).group(...)
)
msg.to_selector() # => Selector().land(...).group(...).message("message-test")
```

你可以认为 `Selector.last_key` (返回最后一个节点名称的 property) 是 `"message"` 的,
都指向某个 Message

此外,Message 可以作为 `Metadata` 使用,关于这方面的详情可以参考以下链接:

- [元信息 (Metadata) 基本操作](/avilla/basic/metadata-basic.md)

!!! tip
如果你希望了解关于消息发送的内容,请参考这里:

- [发送消息](/avilla/basic/hello-avilla/message-send.md)
- [消息链与元素](/avilla/basic/message/chain-and-element.md)
2 changes: 1 addition & 1 deletion docs/avilla/basic/installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
因此,以下提及内容的前提为在理想情况下。

!!! tip
可喜可贺,Avilla 及其文档目前致力于致力于提升使用体验,所以我们会尽可能的让文档记录详尽。
可喜可贺,Avilla 及其文档目前致力于提升使用体验,所以我们会尽可能的让文档记录详尽。

想要运行 Avilla ,你至少需要安装 `avilla-core`

Expand Down

0 comments on commit 0b7fa76

Please sign in to comment.