user.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // Whether the user is a bot.
  46. Bot bool `json:"bot"`
  47. // The public flags on a user's account.
  48. // This is a combination of bit masks; the presence of a certain flag can
  49. // be checked by performing a bitwise AND between this int and the flag.
  50. PublicFlags UserFlags `json:"public_flags"`
  51. // The type of Nitro subscription on a user's account.
  52. // Only available when the request is authorized via a Bearer token.
  53. PremiumType int `json:"premium_type"`
  54. // Whether the user is an Official Discord System user (part of the urgent message system).
  55. System bool `json:"system"`
  56. // The flags on a user's account.
  57. // Only available when the request is authorized via a Bearer token.
  58. Flags int `json:"flags"`
  59. }
  60. // String returns a unique identifier of the form username#discriminator
  61. func (u *User) String() string {
  62. return u.Username + "#" + u.Discriminator
  63. }
  64. // Mention return a string which mentions the user
  65. func (u *User) Mention() string {
  66. return "<@" + u.ID + ">"
  67. }
  68. // AvatarURL returns a URL to the user's avatar.
  69. // size: The size of the user's avatar as a power of two
  70. // if size is an empty string, no size parameter will
  71. // be added to the URL.
  72. func (u *User) AvatarURL(size string) string {
  73. return avatarURL(u.Avatar, EndpointDefaultUserAvatar(u.Discriminator),
  74. EndpointUserAvatar(u.ID, u.Avatar), EndpointUserAvatarAnimated(u.ID, u.Avatar), size)
  75. }