Skip to content

Commit e7897b5

Browse files
authored
Merge pull request #2 from lxbot/develop
bump v1.3.0
2 parents 7e42d27 + a95472b commit e7897b5

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

message.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ type (
1212
Room Room `json:"room"`
1313
Message Message `json:"message"`
1414
Mode string `json:"mode"`
15+
Raw interface{} `json:"raw"`
16+
17+
shouldKeepAttachments bool
1518
}
1619
pack struct {
1720
User User `json:"user"`
1821
Room Room `json:"room"`
1922
Message Message `json:"message"`
23+
Raw interface{} `json:"raw"`
2024
}
2125
User struct {
2226
ID string `json:"id"`
@@ -52,6 +56,8 @@ func NewLXMessage(msg M) (*LXMessage, error) {
5256
Room: pack.Room,
5357
Message: pack.Message,
5458
Mode: "",
59+
Raw: pack.Raw,
60+
shouldKeepAttachments: false,
5561
}, nil
5662
}
5763

@@ -60,6 +66,12 @@ func (this *LXMessage) SetText(text string) *LXMessage {
6066
return this
6167
}
6268

69+
func (this *LXMessage) SetAttachments(attachments []Attachment) *LXMessage {
70+
this.Message.Attachments = attachments
71+
this.shouldKeepAttachments = true
72+
return this
73+
}
74+
6375
func (this *LXMessage) Send() *LXMessage {
6476
this.Mode = "send"
6577
return this
@@ -76,7 +88,11 @@ func (this *LXMessage) ToMap() (M, error) {
7688
return nil, err
7789
}
7890

79-
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
91+
if this.shouldKeepAttachments {
92+
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
93+
} else {
94+
r["message"].(M)["attachments"] = []map[string]interface{}{}
95+
}
8096
return r, err
8197
}
8298

0 commit comments

Comments
 (0)