1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-03-22 09:59:37 +00:00

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.
This commit is contained in:
diamondburned 2020-12-16 12:26:25 -08:00
parent 86756dfbaa
commit 91dc41e388
3 changed files with 19 additions and 19 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}