Skip to content

Commit

Permalink
add with_counts to /users/@me/guilds funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlnrDev committed Jul 16, 2023
1 parent 09a5cb2 commit 836b4a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
14 changes: 8 additions & 6 deletions discord/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ type UnavailableGuild struct {

// OAuth2Guild is returned on the GetGuilds route
type OAuth2Guild struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Icon *string `json:"icon"`
Owner bool `json:"owner"`
Permissions Permissions `json:"permissions"`
Features []GuildFeature `json:"features"`
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Icon *string `json:"icon"`
Owner bool `json:"owner"`
Permissions Permissions `json:"permissions"`
Features []GuildFeature `json:"features"`
ApproximateMemberCount int `json:"approximate_member_count"`
ApproximatePresenceCount int `json:"approximate_presence_count"`
}

// GuildWelcomeScreen is the Welcome Screen of a Guild
Expand Down
14 changes: 8 additions & 6 deletions rest/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type OAuth2 interface {
GetCurrentAuthorizationInfo(bearerToken string, opts ...RequestOpt) (*discord.AuthorizationInformation, error)
GetCurrentUser(bearerToken string, opts ...RequestOpt) (*discord.OAuth2User, error)
GetCurrentMember(bearerToken string, guildID snowflake.ID, opts ...RequestOpt) (*discord.Member, error)
GetCurrentUserGuilds(bearerToken string, before snowflake.ID, after snowflake.ID, limit int, opts ...RequestOpt) ([]discord.OAuth2Guild, error)
GetCurrentUserGuildsPage(bearerToken string, startID snowflake.ID, limit int, opts ...RequestOpt) Page[discord.OAuth2Guild]
GetCurrentUserGuilds(bearerToken string, before snowflake.ID, after snowflake.ID, limit int, withCounts bool, opts ...RequestOpt) ([]discord.OAuth2Guild, error)
GetCurrentUserGuildsPage(bearerToken string, startID snowflake.ID, limit int, withCounts bool, opts ...RequestOpt) Page[discord.OAuth2Guild]
GetCurrentUserConnections(bearerToken string, opts ...RequestOpt) ([]discord.Connection, error)

SetGuildCommandPermissions(bearerToken string, applicationID snowflake.ID, guildID snowflake.ID, commandID snowflake.ID, commandPermissions []discord.ApplicationCommandPermission, opts ...RequestOpt) (*discord.ApplicationCommandPermissions, error)
Expand Down Expand Up @@ -64,8 +64,10 @@ func (s *oAuth2Impl) GetCurrentMember(bearerToken string, guildID snowflake.ID,
return
}

func (s *oAuth2Impl) GetCurrentUserGuilds(bearerToken string, before snowflake.ID, after snowflake.ID, limit int, opts ...RequestOpt) (guilds []discord.OAuth2Guild, err error) {
queryParams := discord.QueryValues{}
func (s *oAuth2Impl) GetCurrentUserGuilds(bearerToken string, before snowflake.ID, after snowflake.ID, limit int, withCounts bool, opts ...RequestOpt) (guilds []discord.OAuth2Guild, err error) {
queryParams := discord.QueryValues{
"with_counts": withCounts,
}
if before != 0 {
queryParams["before"] = before
}
Expand All @@ -79,10 +81,10 @@ func (s *oAuth2Impl) GetCurrentUserGuilds(bearerToken string, before snowflake.I
return
}

func (s *oAuth2Impl) GetCurrentUserGuildsPage(bearerToken string, startID snowflake.ID, limit int, opts ...RequestOpt) Page[discord.OAuth2Guild] {
func (s *oAuth2Impl) GetCurrentUserGuildsPage(bearerToken string, startID snowflake.ID, limit int, withCounts bool, opts ...RequestOpt) Page[discord.OAuth2Guild] {
return Page[discord.OAuth2Guild]{
getItemsFunc: func(before snowflake.ID, after snowflake.ID) ([]discord.OAuth2Guild, error) {
return s.GetCurrentUserGuilds(bearerToken, before, after, limit, opts...)
return s.GetCurrentUserGuilds(bearerToken, before, after, limit, withCounts, opts...)
},
getIDFunc: func(guild discord.OAuth2Guild) snowflake.ID {
return guild.ID
Expand Down
8 changes: 5 additions & 3 deletions rest/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewUsers(client Client) Users {
type Users interface {
GetUser(userID snowflake.ID, opts ...RequestOpt) (*discord.User, error)
UpdateSelfUser(selfUserUpdate discord.SelfUserUpdate, opts ...RequestOpt) (*discord.OAuth2User, error)
GetGuilds(before int, after int, limit int, opts ...RequestOpt) ([]discord.OAuth2Guild, error)
GetGuilds(before int, after int, limit int, withCounts bool, opts ...RequestOpt) ([]discord.OAuth2Guild, error)
LeaveGuild(guildID snowflake.ID, opts ...RequestOpt) error
GetDMChannels(opts ...RequestOpt) ([]discord.Channel, error)
CreateDMChannel(userID snowflake.ID, opts ...RequestOpt) (*discord.DMChannel, error)
Expand All @@ -35,8 +35,10 @@ func (s *userImpl) UpdateSelfUser(updateSelfUser discord.SelfUserUpdate, opts ..
return
}

func (s *userImpl) GetGuilds(before int, after int, limit int, opts ...RequestOpt) (guilds []discord.OAuth2Guild, err error) {
queryParams := discord.QueryValues{}
func (s *userImpl) GetGuilds(before int, after int, limit int, withCounts bool, opts ...RequestOpt) (guilds []discord.OAuth2Guild, err error) {
queryParams := discord.QueryValues{
"with_counts": withCounts,
}
if before > 0 {
queryParams["before"] = before
}
Expand Down

0 comments on commit 836b4a9

Please sign in to comment.