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
|
|
|
Attributes |
97
|
|
|
---------- |
98
|
|
|
guild_id: :class:`Snowflake` |
99
|
|
|
ID of the guild that the user joined. |
100
|
|
|
""" |
101
|
|
|
# NOTE: This isn't a default value. I set it to this because you can't |
102
|
|
|
# have fields without default values after regular fields. Apparently that |
103
|
|
|
# carries over when you inherit from a dataclass. |
104
|
|
|
guild_id: Snowflake = 0 |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
@dataclass |
108
|
|
|
class GuildMemberRemoveEvent(APIObject): |
109
|
|
|
""" |
110
|
|
|
Sent when a user is removed from a guild (leave/kick/ban). |
111
|
|
|
|
112
|
|
|
:param guild_id: |
113
|
|
|
the id of the guild |
114
|
|
|
|
115
|
|
|
:param user: |
116
|
|
|
the user who was removed |
117
|
|
|
""" |
118
|
|
|
guild_id: Snowflake |
119
|
|
|
user: User |
120
|
|
|
|
121
|
|
|
def __post_init__(self): |
122
|
|
|
self.user = User.from_dict( |
123
|
|
|
construct_client_dict(self._client, self.user) |
124
|
|
|
) |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
@dataclass |
|
|
|
|
128
|
|
|
class GuildMemberUpdateEvent(APIObject): |
129
|
|
|
""" |
130
|
|
|
Sent when a guild member is updated. |
131
|
|
|
This will also fire when the user object |
132
|
|
|
of a guild member changes. |
133
|
|
|
|
134
|
|
|
:param guild_id: |
135
|
|
|
the id of the guild |
136
|
|
|
|
137
|
|
|
:param roles: |
138
|
|
|
user role ids |
139
|
|
|
|
140
|
|
|
:param user: |
141
|
|
|
the user |
142
|
|
|
|
143
|
|
|
:param nick: |
144
|
|
|
nickname of the user in the guild |
145
|
|
|
|
146
|
|
|
:param joined_at: |
147
|
|
|
when the user joined the guild |
148
|
|
|
|
149
|
|
|
:param premium_since: |
150
|
|
|
when the user started boosting the guild |
151
|
|
|
|
152
|
|
|
:param deaf: |
153
|
|
|
whether the user is deafened in voice channels |
154
|
|
|
|
155
|
|
|
:param mute: |
156
|
|
|
whether the user is muted in voice channels |
157
|
|
|
|
158
|
|
|
:param pending: |
159
|
|
|
whether the user has not yet passed the guild's |
160
|
|
|
Membership Screening requirements |
161
|
|
|
""" |
162
|
|
|
guild_id: Snowflake |
163
|
|
|
roles: List[Snowflake] |
164
|
|
|
user: User |
165
|
|
|
nick: APINullable[Optional[str]] = MISSING |
166
|
|
|
joined_at: Optional[Timestamp] = None |
167
|
|
|
premium_since: APINullable[Optional[Timestamp]] = MISSING |
168
|
|
|
deaf: APINullable[bool] = MISSING |
169
|
|
|
mute: APINullable[bool] = MISSING |
170
|
|
|
pending: APINullable[bool] = MISSING |
171
|
|
|
|
172
|
|
|
def __post_init__(self): |
173
|
|
|
self.user = User.from_dict(construct_client_dict( |
174
|
|
|
self._client, self.user |
175
|
|
|
)) |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
@dataclass |
179
|
|
|
class GuildMembersChunkEvent(APIObject): |
180
|
|
|
""" |
181
|
|
|
Sent in response to Guild Request Members. |
182
|
|
|
You can use the `chunk_index` and `chunk_count` |
183
|
|
|
to calculate how many chunks are left for your request. |
184
|
|
|
|
185
|
|
|
:param guild_id: |
186
|
|
|
the id of the guild |
187
|
|
|
|
188
|
|
|
:param members: |
189
|
|
|
set of guild members |
190
|
|
|
|
191
|
|
|
:param chunk_index: |
192
|
|
|
the chunk index in the expected chunks for this response |
193
|
|
|
(0 <= chunk_index < chunk_count) |
194
|
|
|
|
195
|
|
|
:param chunk_count: |
196
|
|
|
the total number of expected chunks for this response |
197
|
|
|
|
198
|
|
|
:param not_found: |
199
|
|
|
if passing an invalid id to `REQUEST_GUILD_MEMBERS`, |
200
|
|
|
it will be returned here |
201
|
|
|
|
202
|
|
|
:param presences: |
203
|
|
|
if passing true to `REQUEST_GUILD_MEMBERS`, presences |
204
|
|
|
of the returned members will be here |
205
|
|
|
|
206
|
|
|
:param nonce:" |
207
|
|
|
the nonce used in the Guild Members Request |
208
|
|
|
""" |
209
|
|
|
guild_id: Snowflake |
210
|
|
|
members: List[GuildMember] |
211
|
|
|
chunk_index: int |
212
|
|
|
chunk_count: int |
213
|
|
|
|
214
|
|
|
not_found: APINullable[List[Any]] = MISSING |
215
|
|
|
presences: APINullable[PresenceUpdateEvent] = MISSING |
216
|
|
|
nonce: APINullable[str] = MISSING |
217
|
|
|
|
218
|
|
|
def __post_init__(self): |
219
|
|
|
self.members = [ |
220
|
|
|
GuildMember.from_dict( |
221
|
|
|
construct_client_dict( |
222
|
|
|
self._client, member |
223
|
|
|
) |
224
|
|
|
) |
225
|
|
|
for member in self.members |
226
|
|
|
] |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
@dataclass |
230
|
|
|
class GuildRoleCreateEvent(APIObject): |
231
|
|
|
""" |
232
|
|
|
Sent when a guild role is created. |
233
|
|
|
|
234
|
|
|
:param guild_id: |
235
|
|
|
the id of the guild |
236
|
|
|
|
237
|
|
|
:param role: |
238
|
|
|
the role created |
239
|
|
|
""" |
240
|
|
|
guild_id: Snowflake |
241
|
|
|
role: Role |
242
|
|
|
|
243
|
|
|
|
244
|
|
|
@dataclass |
245
|
|
|
class GuildRoleUpdateEvent(APIObject): |
246
|
|
|
""" |
247
|
|
|
Sent when a guild role is updated. |
248
|
|
|
|
249
|
|
|
:param guild_id: |
250
|
|
|
the id of the guild |
251
|
|
|
|
252
|
|
|
:param role: |
253
|
|
|
the role updated |
254
|
|
|
""" |
255
|
|
|
guild_id: Snowflake |
256
|
|
|
role: Role |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
@dataclass |
260
|
|
|
class GuildRoleDeleteEvent(APIObject): |
261
|
|
|
""" |
262
|
|
|
Sent when a guild role is deleted. |
263
|
|
|
|
264
|
|
|
:param guild_id: |
265
|
|
|
id of the guild |
266
|
|
|
|
267
|
|
|
:param role_id: |
268
|
|
|
id of the role |
269
|
|
|
""" |
270
|
|
|
guild_id: Snowflake |
271
|
|
|
role_id: Snowflake |
272
|
|
|
|