1
|
|
|
# Copyright Pincer 2021-Present
|
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root.
|
3
|
|
|
|
4
|
|
|
from __future__ import annotations
|
5
|
|
|
|
6
|
|
|
from dataclasses import dataclass
|
7
|
|
|
from enum import IntEnum
|
8
|
|
|
from typing import Optional, TYPE_CHECKING
|
9
|
|
|
|
10
|
|
|
from ...core.http import HTTPClient
|
11
|
|
|
from ...utils.api_object import APIObject
|
12
|
|
|
from ...utils.conversion import convert
|
13
|
|
|
from ...utils.snowflake import Snowflake
|
14
|
|
|
from ...utils.types import MISSING
|
15
|
|
|
|
16
|
|
|
if TYPE_CHECKING:
|
17
|
|
|
from ... import Client
|
18
|
|
|
from ...utils import APINullable
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class PremiumTypes(IntEnum):
|
22
|
|
|
"""
|
23
|
|
|
The type of Discord premium a user has.
|
24
|
|
|
"""
|
25
|
|
|
NONE = 0
|
26
|
|
|
NITRO_CLASSIC = 1
|
27
|
|
|
NITRO = 2
|
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class VisibilityType(IntEnum):
|
31
|
|
|
"""
|
32
|
|
|
The type of a connection visibility.
|
33
|
|
|
"""
|
34
|
|
|
NONE = 0
|
35
|
|
|
EVERYONE = 1
|
36
|
|
|
|
37
|
|
|
|
38
|
|
|
@dataclass
|
|
|
|
|
39
|
|
|
class User(APIObject):
|
40
|
|
|
"""
|
41
|
|
|
Represents a Discord user. This can be a bot account or a
|
42
|
|
|
human account.
|
43
|
|
|
|
44
|
|
|
:param _client:
|
45
|
|
|
reference to the Client
|
46
|
|
|
|
47
|
|
|
:param _http:
|
48
|
|
|
reference to the HTTPClient
|
49
|
|
|
|
50
|
|
|
:param avatar:
|
51
|
|
|
the user's avatar hash
|
52
|
|
|
|
53
|
|
|
:param discriminator:
|
54
|
|
|
the user's 4-digit discord-tag
|
55
|
|
|
|
56
|
|
|
:param flags:
|
57
|
|
|
the flags on a user's account
|
58
|
|
|
|
59
|
|
|
:param id:
|
60
|
|
|
the user's id
|
61
|
|
|
|
62
|
|
|
:param username:
|
63
|
|
|
the user's username, not unique across the platform
|
64
|
|
|
|
65
|
|
|
:param accent_color:
|
66
|
|
|
the user's banner color encoded as an integer representation of
|
67
|
|
|
hexadecimal color code
|
68
|
|
|
|
69
|
|
|
:param banner:
|
70
|
|
|
the user's banner, or null if unset
|
71
|
|
|
|
72
|
|
|
:param banner_color:
|
73
|
|
|
the color of the user's banner
|
74
|
|
|
|
75
|
|
|
:param bot:
|
76
|
|
|
whether the user belongs to an OAuth2 application
|
77
|
|
|
|
78
|
|
|
:param email:
|
79
|
|
|
the user's email
|
80
|
|
|
|
81
|
|
|
:param locale:
|
82
|
|
|
the user's chosen language option
|
83
|
|
|
|
84
|
|
|
:param mfa_enabled:
|
85
|
|
|
whether the user has two factor enabled on their account
|
86
|
|
|
|
87
|
|
|
:param premium_type:
|
88
|
|
|
the type of Nitro subscription on a user's account
|
89
|
|
|
|
90
|
|
|
:param public_flags:
|
91
|
|
|
the public flags on a user's account
|
92
|
|
|
|
93
|
|
|
:param system:
|
94
|
|
|
whether the user is an Official Discord System user
|
95
|
|
|
(part of the urgent message system)
|
96
|
|
|
|
97
|
|
|
:param verified:
|
98
|
|
|
whether the email on this account has been verified
|
99
|
|
|
"""
|
100
|
|
|
|
101
|
|
|
_client: Client
|
|
|
|
|
102
|
|
|
_http: HTTPClient
|
103
|
|
|
|
104
|
|
|
avatar: Optional[str]
|
105
|
|
|
discriminator: str
|
106
|
|
|
id: Snowflake
|
107
|
|
|
username: str
|
108
|
|
|
|
109
|
|
|
flags: APINullable[int] = MISSING
|
|
|
|
|
110
|
|
|
accent_color: APINullable[Optional[int]] = MISSING
|
111
|
|
|
banner: APINullable[Optional[str]] = MISSING
|
112
|
|
|
banner_color: APINullable[Optional[int]] = MISSING
|
113
|
|
|
bot: APINullable[bool] = MISSING
|
114
|
|
|
email: APINullable[Optional[str]] = MISSING
|
115
|
|
|
locale: APINullable[str] = MISSING
|
116
|
|
|
mfa_enabled: APINullable[bool] = MISSING
|
117
|
|
|
premium_type: APINullable[int] = MISSING
|
118
|
|
|
public_flags: APINullable[int] = MISSING
|
119
|
|
|
system: APINullable[bool] = MISSING
|
120
|
|
|
verified: APINullable[bool] = MISSING
|
121
|
|
|
|
122
|
|
|
@property
|
123
|
|
|
def premium(self) -> APINullable[PremiumTypes]:
|
124
|
|
|
"""
|
125
|
|
|
The user their premium type in a usable enum.
|
126
|
|
|
"""
|
127
|
|
|
return (
|
128
|
|
|
MISSING
|
129
|
|
|
if self.premium_type is MISSING
|
130
|
|
|
else PremiumTypes(self.premium_type)
|
131
|
|
|
)
|
132
|
|
|
|
133
|
|
|
@property
|
134
|
|
|
def mention(self) -> str:
|
|
|
|
|
135
|
|
|
return f"<@!{self.id}>"
|
136
|
|
|
|
137
|
|
|
def __str__(self):
|
138
|
|
|
"""Return the discord tag when object gets used as a string."""
|
139
|
|
|
return self.username + '#' + self.discriminator
|
140
|
|
|
|
141
|
|
|
def __post_init__(self):
|
142
|
|
|
self.id = convert(self.id, Snowflake.from_string)
|
143
|
|
|
|
144
|
|
|
@classmethod
|
145
|
|
|
async def from_id(cls, client: Client, _id: int) -> User:
|
|
|
|
|
146
|
|
|
data = await client.http.get(f"users/{_id}")
|
147
|
|
|
return cls.from_dict(data)
|
148
|
|
|
|