user.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package discordgo
  2. import "strings"
  3. // UserFlags is the flags of "user" (see UserFlags* consts)
  4. // https://discord.com/developers/docs/resources/user#user-object-user-flags
  5. type UserFlags int
  6. // Valid UserFlags values
  7. const (
  8. UserFlagDiscordEmployee UserFlags = 1 << 0
  9. UserFlagDiscordPartner UserFlags = 1 << 1
  10. UserFlagHypeSquadEvents UserFlags = 1 << 2
  11. UserFlagBugHunterLevel1 UserFlags = 1 << 3
  12. UserFlagHouseBravery UserFlags = 1 << 6
  13. UserFlagHouseBrilliance UserFlags = 1 << 7
  14. UserFlagHouseBalance UserFlags = 1 << 8
  15. UserFlagEarlySupporter UserFlags = 1 << 9
  16. UserFlagTeamUser UserFlags = 1 << 10
  17. UserFlagSystem UserFlags = 1 << 12
  18. UserFlagBugHunterLevel2 UserFlags = 1 << 14
  19. UserFlagVerifiedBot UserFlags = 1 << 16
  20. UserFlagVerifiedBotDeveloper UserFlags = 1 << 17
  21. UserFlagDiscordCertifiedModerator UserFlags = 1 << 18
  22. )
  23. // A User stores all data for an individual Discord user.
  24. type User struct {
  25. // The ID of the user.
  26. ID string `json:"id"`
  27. // The email of the user. This is only present when
  28. // the application possesses the email scope for the user.
  29. Email string `json:"email"`
  30. // The user's username.
  31. Username string `json:"username"`
  32. // The hash of the user's avatar. Use Session.UserAvatar
  33. // to retrieve the avatar itself.
  34. Avatar string `json:"avatar"`
  35. // The user's chosen language option.
  36. Locale string `json:"locale"`
  37. // The discriminator of the user (4 numbers after name).
  38. Discriminator string `json:"discriminator"`
  39. // The token of the user. This is only present for
  40. // the user represented by the current session.
  41. Token string `json:"token"`
  42. // Whether the user's email is verified.
  43. Verified bool `json:"verified"`
  44. // Whether the user has multi-factor authentication enabled.
  45. MFAEnabled bool `json:"mfa_enabled"`
  46. // Whether the user is a bot.
  47. Bot bool `json:"bot"`
  48. // The public flags on a user's account.
  49. // This is a combination of bit masks; the presence of a certain flag can
  50. // be checked by performing a bitwise AND between this int and the flag.
  51. PublicFlags UserFlags `json:"public_flags"`
  52. // The type of Nitro subscription on a user's account.
  53. // Only available when the request is authorized via a Bearer token.
  54. PremiumType int `json:"premium_type"`
  55. // Whether the user is an Official Discord System user (part of the urgent message system).
  56. System bool `json:"system"`
  57. // The flags on a user's account.
  58. // Only available when the request is authorized via a Bearer token.
  59. Flags int `json:"flags"`
  60. }
  61. // String returns a unique identifier of the form username#discriminator
  62. func (u *User) String() string {
  63. return u.Username + "#" + u.Discriminator
  64. }
  65. // Mention return a string which mentions the user
  66. func (u *User) Mention() string {
  67. return "<@" + u.ID + ">"
  68. }
  69. // AvatarURL returns a URL to the user's avatar.
  70. // size: The size of the user's avatar as a power of two
  71. // if size is an empty string, no size parameter will
  72. // be added to the URL.
  73. func (u *User) AvatarURL(size string) string {
  74. var URL string
  75. if u.Avatar == "" {
  76. URL = EndpointDefaultUserAvatar(u.Discriminator)
  77. } else if strings.HasPrefix(u.Avatar, "a_") {
  78. URL = EndpointUserAvatarAnimated(u.ID, u.Avatar)
  79. } else {
  80. URL = EndpointUserAvatar(u.ID, u.Avatar)
  81. }
  82. if size != "" {
  83. return URL + "?size=" + size
  84. }
  85. return URL
  86. }