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