Skip to content

Commit

Permalink
Add DM support
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesBreslin committed Mar 2, 2020
1 parent 8897f5f commit 1fdbec4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rocket/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ func (msg *Message) Reply(text string) (Message, error) {
return msg.rocketCon.SendMessage(msg.RoomId, text)
}

func (msg *Message) DM(text string) (Message, error) {
if msg.IsDirect {
return msg.Reply(text)
}
return msg.rocketCon.DM(msg.UserName, text)
}

func (msg *Message) KickUser() {
msg.Reply("/kick @"+msg.UserName)
}
Expand Down
16 changes: 16 additions & 0 deletions rocket/rocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,22 @@ func (rock *RocketCon) SendMessage(rid string, text string) (Message, error) {
return msg, nil
}

func (rock *RocketCon) DM(username string, text string) (Message, error) {
obj := map[string] interface{} {
"method": "createDirectMessage",
"params": []string {
username,
},
}

reply, err := rock.runMethod(obj)
if err != nil {
return Message{}, err
}
rid := reply["result"].(map[string] interface{})["rid"].(string)
return rock.SendMessage(rid, text)
}

func (rock *RocketCon) React(mid string, emoji string) error {
reaction := map[string] interface{} {
"method": "setReaction",
Expand Down

0 comments on commit 1fdbec4

Please sign in to comment.