File tree Expand file tree Collapse file tree 2 files changed +79
-1
lines changed Expand file tree Collapse file tree 2 files changed +79
-1
lines changed Original file line number Diff line number Diff line change @@ -26,3 +26,42 @@ They will pull a message or action from the `SendChannel` or `ActionChannel` res
26
26
They will not return until a message or action is received.
27
27
28
28
~~ Oh shoot, that's all of it?~~
29
+
30
+ By the way, for message types and event types, you need to implement the corresponding ` MessageType ` method to facilitate ` GoneBot ` processing:
31
+ ``` go
32
+ // This describes a simple part of a message
33
+ type MessageSegment struct {
34
+ // Message type
35
+ Type string ` json:"type"`
36
+ // Make sure it implements MessageType interface
37
+ Data MessageType ` json:"data"`
38
+ }
39
+
40
+ // Implement this to create a message type
41
+ type MessageType interface {
42
+ // Which adapter is this message for
43
+ AdapterName () string
44
+ // Which message type is this message for
45
+ TypeName () string
46
+ // Convert this message segment to raw text
47
+ ToRawText (msg MessageSegment ) string
48
+ }
49
+ ```
50
+ For example, the text message type of ` GoneBot ` is implemented like this:
51
+ ``` go
52
+ type TextType struct {
53
+ Text string ` json:"text"`
54
+ }
55
+
56
+ func (serializer TextType ) AdapterName () string {
57
+ return " "
58
+ }
59
+
60
+ func (serializer TextType ) TypeName () string {
61
+ return " text"
62
+ }
63
+
64
+ func (serializer TextType ) ToRawText (msg MessageSegment ) string {
65
+ return msg.Data .(TextType).Text
66
+ }
67
+ ```
Original file line number Diff line number Diff line change 1
1
---
2
- title : 常用方法
2
+ title : 常用方法 & 约定
3
3
icon : meteor
4
4
order : 3
5
5
category :
@@ -25,3 +25,42 @@ author: Kingcq
25
25
分别从 ` SendChannel ` 和 ` ActionChannel ` 中取出一个消息或动作,用来处理,在没有消息或动作时会阻塞线程,直到有消息或动作再返回。
26
26
27
27
~~ 卧槽,没了~~
28
+
29
+ 同时,对于消息段类型和事件类型,你需要实现对应的 MessageType 方法,以方便 ` GoneBot ` 处理:
30
+ ``` go
31
+ // This describes a simple part of a message
32
+ type MessageSegment struct {
33
+ // Message type
34
+ Type string ` json:"type"`
35
+ // Make sure it implements MessageType interface
36
+ Data MessageType ` json:"data"`
37
+ }
38
+
39
+ // Implement this to create a message type
40
+ type MessageType interface {
41
+ // Which adapter is this message for
42
+ AdapterName () string
43
+ // Which message type is this message for
44
+ TypeName () string
45
+ // Convert this message segment to raw text
46
+ ToRawText (msg MessageSegment ) string
47
+ }
48
+ ```
49
+ 例如,` GoneBot ` 内置的文本消息类型是这样实现的:
50
+ ``` go
51
+ type TextType struct {
52
+ Text string ` json:"text"`
53
+ }
54
+
55
+ func (serializer TextType ) AdapterName () string {
56
+ return " "
57
+ }
58
+
59
+ func (serializer TextType ) TypeName () string {
60
+ return " text"
61
+ }
62
+
63
+ func (serializer TextType ) ToRawText (msg MessageSegment ) string {
64
+ return msg.Data .(TextType).Text
65
+ }
66
+ ```
You can’t perform that action at this time.
0 commit comments