API: Added GuildWithCount
This commit is contained in:
parent
ea27e7c88d
commit
0f38294048
15
api/guild.go
15
api/guild.go
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"io"
|
||||
"net/url"
|
||||
|
||||
"github.com/diamondburned/arikawa/discord" // for clarity
|
||||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
|
@ -40,6 +41,20 @@ func (c *Client) Guild(id discord.Snowflake) (*discord.Guild, error) {
|
|||
return g, c.RequestJSON(&g, "GET", EndpointGuilds+id.String())
|
||||
}
|
||||
|
||||
// GuildWithCount will also return ApproximateMembers and ApproximatePresences
|
||||
// for the guild.
|
||||
func (c *Client) GuildWithCount(id discord.Snowflake) (*discord.Guild, error) {
|
||||
var g *discord.Guild
|
||||
|
||||
return g, c.RequestJSON(
|
||||
&g, "GET",
|
||||
EndpointGuilds+id.String(),
|
||||
httputil.WithSchema(c, url.Values{
|
||||
"with_counts": {"true"},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
// Guilds returns all guilds, automatically paginating. Be careful, as this
|
||||
// method may abuse the API by requesting thousands or millions of guilds. For
|
||||
// lower-level access, usee GuildsRange. Guilds returned have some fields
|
||||
|
|
|
@ -49,6 +49,10 @@ type Guild struct {
|
|||
|
||||
// Defaults to en-US, only set if guild has DISCOVERABLE
|
||||
PreferredLocale string `json:"preferred_locale"`
|
||||
|
||||
// Only presented if WithCounts is true.
|
||||
ApproximateMembers uint64 `json:"approximate_member_count,omitempty"`
|
||||
ApproximatePresences uint64 `json:"approximate_presence_count,omitempty"`
|
||||
}
|
||||
|
||||
// IconURL returns the URL to the guild icon. An empty string is removed if
|
||||
|
|
|
@ -3,6 +3,7 @@ package httputil
|
|||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/diamondburned/arikawa/utils/httputil/httpdriver"
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
|
@ -50,9 +51,16 @@ func WithContentType(ctype string) RequestOption {
|
|||
|
||||
func WithSchema(schema SchemaEncoder, v interface{}) RequestOption {
|
||||
return func(r httpdriver.Request) error {
|
||||
params, err := schema.Encode(v)
|
||||
if err != nil {
|
||||
return err
|
||||
var params url.Values
|
||||
|
||||
if v, ok := v.(url.Values); ok {
|
||||
params = v
|
||||
} else {
|
||||
v, err := schema.Encode(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params = v
|
||||
}
|
||||
|
||||
r.AddQuery(params)
|
||||
|
|
Loading…
Reference in New Issue