Add size parameters to IconURL and BannerURL (#1301)
* Add missing parameters/structs Adds guild icon size parameter, guild banner size parameter, missing ClientStatus struct * Add missing endpoint for animated banners * feat: revert ClientStatus changes Revert addition of ClientStatus since another PR was already merged with it. * feat: add documentation for size parameter * refactor: move icon url logic into separate func Move logic for icon URLs in various functions into a single iconURL function. Similar to banner and avatar functions. Co-authored-by: Fedor Lapshin <fe.lap.prog@gmail.com>
This commit is contained in:
parent
345a9d6466
commit
cb59c78e32
3 changed files with 33 additions and 29 deletions
|
@ -97,6 +97,7 @@ var (
|
||||||
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
|
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
|
||||||
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
|
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
|
||||||
EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }
|
EndpointGuildBanner = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }
|
||||||
|
EndpointGuildBannerAnimated = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".gif" }
|
||||||
EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" }
|
EndpointGuildStickers = func(gID string) string { return EndpointGuilds + gID + "/stickers" }
|
||||||
EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }
|
EndpointGuildSticker = func(gID, sID string) string { return EndpointGuilds + gID + "/stickers/" + sID }
|
||||||
EndpointStageInstance = func(cID string) string { return EndpointStageInstances + "/" + cID }
|
EndpointStageInstance = func(cID string) string { return EndpointStageInstances + "/" + cID }
|
||||||
|
|
45
structs.go
45
structs.go
|
@ -17,7 +17,6 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -917,16 +916,8 @@ type GuildPreview struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IconURL returns a URL to the guild's icon.
|
// IconURL returns a URL to the guild's icon.
|
||||||
func (g *GuildPreview) IconURL() string {
|
func (g *GuildPreview) IconURL(size string) string {
|
||||||
if g.Icon == "" {
|
return iconURL(g.Icon, EndpointGuildIcon(g.ID, g.Icon), EndpointGuildIconAnimated(g.ID, g.Icon), size)
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(g.Icon, "a_") {
|
|
||||||
return EndpointGuildIconAnimated(g.ID, g.Icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
return EndpointGuildIcon(g.ID, g.Icon)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GuildScheduledEvent is a representation of a scheduled event in a guild. Only for retrieval of the data.
|
// GuildScheduledEvent is a representation of a scheduled event in a guild. Only for retrieval of the data.
|
||||||
|
@ -1139,24 +1130,19 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// IconURL returns a URL to the guild's icon.
|
// IconURL returns a URL to the guild's icon.
|
||||||
func (g *Guild) IconURL() string {
|
//
|
||||||
if g.Icon == "" {
|
// size: The size of the desired icon image as a power of two
|
||||||
return ""
|
// Image size can be any power of two between 16 and 4096.
|
||||||
}
|
func (g *Guild) IconURL(size string) string {
|
||||||
|
return iconURL(g.Icon, EndpointGuildIcon(g.ID, g.Icon), EndpointGuildIconAnimated(g.ID, g.Icon), size)
|
||||||
if strings.HasPrefix(g.Icon, "a_") {
|
|
||||||
return EndpointGuildIconAnimated(g.ID, g.Icon)
|
|
||||||
}
|
|
||||||
|
|
||||||
return EndpointGuildIcon(g.ID, g.Icon)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BannerURL returns a URL to the guild's banner.
|
// BannerURL returns a URL to the guild's banner.
|
||||||
func (g *Guild) BannerURL() string {
|
//
|
||||||
if g.Banner == "" {
|
// size: The size of the desired banner image as a power of two
|
||||||
return ""
|
// Image size can be any power of two between 16 and 4096.
|
||||||
}
|
func (g *Guild) BannerURL(size string) string {
|
||||||
return EndpointGuildBanner(g.ID, g.Banner)
|
return bannerURL(g.Banner, EndpointGuildBanner(g.ID, g.Banner), EndpointGuildBannerAnimated(g.ID, g.Banner), size)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A UserGuild holds a brief version of a Guild
|
// A UserGuild holds a brief version of a Guild
|
||||||
|
@ -1387,9 +1373,10 @@ func (m *Member) Mention() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AvatarURL returns the URL of the member's avatar
|
// AvatarURL returns the URL of the member's avatar
|
||||||
// size: The size of the user's avatar as a power of two
|
//
|
||||||
// if size is an empty string, no size parameter will
|
// size: The size of the user's avatar as a power of two
|
||||||
// be added to the URL.
|
// if size is an empty string, no size parameter will
|
||||||
|
// be added to the URL.
|
||||||
func (m *Member) AvatarURL(size string) string {
|
func (m *Member) AvatarURL(size string) string {
|
||||||
if m.Avatar == "" {
|
if m.Avatar == "" {
|
||||||
return m.User.AvatarURL(size)
|
return m.User.AvatarURL(size)
|
||||||
|
|
16
util.go
16
util.go
|
@ -107,3 +107,19 @@ func bannerURL(bannerHash, staticBannerURL, animatedBannerURL, size string) stri
|
||||||
}
|
}
|
||||||
return URL
|
return URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func iconURL(iconHash, staticIconURL, animatedIconURL, size string) string {
|
||||||
|
var URL string
|
||||||
|
if iconHash == "" {
|
||||||
|
return ""
|
||||||
|
} else if strings.HasPrefix(iconHash, "a_") {
|
||||||
|
URL = animatedIconURL
|
||||||
|
} else {
|
||||||
|
URL = staticIconURL
|
||||||
|
}
|
||||||
|
|
||||||
|
if size != "" {
|
||||||
|
return URL + "?size=" + size
|
||||||
|
}
|
||||||
|
return URL
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue