Skip to content

Commit

Permalink
Merge pull request #2 from lxbot/develop
Browse files Browse the repository at this point in the history
bump v1.3.0
  • Loading branch information
mohemohe authored Nov 14, 2020
2 parents 7e42d27 + a95472b commit e7897b5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ type (
Room Room `json:"room"`
Message Message `json:"message"`
Mode string `json:"mode"`
Raw interface{} `json:"raw"`

shouldKeepAttachments bool
}
pack struct {
User User `json:"user"`
Room Room `json:"room"`
Message Message `json:"message"`
Raw interface{} `json:"raw"`
}
User struct {
ID string `json:"id"`
Expand Down Expand Up @@ -52,6 +56,8 @@ func NewLXMessage(msg M) (*LXMessage, error) {
Room: pack.Room,
Message: pack.Message,
Mode: "",
Raw: pack.Raw,
shouldKeepAttachments: false,
}, nil
}

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

func (this *LXMessage) SetAttachments(attachments []Attachment) *LXMessage {
this.Message.Attachments = attachments
this.shouldKeepAttachments = true
return this
}

func (this *LXMessage) Send() *LXMessage {
this.Mode = "send"
return this
Expand All @@ -76,7 +88,11 @@ func (this *LXMessage) ToMap() (M, error) {
return nil, err
}

r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
if this.shouldKeepAttachments {
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
} else {
r["message"].(M)["attachments"] = []map[string]interface{}{}
}
return r, err
}

Expand Down

0 comments on commit e7897b5

Please sign in to comment.