Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pointsbot/discordgo
Browse files Browse the repository at this point in the history
  • Loading branch information
A-da-m committed Dec 23, 2023
2 parents 2ef4ae6 + bf46250 commit 93f2dd3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
43 changes: 37 additions & 6 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2711,11 +2711,22 @@ func (s *Session) ThreadMemberRemove(threadID, memberID string, options ...Reque
return err
}

// ThreadMember returns thread member object for the specified member of a thread
func (s *Session) ThreadMember(threadID, memberID string, options ...RequestOption) (member *ThreadMember, err error) {
endpoint := EndpointThreadMember(threadID, memberID)
// ThreadMember returns thread member object for the specified member of a thread.
// withMember : Whether to include a guild member object.
func (s *Session) ThreadMember(threadID, memberID string, withMember bool, options ...RequestOption) (member *ThreadMember, err error) {
uri := EndpointThreadMember(threadID, memberID)

queryParams := url.Values{}
if withMember {
queryParams.Set("with_member", "true")
}

if len(queryParams) > 0 {
uri += "?" + queryParams.Encode()
}

var body []byte
body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint, options...)
body, err = s.RequestWithBucketID("GET", uri, nil, uri, options...)

if err != nil {
return
Expand All @@ -2726,9 +2737,29 @@ func (s *Session) ThreadMember(threadID, memberID string, options ...RequestOpti
}

// ThreadMembers returns all members of specified thread.
func (s *Session) ThreadMembers(threadID string, options ...RequestOption) (members []*ThreadMember, err error) {
// limit : Max number of thread members to return (1-100). Defaults to 100.
// afterID : Get thread members after this user ID.
// withMember : Whether to include a guild member object for each thread member.
func (s *Session) ThreadMembers(threadID string, limit int, withMember bool, afterID string, options ...RequestOption) (members []*ThreadMember, err error) {
uri := EndpointThreadMembers(threadID)

queryParams := url.Values{}
if withMember {
queryParams.Set("with_member", "true")
}
if limit > 0 {
queryParams.Set("limit", strconv.Itoa(limit))
}
if afterID != "" {
queryParams.Set("after", afterID)
}

if len(queryParams) > 0 {
uri += "?" + queryParams.Encode()
}

var body []byte
body, err = s.RequestWithBucketID("GET", EndpointThreadMembers(threadID), nil, EndpointThreadMembers(threadID), options...)
body, err = s.RequestWithBucketID("GET", uri, nil, uri, options...)

if err != nil {
return
Expand Down
4 changes: 4 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ type ThreadMember struct {
JoinTimestamp time.Time `json:"join_timestamp"`
// Any user-thread settings, currently only used for notifications
Flags int `json:"flags"`
// Additional information about the user.
// NOTE: only present if the withMember parameter is set to true
// when calling Session.ThreadMembers or Session.ThreadMember.
Member *Member `json:"member,omitempty"`
}

// ThreadsList represents a list of threads alongisde with thread member objects for the current user.
Expand Down

0 comments on commit 93f2dd3

Please sign in to comment.