Discord: added Guild URL methods

This commit is contained in:
diamondburned (Forefront) 2020-02-06 16:51:29 -08:00
parent 78ea6f7d9c
commit 330020b6f2
1 changed files with 39 additions and 0 deletions

View File

@ -51,6 +51,45 @@ type Guild struct {
PreferredLocale string `json:"preferred_locale"`
}
// IconURL returns the URL to the guild icon. An empty string is removed if
// there's no icon.
func (g Guild) IconURL() string {
if g.Icon == "" {
return ""
}
base := "https://cdn.discordapp.com/icons/" +
g.ID.String() + "/" + g.Icon
if len(g.Icon) > 2 && g.Icon[:2] == "a_" {
return base + ".gif"
}
return base + ".png"
}
// BannerURL returns the URL to the banner, which is the image on top of the
// channels list.
func (g Guild) BannerURL() string {
if g.Banner == "" {
return ""
}
return "https://cdn.discordapp.com/banners/" +
g.ID.String() + "/" + g.Banner + ".png"
}
// SplashURL returns the URL to the guild splash, which is the invite page's
// background.
func (g Guild) SplashURL() string {
if g.Splash == "" {
return ""
}
return "https://cdn.discordapp.com/banners/" +
g.ID.String() + "/" + g.Splash + ".png"
}
type Role struct {
ID Snowflake `json:"id,string"`
Name string `json:"name"`