user.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package discordgo
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // A User stores all data for an individual Discord user.
  7. type User struct {
  8. ID string `json:"id"`
  9. Email string `json:"email"`
  10. Username string `json:"username"`
  11. Avatar string `json:"avatar"`
  12. Discriminator string `json:"discriminator"`
  13. Token string `json:"token"`
  14. Verified bool `json:"verified"`
  15. MFAEnabled bool `json:"mfa_enabled"`
  16. Bot bool `json:"bot"`
  17. }
  18. // String returns a unique identifier of the form username#discriminator
  19. func (u *User) String() string {
  20. return fmt.Sprintf("%s#%s", u.Username, u.Discriminator)
  21. }
  22. // Mention return a string which mentions the user
  23. func (u *User) Mention() string {
  24. return fmt.Sprintf("<@%s>", u.ID)
  25. }
  26. // AvatarURL returns a URL to the user's avatar.
  27. // size: The size of the user's avatar as a power of two
  28. // if size is an empty string, no size parameter will
  29. // be added to the URL.
  30. func (u *User) AvatarURL(size string) string {
  31. var URL string
  32. if strings.HasPrefix(u.Avatar, "a_") {
  33. URL = EndpointUserAvatarAnimated(u.ID, u.Avatar)
  34. } else {
  35. URL = EndpointUserAvatar(u.ID, u.Avatar)
  36. }
  37. if size != "" {
  38. return URL + "?size=" + size
  39. }
  40. return URL
  41. }