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 typing import Optional, List, TYPE_CHECKING |
8
|
|
|
|
9
|
|
|
from ..user import User |
10
|
|
|
from ...utils.api_object import APIObject, HTTPMeta |
|
|
|
|
11
|
|
|
from ...utils.conversion import convert |
12
|
|
|
from ...utils.snowflake import Snowflake |
13
|
|
|
from ...utils.timestamp import Timestamp |
|
|
|
|
14
|
|
|
from ...utils.types import MISSING |
15
|
|
|
|
16
|
|
|
if TYPE_CHECKING: |
17
|
|
|
from ... import Client |
18
|
|
|
from ...utils.types import APINullable |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
@dataclass |
22
|
|
|
class BaseMember(APIObject): |
23
|
|
|
""" |
24
|
|
|
Represents the base of a guild member. |
25
|
|
|
|
26
|
|
|
:param deaf: |
27
|
|
|
whether the user is deafened in voice channels |
28
|
|
|
|
29
|
|
|
:param joined_at: |
30
|
|
|
when the user joined the guild |
31
|
|
|
|
32
|
|
|
:param mute: |
33
|
|
|
whether the user is muted in voice channels |
34
|
|
|
|
35
|
|
|
:param roles: |
36
|
|
|
array of role object ids |
37
|
|
|
|
38
|
|
|
:param hoisted_role: |
39
|
|
|
The user their top guild role! |
40
|
|
|
""" |
41
|
|
|
deaf: bool |
42
|
|
|
joined_at: Timestamp |
43
|
|
|
mute: bool |
44
|
|
|
roles: List[Snowflake] |
45
|
|
|
|
46
|
|
|
hoisted_role: APINullable[Snowflake] = MISSING |
47
|
|
|
|
48
|
|
|
def __post_init__(self): |
49
|
|
|
self.roles = convert(self.roles, Snowflake.from_string) |
50
|
|
|
self.hoisted_role = convert(self.hoisted_role, Snowflake.from_string) |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
@dataclass |
54
|
|
|
class PartialGuildMember(APIObject): |
55
|
|
|
""" |
56
|
|
|
Represents a partial guild member. |
57
|
|
|
This is a reference to a member from a guild which does not contain |
58
|
|
|
all information. |
59
|
|
|
|
60
|
|
|
This gets used in form example message mentions. |
61
|
|
|
|
62
|
|
|
:param id: |
63
|
|
|
the user's id |
64
|
|
|
|
65
|
|
|
:param username: |
66
|
|
|
the user's username, not unique across the platform |
67
|
|
|
|
68
|
|
|
:param discriminator: |
69
|
|
|
the user's 4-digit discord-tag |
70
|
|
|
|
71
|
|
|
:param avatar: |
72
|
|
|
the user's avatar hash |
73
|
|
|
|
74
|
|
|
:param public_flags: |
75
|
|
|
the flags on a user's account |
76
|
|
|
|
77
|
|
|
:param member: |
78
|
|
|
The user their (partial) guild information. |
79
|
|
|
""" |
80
|
|
|
id: Snowflake |
81
|
|
|
username: str |
82
|
|
|
discriminator: str |
83
|
|
|
avatar: str |
84
|
|
|
public_flags: int |
85
|
|
|
member: BaseMember |
86
|
|
|
|
87
|
|
|
def __post_init__(self): |
88
|
|
|
self.member = convert(self.member, BaseMember.from_dict) |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
@dataclass |
92
|
|
|
class GuildMember(BaseMember, APIObject): |
93
|
|
|
""" |
94
|
|
|
Represents a member which resides in a guild/server. |
95
|
|
|
|
96
|
|
|
:param _client: |
97
|
|
|
reference to the Client |
98
|
|
|
|
99
|
|
|
:param _http: |
100
|
|
|
reference to the HTTPClient |
101
|
|
|
|
102
|
|
|
:param nick: |
103
|
|
|
this users guild nickname |
104
|
|
|
|
105
|
|
|
:param pending: |
106
|
|
|
whether the user has not yet passed the guild's Membership |
107
|
|
|
Screening requirements |
108
|
|
|
|
109
|
|
|
:param is_pending: |
110
|
|
|
Deprecated version of pending. |
111
|
|
|
|
112
|
|
|
:param permissions: |
113
|
|
|
total permissions of the member in the channel, |
114
|
|
|
including overwrites, returned when in the interaction object |
115
|
|
|
|
116
|
|
|
:param premium_since: |
117
|
|
|
when the user started boosting the guild |
118
|
|
|
|
119
|
|
|
:param user: |
120
|
|
|
the user this guild member represents |
121
|
|
|
""" |
122
|
|
|
|
123
|
|
|
# _client: Client |
124
|
|
|
# _http: HTTPClient |
125
|
|
|
|
126
|
|
|
nick: APINullable[Optional[str]] = MISSING |
127
|
|
|
pending: APINullable[bool] = MISSING |
128
|
|
|
is_pending: APINullable[bool] = MISSING |
129
|
|
|
permissions: APINullable[str] = MISSING |
130
|
|
|
premium_since: APINullable[Optional[Timestamp]] = MISSING |
131
|
|
|
user: APINullable[User] = MISSING |
132
|
|
|
avatar: APINullable[str] = MISSING |
133
|
|
|
|
134
|
|
|
def __post_init__(self): |
135
|
|
|
self.user = convert(self.user, User.from_dict, User, self._client) |
|
|
|
|
136
|
|
|
self.premium_since = convert( |
137
|
|
|
self.premium_since, Timestamp.parse, Timestamp |
138
|
|
|
) |
139
|
|
|
|
140
|
|
|
@classmethod |
141
|
|
|
async def from_id( |
|
|
|
|
142
|
|
|
cls, |
143
|
|
|
client: Client, |
144
|
|
|
guild_id: int, |
145
|
|
|
_id: int |
146
|
|
|
) -> GuildMember: |
147
|
|
|
data = await client.http.get(f"guilds/{guild_id}/members/{_id}") |
148
|
|
|
return cls.from_dict({**data, "_client": client, "_http": client.http}) |
149
|
|
|
|