adds EndpointGuildIconAnimated; adds guild.IconURL() helper (#658)

This commit is contained in:
Sebastian Winkler 2019-07-22 06:09:39 +02:00 committed by Chris Rhodes
parent d7c22e2791
commit 579121fe1a
2 changed files with 15 additions and 0 deletions

View file

@ -93,6 +93,7 @@ var (
EndpointGuildEmbed = func(gID string) string { return EndpointGuilds + gID + "/embed" }
EndpointGuildPrune = func(gID string) string { return EndpointGuilds + gID + "/prune" }
EndpointGuildIcon = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".png" }
EndpointGuildIconAnimated = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".gif" }
EndpointGuildSplash = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" }
EndpointGuildWebhooks = func(gID string) string { return EndpointGuilds + gID + "/webhooks" }
EndpointGuildAuditLogs = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" }

View file

@ -15,6 +15,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"
"sync"
"time"
@ -475,6 +476,19 @@ type Guild struct {
PremiumSubscriptionCount int `json:"premium_subscription_count"`
}
// IconURL returns a URL to the guild's icon.
func (g *Guild) IconURL() string {
if g.Icon == "" {
return ""
}
if strings.HasPrefix(g.Icon, "a_") {
return EndpointGuildIconAnimated(g.ID, g.Icon)
}
return EndpointGuildIcon(g.ID, g.Icon)
}
// A UserGuild holds a brief version of a Guild
type UserGuild struct {
ID string `json:"id"`