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

Adding User Banners? #1093

Closed
lxi1400 opened this issue Feb 14, 2022 · 2 comments · Fixed by #1117
Closed

Adding User Banners? #1093

lxi1400 opened this issue Feb 14, 2022 · 2 comments · Fixed by #1117
Labels
feature Feature implementation

Comments

@lxi1400
Copy link

lxi1400 commented Feb 14, 2022

Hey there. Banners have been out for a while but it seems that discordgo still has 0 support for them. Is there any ETA to when this will be added?

@FedorLap2006 FedorLap2006 added the feature Feature implementation label Feb 15, 2022
@sentinelb51
Copy link
Contributor

Think it could be implemented if they add the following:

in endpoints.go:

EndpointUserBanner = func(uID, hash string) string { return EndpointCDNBanners + uID + "/" + hash + ".png" }
EndpointUserBannerAnimated = func(uID, hash string) string { return EndpointCDNBanners + uID + "/" + hash + ".gif" }

in user.go:

// The hash of the user's banner asset
Banner string `json:"banner,omitempty"`
// BannerURL returns a URL to the user's banner.
//    size:    The size of the user's banner as a power of two
//             if size is an empty string, no size parameter will
//             be added to the URL.
func (u *User) BannerURL(size string) string {
	var URL string

	if strings.HasPrefix(u.Banner, "a_") {
		URL = EndpointUserBannerAnimated(u.ID, u.Banner)
	} else {
		URL = EndpointUserBanner(u.ID, u.Banner)
	}

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

Tested in production and seems to work fine

@lxi1400
Copy link
Author

lxi1400 commented Feb 22, 2022

Think it could be implemented if they add the following:

in endpoints.go:

EndpointUserBanner = func(uID, hash string) string { return EndpointCDNBanners + uID + "/" + hash + ".png" }
EndpointUserBannerAnimated = func(uID, hash string) string { return EndpointCDNBanners + uID + "/" + hash + ".gif" }

in user.go:

// The hash of the user's banner asset
Banner string `json:"banner,omitempty"`
// BannerURL returns a URL to the user's banner.
//    size:    The size of the user's banner as a power of two
//             if size is an empty string, no size parameter will
//             be added to the URL.
func (u *User) BannerURL(size string) string {
 var URL string

 if strings.HasPrefix(u.Banner, "a_") {
 	URL = EndpointUserBannerAnimated(u.ID, u.Banner)
 } else {
 	URL = EndpointUserBanner(u.ID, u.Banner)
 }

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

Tested in production and seems to work fine

Only issue is that this doesn't return the accent color if a user has no banner set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature implementation
Projects
None yet
3 participants