From 91dc41e388a0099dee76a828dfda6f37e96f16b0 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Wed, 16 Dec 2020 12:26:25 -0800 Subject: [PATCH] API: Expose Max fetch constants This commit exposes the Max fetch constants to allow package users to externally reimplement any part of the API abstractions without having to redeclare more constants. --- api/guild.go | 16 ++++++++-------- api/member.go | 8 ++++---- api/message_reaction.go | 14 +++++++------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/guild.go b/api/guild.go index 7ba7bcf..94b6d9d 100644 --- a/api/guild.go +++ b/api/guild.go @@ -9,9 +9,9 @@ import ( "github.com/diamondburned/arikawa/v2/utils/json/option" ) -// maxGuildFetchLimit is the limit of max guilds per request, as imposed by +// MaxGuildFetchLimit is the limit of max guilds per request, as imposed by // Discord. -const maxGuildFetchLimit = 100 +const MaxGuildFetchLimit = 100 var EndpointGuilds = Endpoint + "guilds/" @@ -139,7 +139,7 @@ func (c *Client) Guilds(limit uint) ([]discord.Guild, error) { func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Guild, error) { guilds := make([]discord.Guild, 0, limit) - fetch := uint(maxGuildFetchLimit) + fetch := uint(MaxGuildFetchLimit) unlimited := limit == 0 @@ -147,7 +147,7 @@ func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Gui if limit > 0 { // Only fetch as much as we need. Since limit gradually decreases, // we only need to fetch min(fetch, limit). - fetch = uint(min(maxGuildFetchLimit, int(limit))) + fetch = uint(min(MaxGuildFetchLimit, int(limit))) limit -= fetch } @@ -157,7 +157,7 @@ func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Gui } guilds = append(g, guilds...) - if len(g) < maxGuildFetchLimit { + if len(g) < MaxGuildFetchLimit { break } @@ -184,7 +184,7 @@ func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Gui func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild, error) { guilds := make([]discord.Guild, 0, limit) - fetch := uint(maxGuildFetchLimit) + fetch := uint(MaxGuildFetchLimit) unlimited := limit == 0 @@ -192,7 +192,7 @@ func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild if limit > 0 { // Only fetch as much as we need. Since limit gradually decreases, // we only need to fetch min(fetch, limit). - fetch = uint(min(maxGuildFetchLimit, int(limit))) + fetch = uint(min(MaxGuildFetchLimit, int(limit))) limit -= fetch } @@ -202,7 +202,7 @@ func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild } guilds = append(guilds, g...) - if len(g) < maxGuildFetchLimit { + if len(g) < MaxGuildFetchLimit { break } diff --git a/api/member.go b/api/member.go index 431d685..0182e7b 100644 --- a/api/member.go +++ b/api/member.go @@ -6,7 +6,7 @@ import ( "github.com/diamondburned/arikawa/v2/utils/json/option" ) -const maxMemberFetchLimit = 1000 +const MaxMemberFetchLimit = 1000 // Member returns a guild member object for the specified user. func (c *Client) Member(guildID discord.GuildID, userID discord.UserID) (*discord.Member, error) { @@ -39,7 +39,7 @@ func (c *Client) MembersAfter( mems := make([]discord.Member, 0, limit) - fetch := uint(maxMemberFetchLimit) + fetch := uint(MaxMemberFetchLimit) unlimited := limit == 0 @@ -47,7 +47,7 @@ func (c *Client) MembersAfter( // Only fetch as much as we need. Since limit gradually decreases, // we only need to fetch min(fetch, limit). if limit > 0 { - fetch = uint(min(maxMemberFetchLimit, int(limit))) + fetch = uint(min(MaxMemberFetchLimit, int(limit))) limit -= fetch } @@ -58,7 +58,7 @@ func (c *Client) MembersAfter( mems = append(mems, m...) // There aren't any to fetch, even if this is less than limit. - if len(m) < maxMemberFetchLimit { + if len(m) < MaxMemberFetchLimit { break } diff --git a/api/message_reaction.go b/api/message_reaction.go index 3b567c2..f902e20 100644 --- a/api/message_reaction.go +++ b/api/message_reaction.go @@ -5,7 +5,7 @@ import ( "github.com/diamondburned/arikawa/v2/utils/httputil" ) -const maxMessageReactionFetchLimit = 100 +const MaxMessageReactionFetchLimit = 100 // React creates a reaction for the message. // @@ -66,7 +66,7 @@ func (c *Client) ReactionsBefore( users := make([]discord.User, 0, limit) - fetch := uint(maxMessageReactionFetchLimit) + fetch := uint(MaxMessageReactionFetchLimit) unlimited := limit == 0 @@ -74,7 +74,7 @@ func (c *Client) ReactionsBefore( if limit > 0 { // Only fetch as much as we need. Since limit gradually decreases, // we only need to fetch min(fetch, limit). - fetch = uint(min(maxMessageReactionFetchLimit, int(limit))) + fetch = uint(min(MaxMessageReactionFetchLimit, int(limit))) limit -= fetch } @@ -84,7 +84,7 @@ func (c *Client) ReactionsBefore( } users = append(r, users...) - if len(r) < maxMessageReactionFetchLimit { + if len(r) < MaxMessageReactionFetchLimit { break } @@ -114,7 +114,7 @@ func (c *Client) ReactionsAfter( users := make([]discord.User, 0, limit) - fetch := uint(maxMessageReactionFetchLimit) + fetch := uint(MaxMessageReactionFetchLimit) unlimited := limit == 0 @@ -122,7 +122,7 @@ func (c *Client) ReactionsAfter( if limit > 0 { // Only fetch as much as we need. Since limit gradually decreases, // we only need to fetch min(fetch, limit). - fetch = uint(min(maxMessageReactionFetchLimit, int(limit))) + fetch = uint(min(MaxMessageReactionFetchLimit, int(limit))) limit -= fetch } @@ -132,7 +132,7 @@ func (c *Client) ReactionsAfter( } users = append(users, r...) - if len(r) < maxMessageReactionFetchLimit { + if len(r) < MaxMessageReactionFetchLimit { break }