user.go 3.8 KB

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