diff --git a/endpoints.go b/endpoints.go index d3fe034..6f86b67 100644 --- a/endpoints.go +++ b/endpoints.go @@ -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" } diff --git a/structs.go b/structs.go index 948682f..bb00368 100644 --- a/structs.go +++ b/structs.go @@ -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"`