Skip to content

Commit

Permalink
add answer votes paging
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Apr 15, 2024
1 parent 3479848 commit c7e441c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rest/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Channels interface {
Follow(channelID snowflake.ID, targetChannelID snowflake.ID, opts ...RequestOpt) (*discord.FollowedChannel, error)

GetPollAnswerVotes(channelID snowflake.ID, messageID snowflake.ID, answerID int, after snowflake.ID, limit int, opts ...RequestOpt) ([]discord.User, error)
GetPollAnswerVotesPage(channelID snowflake.ID, messageID snowflake.ID, answerID int, startID snowflake.ID, limit int, opts ...RequestOpt) PollAnswerVotesPage
ExpirePoll(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) (*discord.Message, error)
}

Expand Down Expand Up @@ -238,6 +239,15 @@ func (s *channelImpl) GetPollAnswerVotes(channelID snowflake.ID, messageID snowf
return
}

func (s *channelImpl) GetPollAnswerVotesPage(channelID snowflake.ID, messageID snowflake.ID, answerID int, startID snowflake.ID, limit int, opts ...RequestOpt) PollAnswerVotesPage {
return PollAnswerVotesPage{
getItems: func(after snowflake.ID) ([]discord.User, error) {
return s.GetPollAnswerVotes(channelID, messageID, answerID, after, limit, opts...)
},
ID: startID,
}
}

func (s *channelImpl) ExpirePoll(channelID snowflake.ID, messageID snowflake.ID, opts ...RequestOpt) (message *discord.Message, err error) {
err = s.client.Do(ExpirePoll.Compile(nil, channelID, messageID), nil, &message, opts...)
return
Expand Down
25 changes: 25 additions & 0 deletions rest/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,28 @@ func (p *ThreadMemberPage) Next() bool {
}
return p.Err == nil
}

type PollAnswerVotesPage struct {
getItems func(after snowflake.ID) ([]discord.User, error)

Items []discord.User
Err error

ID snowflake.ID
}

func (p *PollAnswerVotesPage) Next() bool {
if p.Err != nil {
return false
}

if len(p.Items) > 0 {
p.ID = p.Items[0].ID
}

p.Items, p.Err = p.getItems(p.ID)
if p.Err == nil && len(p.Items) == 0 {
p.Err = ErrNoMorePages
}
return p.Err == nil
}

0 comments on commit c7e441c

Please sign in to comment.