Skip to content

Commit

Permalink
feat: add endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
FedorLap2006 committed May 7, 2024
1 parent 9adedf8 commit 1efec2e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ var (
return EndpointMessageReactions(cID, mID, eID) + "/" + uID
}

EndpointPoll = func(cID, mID string) string {
return EndpointChannel(cID) + "/polls/" + mID
}
EndpointPollAnswerVoters = func(cID, mID, aID string) string {
return EndpointPoll(cID, mID) + "/answers/" + aID
}
EndpointPollExpire = func(cID, mID string) string {
return EndpointPoll(cID, mID) + "/expire"
}

EndpointApplicationGlobalCommands = func(aID string) string {
return EndpointApplication(aID) + "/commands"
}
Expand Down
39 changes: 39 additions & 0 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3453,3 +3453,42 @@ func (s *Session) UserApplicationRoleConnectionUpdate(appID string, rconn *Appli
err = unmarshal(body, &st)
return
}

// ----------------------------------------------------------------------
// Functions specific to polls
// ----------------------------------------------------------------------

func (s *Session) PollAnswerVoters(channelID, messageID, answerID string) (voters []*User, err error) {
endpoint := EndpointPollAnswerVoters(channelID, messageID, answerID)

var body []byte
body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint)
if err != nil {
return
}

var r struct {
Users []*User `json:"users"`
}

err = unmarshal(body, &r)
if err != nil {
return
}

voters = r.Users
return
}

func (s *Session) PollExpire(channelID, messageID string) (msg *Message, err error) {
endpoint := EndpointPollExpire(channelID, messageID)

var body []byte
body, err = s.RequestWithBucketID("PUT", endpoint, nil, endpoint)
if err != nil {
return
}

err = unmarshal(body, &msg)
return
}

0 comments on commit 1efec2e

Please sign in to comment.