1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
3
|
|
|
|
4
|
|
|
from dataclasses import dataclass |
5
|
|
|
from typing import Any, List, Optional |
6
|
|
|
|
7
|
|
|
from .presence import PresenceUpdateEvent |
8
|
|
|
from ..guild.member import GuildMember |
9
|
|
|
from ..guild.role import Role |
10
|
|
|
from ..message.emoji import Emoji |
11
|
|
|
from ..message.sticker import Sticker |
12
|
|
|
from ..user import User |
13
|
|
|
from ...utils.api_object import APIObject |
14
|
|
|
from ...utils.conversion import construct_client_dict |
15
|
|
|
from ...utils.snowflake import Snowflake |
16
|
|
|
from ...utils.timestamp import Timestamp |
|
|
|
|
17
|
|
|
from ...utils.types import MISSING, APINullable |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
@dataclass |
21
|
|
|
class GuildBanAddEvent(APIObject): |
22
|
|
|
""" |
23
|
|
|
Sent when a user is banned from a guild. |
24
|
|
|
|
25
|
|
|
:param guild_id: |
26
|
|
|
id of the guild |
27
|
|
|
|
28
|
|
|
:param user: |
29
|
|
|
the banned user |
30
|
|
|
""" |
31
|
|
|
guild_id: Snowflake |
32
|
|
|
user: User |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
@dataclass |
36
|
|
|
class GuildBanRemoveEvent(APIObject): |
37
|
|
|
""" |
38
|
|
|
Sent when a user is unbanned from a guild. |
39
|
|
|
|
40
|
|
|
:param guild_id: |
41
|
|
|
id of the guild |
42
|
|
|
|
43
|
|
|
:param user: |
44
|
|
|
the unbanned user |
45
|
|
|
""" |
46
|
|
|
guild_id: Snowflake |
47
|
|
|
user: User |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
@dataclass |
51
|
|
|
class GuildEmojisUpdateEvent(APIObject): |
52
|
|
|
""" |
53
|
|
|
Sent when a guild's emojis have been updated. |
54
|
|
|
|
55
|
|
|
:param guild_id: |
56
|
|
|
id of the guild |
57
|
|
|
|
58
|
|
|
:param emojis: |
59
|
|
|
array of emojis |
60
|
|
|
""" |
61
|
|
|
guild_id: Snowflake |
62
|
|
|
emojis: List[Emoji] |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
@dataclass |
66
|
|
|
class GuildStickersUpdateEvent(APIObject): |
67
|
|
|
""" |
68
|
|
|
Sent when a guild's stickers have been updated. |
69
|
|
|
|
70
|
|
|
:param guild_id: |
71
|
|
|
id of the guild |
72
|
|
|
|
73
|
|
|
:param stickers: |
74
|
|
|
array of stickers |
75
|
|
|
""" |
76
|
|
|
guild_id: Snowflake |
77
|
|
|
stickers: List[Sticker] |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
@dataclass |
81
|
|
|
class GuildIntegrationsUpdateEvent(APIObject): |
82
|
|
|
""" |
83
|
|
|
Sent when a guild integration is updated. |
84
|
|
|
|
85
|
|
|
:param guild_id: |
86
|
|
|
id of the guild whose integrations were updated |
87
|
|
|
""" |
88
|
|
|
guild_id: Snowflake |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
@dataclass |
92
|
|
|
class GuildMemberAddEvent(GuildMember): |
93
|
|
|
""" |
94
|
|
|
Sent when a user joins a guild. |
95
|
|
|
|
96
|
|
|
:param guild_id: |
97
|
|
|
ID of the guild that the user joined. |
98
|
|
|
""" |
99
|
|
|
# NOTE: This isn't a default value. I set it to this because you can't |
100
|
|
|
# have fields without default values after regular fields. Apparently that |
101
|
|
|
# carries over when you inherit from a dataclass. |
102
|
|
|
guild_id: Snowflake = 0 |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
@dataclass |
106
|
|
|
class GuildMemberRemoveEvent(APIObject): |
107
|
|
|
""" |
108
|
|
|
Sent when a user is removed from a guild (leave/kick/ban). |
109
|
|
|
|
110
|
|
|
:param guild_id: |
111
|
|
|
the id of the guild |
112
|
|
|
|
113
|
|
|
:param user: |
114
|
|
|
the user who was removed |
115
|
|
|
""" |
116
|
|
|
guild_id: Snowflake |
117
|
|
|
user: User |
118
|
|
|
|
119
|
|
|
def __post_init__(self): |
120
|
|
|
self.user = User.from_dict( |
121
|
|
|
construct_client_dict(self._client, self.user) |
|
|
|
|
122
|
|
|
) |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
@dataclass |
|
|
|
|
126
|
|
|
class GuildMemberUpdateEvent(APIObject): |
127
|
|
|
""" |
128
|
|
|
Sent when a guild member is updated. |
129
|
|
|
This will also fire when the user object |
130
|
|
|
of a guild member changes. |
131
|
|
|
|
132
|
|
|
:param guild_id: |
133
|
|
|
the id of the guild |
134
|
|
|
|
135
|
|
|
:param roles: |
136
|
|
|
user role ids |
137
|
|
|
|
138
|
|
|
:param user: |
139
|
|
|
the user |
140
|
|
|
|
141
|
|
|
:param nick: |
142
|
|
|
nickname of the user in the guild |
143
|
|
|
|
144
|
|
|
:param joined_at: |
145
|
|
|
when the user joined the guild |
146
|
|
|
|
147
|
|
|
:param premium_since: |
148
|
|
|
when the user started boosting the guild |
149
|
|
|
|
150
|
|
|
:param deaf: |
151
|
|
|
whether the user is deafened in voice channels |
152
|
|
|
|
153
|
|
|
:param mute: |
154
|
|
|
whether the user is muted in voice channels |
155
|
|
|
|
156
|
|
|
:param pending: |
157
|
|
|
whether the user has not yet passed the guild's |
158
|
|
|
Membership Screening requirements |
159
|
|
|
""" |
160
|
|
|
guild_id: Snowflake |
161
|
|
|
roles: List[Snowflake] |
162
|
|
|
user: User |
163
|
|
|
nick: APINullable[Optional[str]] = MISSING |
164
|
|
|
joined_at: Optional[Timestamp] = None |
165
|
|
|
premium_since: APINullable[Optional[Timestamp]] = MISSING |
166
|
|
|
deaf: APINullable[bool] = MISSING |
167
|
|
|
mute: APINullable[bool] = MISSING |
168
|
|
|
pending: APINullable[bool] = MISSING |
169
|
|
|
|
170
|
|
|
def __post_init__(self): |
171
|
|
|
self.user = User.from_dict(construct_client_dict( |
172
|
|
|
self._client, self.user |
|
|
|
|
173
|
|
|
)) |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
@dataclass |
177
|
|
|
class GuildMembersChunkEvent(APIObject): |
178
|
|
|
""" |
179
|
|
|
Sent in response to Guild Request Members. |
180
|
|
|
You can use the `chunk_index` and `chunk_count` |
181
|
|
|
to calculate how many chunks are left for your request. |
182
|
|
|
|
183
|
|
|
:param guild_id: |
184
|
|
|
the id of the guild |
185
|
|
|
|
186
|
|
|
:param members: |
187
|
|
|
set of guild members |
188
|
|
|
|
189
|
|
|
:param chunk_index: |
190
|
|
|
the chunk index in the expected chunks for this response |
191
|
|
|
(0 <= chunk_index < chunk_count) |
192
|
|
|
|
193
|
|
|
:param chunk_count: |
194
|
|
|
the total number of expected chunks for this response |
195
|
|
|
|
196
|
|
|
:param not_found: |
197
|
|
|
if passing an invalid id to `REQUEST_GUILD_MEMBERS`, |
198
|
|
|
it will be returned here |
199
|
|
|
|
200
|
|
|
:param presences: |
201
|
|
|
if passing true to `REQUEST_GUILD_MEMBERS`, presences |
202
|
|
|
of the returned members will be here |
203
|
|
|
|
204
|
|
|
:param nonce:" |
205
|
|
|
the nonce used in the Guild Members Request |
206
|
|
|
""" |
207
|
|
|
guild_id: Snowflake |
208
|
|
|
members: List[GuildMember] |
209
|
|
|
chunk_index: int |
210
|
|
|
chunk_count: int |
211
|
|
|
|
212
|
|
|
not_found: APINullable[List[Any]] = MISSING |
213
|
|
|
presences: APINullable[PresenceUpdateEvent] = MISSING |
214
|
|
|
nonce: APINullable[str] = MISSING |
215
|
|
|
|
216
|
|
|
def __post_init__(self): |
217
|
|
|
self.members = [ |
218
|
|
|
GuildMember.from_dict( |
219
|
|
|
construct_client_dict( |
220
|
|
|
self._client, member |
|
|
|
|
221
|
|
|
) |
222
|
|
|
) |
223
|
|
|
for member in self.members |
224
|
|
|
] |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
@dataclass |
228
|
|
|
class GuildRoleCreateEvent(APIObject): |
229
|
|
|
""" |
230
|
|
|
Sent when a guild role is created. |
231
|
|
|
|
232
|
|
|
:param guild_id: |
233
|
|
|
the id of the guild |
234
|
|
|
|
235
|
|
|
:param role: |
236
|
|
|
the role created |
237
|
|
|
""" |
238
|
|
|
guild_id: Snowflake |
239
|
|
|
role: Role |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
@dataclass |
243
|
|
|
class GuildRoleUpdateEvent(APIObject): |
244
|
|
|
""" |
245
|
|
|
Sent when a guild role is updated. |
246
|
|
|
|
247
|
|
|
:param guild_id: |
248
|
|
|
the id of the guild |
249
|
|
|
|
250
|
|
|
:param role: |
251
|
|
|
the role updated |
252
|
|
|
""" |
253
|
|
|
guild_id: Snowflake |
254
|
|
|
role: Role |
255
|
|
|
|
256
|
|
|
|
257
|
|
|
@dataclass |
258
|
|
|
class GuildRoleDeleteEvent(APIObject): |
259
|
|
|
""" |
260
|
|
|
Sent when a guild role is deleted. |
261
|
|
|
|
262
|
|
|
:param guild_id: |
263
|
|
|
id of the guild |
264
|
|
|
|
265
|
|
|
:param role_id: |
266
|
|
|
id of the role |
267
|
|
|
""" |
268
|
|
|
guild_id: Snowflake |
269
|
|
|
role_id: Snowflake |
270
|
|
|
|