1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-10 23:45:42 +00:00

Discord: Added a fallback avatar URL

This commit is contained in:
diamondburned (Forefront) 2020-04-14 20:52:48 -07:00
parent d1f30b483d
commit 0d81f9176a

View file

@ -2,6 +2,10 @@ package discord
import "strings" import "strings"
// DefaultAvatarURL is the link to the default green avatar on Discord. It's
// returned from AvatarURL() if the user doesn't have an avatar.
var DefaultAvatarURL = "https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"
type User struct { type User struct {
ID Snowflake `json:"id,string"` ID Snowflake `json:"id,string"`
Username string `json:"username"` Username string `json:"username"`
@ -28,12 +32,11 @@ func (u User) Mention() string {
} }
func (u User) AvatarURL() string { func (u User) AvatarURL() string {
base := "https://cdn.discordapp.com"
if u.Avatar == "" { if u.Avatar == "" {
return "" return DefaultAvatarURL
} }
base := "https://cdn.discordapp.com"
base += "/avatars/" + u.ID.String() + "/" + u.Avatar base += "/avatars/" + u.ID.String() + "/" + u.Avatar
if strings.HasPrefix(u.Avatar, "a_") { if strings.HasPrefix(u.Avatar, "a_") {