1
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
2
|
|
|
# MIT License |
3
|
|
|
# |
4
|
|
|
# Copyright (c) 2021 Pincer |
5
|
|
|
# |
6
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining |
7
|
|
|
# a copy of this software and associated documentation files |
8
|
|
|
# (the "Software"), to deal in the Software without restriction, |
9
|
|
|
# including without limitation the rights to use, copy, modify, merge, |
10
|
|
|
# publish, distribute, sublicense, and/or sell copies of the Software, |
11
|
|
|
# and to permit persons to whom the Software is furnished to do so, |
12
|
|
|
# subject to the following conditions: |
13
|
|
|
# |
14
|
|
|
# The above copyright notice and this permission notice shall be |
15
|
|
|
# included in all copies or substantial portions of the Software. |
16
|
|
|
# |
17
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
18
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
19
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
20
|
|
|
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
21
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
22
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
23
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
24
|
|
|
from __future__ import annotations |
25
|
|
|
|
26
|
|
|
from dataclasses import dataclass |
27
|
|
|
from enum import Enum |
28
|
|
|
from typing import Optional |
29
|
|
|
|
30
|
|
|
from pincer.utils.api_object import APIObject |
31
|
|
|
from pincer.utils.constants import MISSING, APINullable |
32
|
|
|
from pincer.utils.snowflake import Snowflake |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
class PremiumTypes(Enum): |
36
|
|
|
""" |
37
|
|
|
The type of Discord premium a user has. |
38
|
|
|
""" |
39
|
|
|
NONE = 0 |
40
|
|
|
NITRO_CLASSIC = 1 |
41
|
|
|
NITRO = 2 |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
@dataclass |
|
|
|
|
45
|
|
|
class User(APIObject): |
46
|
|
|
""" |
47
|
|
|
Represents a Discord user. This can be a bot account or a |
48
|
|
|
human account. |
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 bot: |
73
|
|
|
whether the user belongs to an OAuth2 application |
74
|
|
|
|
75
|
|
|
:param email: |
76
|
|
|
the user's email |
77
|
|
|
|
78
|
|
|
:param locale: |
79
|
|
|
the user's chosen language option |
80
|
|
|
|
81
|
|
|
:param mfa_enabled: |
82
|
|
|
whether the user has two factor enabled on their account |
83
|
|
|
|
84
|
|
|
:param premium_type: |
85
|
|
|
the type of Nitro subscription on a user's account |
86
|
|
|
|
87
|
|
|
:param public_flags: |
88
|
|
|
the public flags on a user's account |
89
|
|
|
|
90
|
|
|
:param system: |
91
|
|
|
whether the user is an Official Discord System user (part of the urgent |
92
|
|
|
message system) |
93
|
|
|
|
94
|
|
|
:param verified: |
95
|
|
|
whether the email on this account has been verified |
96
|
|
|
""" |
97
|
|
|
|
98
|
|
|
avatar: Optional[str] |
99
|
|
|
discriminator: str |
100
|
|
|
flags: int |
101
|
|
|
id: Snowflake |
|
|
|
|
102
|
|
|
username: str |
103
|
|
|
|
104
|
|
|
accent_color: APINullable[Optional[int]] = MISSING |
|
|
|
|
105
|
|
|
banner: APINullable[Optional[str]] = MISSING |
|
|
|
|
106
|
|
|
bot: APINullable[bool] = MISSING |
|
|
|
|
107
|
|
|
email: APINullable[Optional[str]] = MISSING |
|
|
|
|
108
|
|
|
locale: APINullable[str] = MISSING |
|
|
|
|
109
|
|
|
mfa_enabled: APINullable[bool] = MISSING |
|
|
|
|
110
|
|
|
premium_type: APINullable[int] = MISSING |
|
|
|
|
111
|
|
|
public_flags: APINullable[int] = MISSING |
|
|
|
|
112
|
|
|
system: APINullable[bool] = MISSING |
|
|
|
|
113
|
|
|
verified: APINullable[bool] = MISSING |
|
|
|
|
114
|
|
|
|
115
|
|
|
@property |
116
|
|
|
def premium(self) -> PremiumTypes: |
117
|
|
|
""" |
118
|
|
|
The user their premium type in a usable enum. |
119
|
|
|
""" |
120
|
|
|
return PremiumTypes(self.premium_type) |
121
|
|
|
|
122
|
|
|
def __str__(self): |
123
|
|
|
"""Return the discord tag when object gets used as a string.""" |
124
|
|
|
return self.username + '#' + self.discriminator |
125
|
|
|
|