From 4637c5b7e8524ca780aec8fa2622c78db1449556 Mon Sep 17 00:00:00 2001 From: nitroflap Date: Fri, 1 Apr 2022 00:08:25 +0300 Subject: [PATCH] feat(rest): add pagination params for GuildBans --- restapi.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/restapi.go b/restapi.go index d8ff931..0230fd6 100644 --- a/restapi.go +++ b/restapi.go @@ -577,12 +577,30 @@ func (s *Session) GuildLeave(guildID string) (err error) { return } -// GuildBans returns an array of GuildBan structures for all bans of a -// given guild. -// guildID : The ID of a Guild. -func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error) { +// GuildBans returns an array of GuildBan structures for bans in the given guild. +// guildID : The ID of a Guild +// limit : Max number of bans to return (max 1000) +// beforeID : If not empty all returned users will be after the given id +// afterID : If not empty all returned users will be before the given id +func (s *Session) GuildBans(guildID string, limit int, beforeID, afterID string) (st []*GuildBan, err error) { + uri := EndpointGuildBans(guildID) - body, err := s.RequestWithBucketID("GET", EndpointGuildBans(guildID), nil, EndpointGuildBans(guildID)) + v := url.Values{} + if limit != 0 { + v.Set("limit", strconv.Itoa(limit)) + } + if beforeID != "" { + v.Set("before", beforeID) + } + if afterID != "" { + v.Set("after", afterID) + } + + if len(v) > 0 { + uri += "?" + v.Encode() + } + + body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuildBans(guildID)) if err != nil { return }