Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Guild Member Cover & Accent Color support #1117

Merged
merged 9 commits into from Mar 2, 2022
6 changes: 6 additions & 0 deletions endpoints.go
Expand Up @@ -54,6 +54,12 @@ var (
uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator)
return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png"
}
EndpointUserBanner = func(uID, cID string) string {
return EndpointCDNBanners + uID + "/" + cID + ".png"
}
EndpointUserBannerAnimated = func(uID, cID string) string {
return EndpointCDNBanners + uID + "/" + cID + ".gif"
}

EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
Expand Down
13 changes: 13 additions & 0 deletions user.go
Expand Up @@ -54,6 +54,12 @@ type User struct {
// Whether the user has multi-factor authentication enabled.
MFAEnabled bool `json:"mfa_enabled"`

// The hash of the user's banner image.
Banner string `json:"banner"`

// User's banner color, encoded as an integer representation of hexadecimal color code
AccentColor int `json:"accent_color"`

// Whether the user is a bot.
Bot bool `json:"bot"`

Expand Down Expand Up @@ -92,3 +98,10 @@ func (u *User) AvatarURL(size string) string {
return avatarURL(u.Avatar, EndpointDefaultUserAvatar(u.Discriminator),
EndpointUserAvatar(u.ID, u.Avatar), EndpointUserAvatarAnimated(u.ID, u.Avatar), size)
}

// BannerURL returns the URL of the users's banner image.
// size: The size of the desired banner image as a power of two
// Image size can be any power of two between 16 and 4096.
func (u *User) BannerURL(size string) string {
return bannerURL(u.Banner, EndpointUserBanner(u.ID, u.Banner), EndpointUserBannerAnimated(u.ID, u.Banner), size)
}
16 changes: 16 additions & 0 deletions util.go
Expand Up @@ -92,3 +92,19 @@ func avatarURL(avatarHash, defaultAvatarURL, staticAvatarURL, animatedAvatarURL,
}
return URL
}

func bannerURL(bannerHash, staticBannerURL, animatedBannerURL, size string) string {
var URL string
if bannerHash == "" {
return ""
} else if strings.HasPrefix(bannerHash, "a_") {
URL = animatedBannerURL
} else {
URL = staticBannerURL
}

if size != "" {
return URL + "?size=" + size
}
return URL
}