Skip to content

Commit

Permalink
オブジェクトを取れるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
mohemohe committed Jan 29, 2020
1 parent f202a28 commit 7e42d27
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
type (
M = map[string]interface{}
LXMessage struct {
pack *pack
User User `json:"user"`
Room Room `json:"room"`
Message Message `json:"message"`
Mode string `json:"mode"`
}
pack struct {
User User `json:"user"`
Room Room `json:"room"`
Message Message `json:"message"`
Mode string `json:"mode"`
}
User struct {
ID string `json:"id"`
Expand Down Expand Up @@ -45,31 +47,36 @@ func NewLXMessage(msg M) (*LXMessage, error) {
if err := json.Unmarshal(t, pack); err != nil {
return nil, err
}
return &LXMessage{pack}, nil
return &LXMessage{
User: pack.User,
Room: pack.Room,
Message: pack.Message,
Mode: "",
}, nil
}

func (this *LXMessage) Text(text string) *LXMessage {
this.pack.Message.Text = text
func (this *LXMessage) SetText(text string) *LXMessage {
this.Message.Text = text
return this
}

func (this *LXMessage) Send() *LXMessage {
this.pack.Mode = "send"
this.Mode = "send"
return this
}

func (this *LXMessage) Reply() *LXMessage {
this.pack.Mode = "reply"
this.Mode = "reply"
return this
}

func (this *LXMessage) ToMap() (M, error) {
r, err := toMap(this.pack)
r, err := toMap(this)
if err != nil {
return nil, err
}

r["message"].(M)["attachments"], err = toArrayMap(this.pack.Message.Attachments)
r["message"].(M)["attachments"], err = toArrayMap(this.Message.Attachments)
return r, err
}

Expand Down

0 comments on commit 7e42d27

Please sign in to comment.