mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-02-11 05:52:58 +00:00
discord: Support the new username system (#393)
* add support for the new username system * rename User.GlobalName to DisplayName
This commit is contained in:
parent
73986699b7
commit
13a6bf10cc
|
@ -8,8 +8,9 @@ import (
|
||||||
type User struct {
|
type User struct {
|
||||||
ID UserID `json:"id"`
|
ID UserID `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Discriminator string `json:"discriminator"`
|
Discriminator string `json:"discriminator"` // This is "0" if the user has migrated to the new username system.
|
||||||
Avatar Hash `json:"avatar"`
|
Avatar Hash `json:"avatar"`
|
||||||
|
DisplayName string `json:"global_name"`
|
||||||
|
|
||||||
// These fields may be omitted
|
// These fields may be omitted
|
||||||
|
|
||||||
|
@ -42,6 +43,10 @@ func (u User) Mention() string {
|
||||||
|
|
||||||
// Tag returns a tag of the user.
|
// Tag returns a tag of the user.
|
||||||
func (u User) Tag() string {
|
func (u User) Tag() string {
|
||||||
|
if u.Discriminator == "0" {
|
||||||
|
return u.Username
|
||||||
|
}
|
||||||
|
|
||||||
return u.Username + "#" + u.Discriminator
|
return u.Username + "#" + u.Discriminator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +67,16 @@ func (u User) AvatarURLWithType(t ImageType) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var picNo string
|
||||||
|
if u.Discriminator != "0" {
|
||||||
disc, err := strconv.Atoi(u.Discriminator)
|
disc, err := strconv.Atoi(u.Discriminator)
|
||||||
if err != nil { // this should never happen
|
if err != nil { // this should never happen
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
picNo := strconv.Itoa(disc % 5)
|
picNo = strconv.Itoa(disc % 5)
|
||||||
|
} else {
|
||||||
|
picNo = strconv.FormatUint(uint64(u.ID>>22)%5, 10)
|
||||||
|
}
|
||||||
|
|
||||||
return "https://cdn.discordapp.com/embed/avatars/" + picNo + ".png"
|
return "https://cdn.discordapp.com/embed/avatars/" + picNo + ".png"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue