2020-01-02 19:53:08 +00:00
|
|
|
package discord
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-15 20:07:27 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
2021-05-20 22:47:44 +00:00
|
|
|
"time"
|
2020-05-15 20:07:27 +00:00
|
|
|
)
|
2020-04-15 03:52:48 +00:00
|
|
|
|
2020-01-02 05:39:52 +00:00
|
|
|
type User struct {
|
2020-11-22 14:48:36 +00:00
|
|
|
ID UserID `json:"id"`
|
2020-07-21 20:27:59 +00:00
|
|
|
Username string `json:"username"`
|
2023-06-08 00:56:07 +00:00
|
|
|
Discriminator string `json:"discriminator"` // This is "0" if the user has migrated to the new username system.
|
2020-07-21 20:27:59 +00:00
|
|
|
Avatar Hash `json:"avatar"`
|
2023-06-08 00:56:07 +00:00
|
|
|
DisplayName string `json:"global_name"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
// These fields may be omitted
|
|
|
|
|
|
|
|
Bot bool `json:"bot,omitempty"`
|
|
|
|
MFA bool `json:"mfa_enabled,omitempty"`
|
|
|
|
|
2020-11-22 14:48:36 +00:00
|
|
|
Nitro UserNitro `json:"premium_type,omitempty"`
|
|
|
|
Flags UserFlags `json:"flags,omitempty"`
|
|
|
|
PublicFlags UserFlags `json:"public_flags,omitempty"`
|
|
|
|
|
2020-01-02 05:39:52 +00:00
|
|
|
DiscordSystem bool `json:"system,omitempty"`
|
|
|
|
EmailVerified bool `json:"verified,omitempty"`
|
|
|
|
|
|
|
|
Locale string `json:"locale,omitempty"`
|
|
|
|
Email string `json:"email,omitempty"`
|
2021-08-17 06:48:36 +00:00
|
|
|
|
|
|
|
Banner Hash `json:"banner,omitempty"`
|
|
|
|
Accent Color `json:"accent_color,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:47:44 +00:00
|
|
|
// CreatedAt returns a time object representing when the user was created.
|
|
|
|
func (u User) CreatedAt() time.Time {
|
|
|
|
return u.ID.Time()
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:17:58 +00:00
|
|
|
// Mention returns a mention of the user.
|
2020-01-24 05:45:47 +00:00
|
|
|
func (u User) Mention() string {
|
2020-09-24 18:43:20 +00:00
|
|
|
return u.ID.Mention()
|
2020-01-24 05:45:47 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:49:56 +00:00
|
|
|
// Tag returns a tag of the user.
|
|
|
|
func (u User) Tag() string {
|
2023-06-08 00:56:07 +00:00
|
|
|
if u.Discriminator == "0" {
|
|
|
|
return u.Username
|
|
|
|
}
|
|
|
|
|
2021-05-20 22:49:56 +00:00
|
|
|
return u.Username + "#" + u.Discriminator
|
|
|
|
}
|
|
|
|
|
2020-05-15 20:07:27 +00:00
|
|
|
// AvatarURL returns the URL of the Avatar Image. It automatically detects a
|
|
|
|
// suitable type.
|
2020-01-24 06:00:41 +00:00
|
|
|
func (u User) AvatarURL() string {
|
2020-05-15 20:07:27 +00:00
|
|
|
return u.AvatarURLWithType(AutoImage)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AvatarURLWithType returns the URL of the Avatar Image using the passed type.
|
|
|
|
// If the user has no Avatar, his default avatar will be returned. This
|
|
|
|
// requires ImageType Auto or PNG
|
|
|
|
//
|
|
|
|
// Supported Image Types: PNG, JPEG, WebP, GIF (read above for caveat)
|
|
|
|
func (u User) AvatarURLWithType(t ImageType) string {
|
2020-01-24 06:00:41 +00:00
|
|
|
if u.Avatar == "" {
|
2020-05-15 20:07:27 +00:00
|
|
|
if t != PNGImage && t != AutoImage {
|
|
|
|
return ""
|
|
|
|
}
|
2020-01-24 06:00:41 +00:00
|
|
|
|
2023-06-08 00:56:07 +00:00
|
|
|
var picNo string
|
|
|
|
if u.Discriminator != "0" {
|
|
|
|
disc, err := strconv.Atoi(u.Discriminator)
|
|
|
|
if err != nil { // this should never happen
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
picNo = strconv.Itoa(disc % 5)
|
|
|
|
} else {
|
|
|
|
picNo = strconv.FormatUint(uint64(u.ID>>22)%5, 10)
|
2020-05-15 20:07:27 +00:00
|
|
|
}
|
2020-01-24 06:00:41 +00:00
|
|
|
|
2020-05-22 21:38:53 +00:00
|
|
|
return "https://cdn.discordapp.com/embed/avatars/" + picNo + ".png"
|
2020-01-24 06:00:41 +00:00
|
|
|
}
|
2020-05-15 20:07:27 +00:00
|
|
|
|
|
|
|
return "https://cdn.discordapp.com/avatars/" + u.ID.String() + "/" + t.format(u.Avatar)
|
2020-01-24 06:00:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 06:48:36 +00:00
|
|
|
// BannerURL returns the URL of the Banner Image. It automatically detects a
|
|
|
|
// suitable type.
|
|
|
|
func (u User) BannerURL() string {
|
|
|
|
return u.BannerURLWithType(AutoImage)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BannerURLWithType returns the URL of the Banner Image using the passed type.
|
|
|
|
// If the user has no Banner, an empty string will be returned.
|
|
|
|
func (u User) BannerURLWithType(t ImageType) string {
|
|
|
|
if u.Banner == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return "https://cdn.discordapp.com/banners/" + u.ID.String() + "/" + t.format(u.Banner)
|
|
|
|
}
|
|
|
|
|
2020-05-05 03:22:06 +00:00
|
|
|
type UserFlags uint32
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-06 01:08:40 +00:00
|
|
|
const NoFlag UserFlags = 0
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-06 01:08:40 +00:00
|
|
|
const (
|
2020-07-29 23:29:01 +00:00
|
|
|
Employee UserFlags = 1 << iota
|
|
|
|
Partner
|
2020-01-02 05:39:52 +00:00
|
|
|
HypeSquadEvents
|
2020-05-05 03:22:06 +00:00
|
|
|
BugHunterLvl1
|
2020-05-05 03:36:39 +00:00
|
|
|
_
|
|
|
|
_
|
2020-01-02 05:39:52 +00:00
|
|
|
HouseBravery
|
|
|
|
HouseBrilliance
|
|
|
|
HouseBalance
|
|
|
|
EarlySupporter
|
|
|
|
TeamUser
|
2020-05-05 03:36:39 +00:00
|
|
|
_
|
2020-01-02 05:39:52 +00:00
|
|
|
System
|
2020-05-05 03:36:39 +00:00
|
|
|
_
|
2020-05-05 03:22:06 +00:00
|
|
|
BugHunterLvl2
|
2020-05-05 03:36:39 +00:00
|
|
|
_
|
2020-05-05 03:22:06 +00:00
|
|
|
VerifiedBot
|
|
|
|
VerifiedBotDeveloper
|
2021-05-20 13:44:11 +00:00
|
|
|
CertifiedModerator
|
2022-04-17 09:47:48 +00:00
|
|
|
LikelySpammer // undocumented
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
type UserNitro uint8
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
const (
|
2020-01-04 04:19:24 +00:00
|
|
|
NoUserNitro UserNitro = iota
|
2020-01-02 05:39:52 +00:00
|
|
|
NitroClassic
|
|
|
|
NitroFull
|
2023-01-02 07:46:14 +00:00
|
|
|
NitroBasic
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
2020-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
type Connection struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Type Service `json:"type"`
|
2020-01-07 06:45:29 +00:00
|
|
|
|
|
|
|
Revoked bool `json:"revoked"`
|
|
|
|
Verified bool `json:"verified"`
|
|
|
|
FriendSync bool `json:"friend_sync"`
|
|
|
|
ShowActivity bool `json:"show_activity"`
|
|
|
|
|
|
|
|
Visibility ConnectionVisibility `json:"visibility"`
|
|
|
|
|
|
|
|
// Only partial
|
2020-01-15 07:34:18 +00:00
|
|
|
Integrations []Integration `json:"integrations"`
|
2020-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ConnectionVisibility uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
ConnectionNotVisible ConnectionVisibility = iota
|
|
|
|
ConnectionVisibleEveryone
|
|
|
|
)
|
2020-01-18 21:04:12 +00:00
|
|
|
|
|
|
|
type Activity struct {
|
2020-11-22 14:48:36 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
URL URL `json:"url,omitempty"`
|
|
|
|
|
2020-01-18 21:04:12 +00:00
|
|
|
Type ActivityType `json:"type"`
|
|
|
|
|
|
|
|
// User only
|
|
|
|
|
2020-11-22 14:48:36 +00:00
|
|
|
Instance bool `json:"instance,omitempty"`
|
|
|
|
Flags ActivityFlags `json:"flags,omitempty"`
|
|
|
|
|
2021-06-06 14:19:19 +00:00
|
|
|
CreatedAt UnixTimestamp `json:"created_at,omitempty"`
|
|
|
|
Timestamps *ActivityTimestamps `json:"timestamps,omitempty"`
|
2020-01-18 21:04:12 +00:00
|
|
|
|
2021-01-27 18:11:17 +00:00
|
|
|
AppID AppID `json:"application_id,omitempty"`
|
|
|
|
Details string `json:"details,omitempty"`
|
|
|
|
State string `json:"state,omitempty"` // party status
|
|
|
|
Emoji *Emoji `json:"emoji,omitempty"`
|
2020-01-18 21:04:12 +00:00
|
|
|
|
2020-03-31 05:46:34 +00:00
|
|
|
Party *ActivityParty `json:"party,omitempty"`
|
|
|
|
Assets *ActivityAssets `json:"assets,omitempty"`
|
|
|
|
Secrets *ActivitySecrets `json:"secrets,omitempty"`
|
2020-01-18 21:04:12 +00:00
|
|
|
|
2020-02-23 17:56:16 +00:00
|
|
|
// Undocumented fields
|
|
|
|
SyncID string `json:"sync_id,omitempty"`
|
|
|
|
SessionID string `json:"session_id,omitempty"`
|
2020-01-18 21:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ActivityType uint8
|
|
|
|
|
|
|
|
const (
|
2021-11-16 22:34:37 +00:00
|
|
|
GameActivity ActivityType = iota // Playing $name
|
|
|
|
StreamingActivity // Streaming $details
|
|
|
|
ListeningActivity // Listening to $name
|
|
|
|
WatchingActivity // Watching $name
|
|
|
|
CustomActivity // $emoji $state
|
|
|
|
CompetingActivity // Competing in $name
|
2020-01-18 21:04:12 +00:00
|
|
|
)
|
|
|
|
|
2020-05-05 06:13:15 +00:00
|
|
|
type ActivityFlags uint32
|
2020-01-18 21:04:12 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
InstanceActivity ActivityFlags = 1 << iota
|
|
|
|
JoinActivity
|
|
|
|
SpectateActivity
|
|
|
|
JoinRequestActivity
|
|
|
|
SyncActivity
|
|
|
|
PlayActivity
|
|
|
|
)
|
2020-03-31 05:00:28 +00:00
|
|
|
|
2021-06-06 14:19:19 +00:00
|
|
|
type ActivityTimestamps struct {
|
2020-03-31 05:46:34 +00:00
|
|
|
Start UnixMsTimestamp `json:"start,omitempty"`
|
|
|
|
End UnixMsTimestamp `json:"end,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-03-31 05:00:28 +00:00
|
|
|
type ActivityParty struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Size [2]int `json:"size,omitempty"` // [ current, max ]
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActivityAssets struct {
|
|
|
|
LargeImage string `json:"large_image,omitempty"` // id
|
|
|
|
LargeText string `json:"large_text,omitempty"`
|
|
|
|
SmallImage string `json:"small_image,omitempty"` // id
|
|
|
|
SmallText string `json:"small_text,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActivitySecrets struct {
|
|
|
|
Join string `json:"join,omitempty"`
|
|
|
|
Spectate string `json:"spectate,omitempty"`
|
|
|
|
Match string `json:"match,omitempty"`
|
|
|
|
}
|
2020-07-15 01:01:24 +00:00
|
|
|
|
|
|
|
// A Relationship between the logged in user and the user in the struct. This
|
|
|
|
// struct is undocumented.
|
|
|
|
type Relationship struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
UserID UserID `json:"id"`
|
2020-07-15 01:01:24 +00:00
|
|
|
User User `json:"user"`
|
|
|
|
Type RelationshipType `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// RelationshipType is an enum for a relationship.
|
|
|
|
type RelationshipType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
_ RelationshipType = iota
|
|
|
|
FriendRelationship
|
|
|
|
BlockedRelationship
|
|
|
|
IncomingFriendRequest
|
|
|
|
SentFriendRequest
|
|
|
|
)
|