|
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 enum import IntEnum |
|
8
|
|
|
from typing import TYPE_CHECKING |
|
9
|
|
|
|
|
10
|
|
|
from ...utils.api_object import APIObject, GuildProperty |
|
11
|
|
|
from ...utils.types import MISSING, APINullable |
|
12
|
|
|
|
|
13
|
|
|
if TYPE_CHECKING: |
|
14
|
|
|
from typing import List, Optional, Tuple |
|
15
|
|
|
from ..user.user import User |
|
16
|
|
|
from ...utils.snowflake import Snowflake |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
class ActivityType(IntEnum): |
|
20
|
|
|
"""Represents the enum of the type of activity. |
|
21
|
|
|
|
|
22
|
|
|
Attributes |
|
23
|
|
|
---------- |
|
24
|
|
|
GAME: |
|
25
|
|
|
Playing {name}; e.g. "Playing Rocket League" |
|
26
|
|
|
STREAMING: |
|
27
|
|
|
Streaming {details}; e.g. "Streaming Rocket League"; Only supports Twitch and YouTube. |
|
28
|
|
|
LISTENING: |
|
29
|
|
|
Listening to {name}; e.g. "Listening to Spotify" |
|
30
|
|
|
WATCHING: |
|
31
|
|
|
Watching {name}; e.g. "Watching YouTube Together" |
|
32
|
|
|
CUSTOM: |
|
33
|
|
|
\\{emoji} {name}; e.g. "\\:smiley: I am cool"; Not for bots; discord limitation |
|
34
|
|
|
COMPETING: |
|
35
|
|
|
Competing in {name}; e.g. "Competing in Arena World Champions" |
|
36
|
|
|
""" # noqa: E501 |
|
37
|
|
|
GAME = 0 |
|
38
|
|
|
STREAMING = 1 |
|
39
|
|
|
LISTENING = 2 |
|
40
|
|
|
WATCHING = 3 |
|
41
|
|
|
CUSTOM = 4 |
|
42
|
|
|
COMPETING = 5 |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
@dataclass(repr=False) |
|
46
|
|
|
class ActivityTimestamp(APIObject): |
|
47
|
|
|
"""Represents the timestamp of an activity. |
|
48
|
|
|
|
|
49
|
|
|
Attributes |
|
50
|
|
|
---------- |
|
51
|
|
|
start: APINullable[:class:`int`] |
|
52
|
|
|
Unix time (in milliseconds) of when the activity started |
|
53
|
|
|
end: APINullable[:class:`int`] |
|
54
|
|
|
Unix time (in milliseconds) of when the activity ends |
|
55
|
|
|
""" |
|
56
|
|
|
start: APINullable[int] = MISSING |
|
57
|
|
|
end: APINullable[int] = MISSING |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
@dataclass(repr=False) |
|
61
|
|
|
class ActivityEmoji(APIObject): |
|
62
|
|
|
"""Represents an emoji in an activity. |
|
63
|
|
|
|
|
64
|
|
|
Attributes |
|
65
|
|
|
---------- |
|
66
|
|
|
name: :class:`str` |
|
67
|
|
|
The name of the emoji |
|
68
|
|
|
id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
|
69
|
|
|
The id of the emoji |
|
70
|
|
|
animated: APINullable[:class:`bool`] |
|
71
|
|
|
Whether this emoji is animated |
|
72
|
|
|
""" |
|
73
|
|
|
name: str |
|
74
|
|
|
id: APINullable[Snowflake] = MISSING |
|
75
|
|
|
animated: APINullable[bool] = MISSING |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
@dataclass(repr=False) |
|
79
|
|
|
class ActivityParty(APIObject): |
|
80
|
|
|
"""Represents a party in an activity. |
|
81
|
|
|
|
|
82
|
|
|
Attributes |
|
83
|
|
|
---------- |
|
84
|
|
|
id: APINullable[:class:`str`] |
|
85
|
|
|
The id of the party |
|
86
|
|
|
size: APINullable[Tuple[:class:`int`, :class:`int`]] |
|
87
|
|
|
Array of two integers (current_size, max_size) |
|
88
|
|
|
""" |
|
89
|
|
|
id: APINullable[str] = MISSING |
|
90
|
|
|
size: APINullable[Tuple[int, int]] = MISSING |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
@dataclass(repr=False) |
|
94
|
|
|
class ActivityAssets(APIObject): |
|
95
|
|
|
"""Represents an asset of an activity. |
|
96
|
|
|
|
|
97
|
|
|
Attributes |
|
98
|
|
|
---------- |
|
99
|
|
|
large_image: APINullable[:class:`str`] |
|
100
|
|
|
the id for a large asset of the activity, usually a snowflake |
|
101
|
|
|
large_text: APINullable[:class:`str`] |
|
102
|
|
|
text displayed when hovering over |
|
103
|
|
|
the large image of the activity |
|
104
|
|
|
small_image: APINullable[:class:`str`] |
|
105
|
|
|
the id for a small asset of the activity, usually a snowflake |
|
106
|
|
|
small_text: APINullable[:class:`str`] |
|
107
|
|
|
text displayed when hovering over |
|
108
|
|
|
the small image of the activity |
|
109
|
|
|
""" |
|
110
|
|
|
large_image: APINullable[str] = MISSING |
|
111
|
|
|
large_text: APINullable[str] = MISSING |
|
112
|
|
|
small_image: APINullable[str] = MISSING |
|
113
|
|
|
small_text: APINullable[str] = MISSING |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
@dataclass(repr=False) |
|
117
|
|
|
class ActivitySecrets(APIObject): |
|
118
|
|
|
"""Represents a secret of an activity. |
|
119
|
|
|
|
|
120
|
|
|
Attributes |
|
121
|
|
|
---------- |
|
122
|
|
|
join: APINullable[:class:`str`] |
|
123
|
|
|
The secret for joining a party |
|
124
|
|
|
spectate: APINullable[:class:`str`] |
|
125
|
|
|
The secret for spectating a game |
|
126
|
|
|
match: APINullable[:class:`str`] |
|
127
|
|
|
The secret for a specific instanced match |
|
128
|
|
|
""" |
|
129
|
|
|
join: APINullable[str] = MISSING |
|
130
|
|
|
spectate: APINullable[str] = MISSING |
|
131
|
|
|
match_: APINullable[str] = MISSING |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
@dataclass |
|
135
|
|
|
class ActivityFlags: |
|
|
|
|
|
|
136
|
|
|
""" |
|
137
|
|
|
There is no information on what the flags are in the Discord API docs. |
|
138
|
|
|
https://discord.com/developers/docs/topics/gateway#activity-object-activity-flags |
|
139
|
|
|
""" |
|
140
|
|
|
INSTANCE: bool |
|
141
|
|
|
JOIN: bool |
|
142
|
|
|
SPECTATE: bool |
|
143
|
|
|
JOIN_REQUEST: bool |
|
144
|
|
|
SYNC: bool |
|
145
|
|
|
PLAY: bool |
|
146
|
|
|
PARTY_PRIVACY_FRIENDS: bool |
|
147
|
|
|
PARTY_PRIVACY_VOICE_CHANNEL: bool |
|
148
|
|
|
EMBEDDED: bool |
|
149
|
|
|
|
|
150
|
|
|
def __init__(self, flags) -> None: |
|
151
|
|
|
self.INSTANCE = bool(flags >> 0 & 1) |
|
152
|
|
|
self.JOIN = bool(flags >> 1 & 1) |
|
153
|
|
|
self.SPECTATE = bool(flags >> 2 & 1) |
|
154
|
|
|
self.JOIN_REQUEST = bool(flags >> 3 & 1) |
|
155
|
|
|
self.SYNC = bool(flags >> 4 & 1) |
|
156
|
|
|
self.PLAY = bool(flags >> 5 & 1) |
|
157
|
|
|
self.PARTY_PRIVACY_FRIENDS = bool(flags >> 6 & 1) |
|
158
|
|
|
self.PARTY_PRIVACY_VOICE_CHANNEL = bool(flags >> 7 & 1) |
|
159
|
|
|
self.EMBEDDED = bool(flags >> 8 & 1) |
|
160
|
|
|
|
|
161
|
|
|
|
|
162
|
|
|
@dataclass(repr=False) |
|
163
|
|
|
class ActivityButton(APIObject): |
|
164
|
|
|
"""When received over the gateway, the buttons' field is an array |
|
165
|
|
|
of strings, which are the button labels. Bots cannot access |
|
166
|
|
|
a user's activity button URLs. When sending, the buttons' field |
|
167
|
|
|
must be an array of this object. |
|
168
|
|
|
|
|
169
|
|
|
Attributes |
|
170
|
|
|
---------- |
|
171
|
|
|
label: :class:`str` |
|
172
|
|
|
The text shown on the button (1-32 characters) |
|
173
|
|
|
url: :class:`str` |
|
174
|
|
|
The url opened when clicking the button (1-512 characters) |
|
175
|
|
|
""" |
|
176
|
|
|
label: str |
|
177
|
|
|
url: str |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
@dataclass(repr=False) |
|
181
|
|
|
class Activity(APIObject): |
|
|
|
|
|
|
182
|
|
|
"""Bots are only able to send ``name``, ``type``, and optionally ``url``. |
|
183
|
|
|
|
|
184
|
|
|
Attributes |
|
185
|
|
|
---------- |
|
186
|
|
|
name: :class:`str` |
|
187
|
|
|
The activity's name |
|
188
|
|
|
type: :class:`~pincer.objects.events.presence.ActivityType` |
|
189
|
|
|
Activity type |
|
190
|
|
|
created_at: :class:`int` |
|
191
|
|
|
Unix timestamp (in milliseconds) of when |
|
192
|
|
|
the activity was added to the user's session |
|
193
|
|
|
url: APINullable[Optional[:class:`str`]] |
|
194
|
|
|
Stream url, is validated when type is 1 |
|
195
|
|
|
timestamps: APINullable[:class:`~pincer.objects.events.presence.ActivityTimestamp`] |
|
196
|
|
|
Unix timestamps for start and/or end of the game |
|
197
|
|
|
application_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
|
198
|
|
|
Application id for the game |
|
199
|
|
|
details: APINullable[Optional[:class:`str`]] |
|
200
|
|
|
What the player is currently doing |
|
201
|
|
|
state: APINullable[Optional[:class:`str`]] |
|
202
|
|
|
The user's current party status |
|
203
|
|
|
emoji: APINullable[Optional[:class:`~pincer.objects.events.presence.ActivityEmoji`]] |
|
204
|
|
|
The emoji used for a custom status |
|
205
|
|
|
party: APINullable[:class:`~pincer.objects.events.presence.ActivityParty`] |
|
206
|
|
|
Information for the current party of the player |
|
207
|
|
|
assets: APINullable[:class:`~pincer.objects.events.presence.ActivityAssets`] |
|
208
|
|
|
Images for the presence and their hover texts |
|
209
|
|
|
secrets: APINullable[:class:`~pincer.objects.events.presence.ActivitySecrets`] |
|
210
|
|
|
Secrets for Rich Presence joining and spectating |
|
211
|
|
|
instance: APINullable[:class:`bool`] |
|
212
|
|
|
"nether or not the activity is an instanced game session |
|
213
|
|
|
flags: APINullable[:class:`~pincer.objects.events.presence.ActivityFlags`] |
|
214
|
|
|
Activity flags ``OR``\\d together, |
|
215
|
|
|
describes what the payload includes |
|
216
|
|
|
buttons: APINullable[List[:class:`~pincer.objects.events.presence.ActivityButton`]] |
|
217
|
|
|
The url button on an activity. |
|
218
|
|
|
""" |
|
219
|
|
|
# noqa: E501 |
|
220
|
|
|
name: str |
|
221
|
|
|
type: ActivityType |
|
222
|
|
|
created_at: int |
|
223
|
|
|
|
|
224
|
|
|
url: APINullable[Optional[str]] = MISSING |
|
225
|
|
|
timestamps: APINullable[ActivityTimestamp] = MISSING |
|
226
|
|
|
application_id: APINullable[Snowflake] = MISSING |
|
227
|
|
|
details: APINullable[Optional[str]] = MISSING |
|
228
|
|
|
state: APINullable[Optional[str]] = MISSING |
|
229
|
|
|
emoji: APINullable[Optional[ActivityEmoji]] = MISSING |
|
230
|
|
|
party: APINullable[ActivityParty] = MISSING |
|
231
|
|
|
assets: APINullable[ActivityAssets] = MISSING |
|
232
|
|
|
secrets: APINullable[ActivitySecrets] = MISSING |
|
233
|
|
|
instance: APINullable[bool] = MISSING |
|
234
|
|
|
flags: APINullable[ActivityFlags] = MISSING |
|
235
|
|
|
buttons: APINullable[List[ActivityButton]] = MISSING |
|
236
|
|
|
|
|
237
|
|
|
|
|
238
|
|
|
@dataclass(repr=False) |
|
239
|
|
|
class ClientStatus(APIObject): |
|
240
|
|
|
"""Active sessions are indicated with an "online", |
|
241
|
|
|
"idle", or "dnd" string per platform. |
|
242
|
|
|
If a user is offline or invisible, the corresponding |
|
243
|
|
|
field is not present. |
|
244
|
|
|
|
|
245
|
|
|
Attributes |
|
246
|
|
|
---------- |
|
247
|
|
|
desktop: APINullable[:class:`str`] |
|
248
|
|
|
The user's status set for an active desktop |
|
249
|
|
|
(Windows, Linux, Mac) application session |
|
250
|
|
|
mobile: APINullable[:class:`str`] |
|
251
|
|
|
The user's status set for an active mobile |
|
252
|
|
|
(iOS, Android) application session |
|
253
|
|
|
web: APINullable[:class:`str`] |
|
254
|
|
|
The user's status set for an active web |
|
255
|
|
|
(browser, bot account) application session |
|
256
|
|
|
""" |
|
257
|
|
|
desktop: APINullable[str] = MISSING |
|
258
|
|
|
mobile: APINullable[str] = MISSING |
|
259
|
|
|
web: APINullable[str] = MISSING |
|
260
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
@dataclass(repr=False) |
|
263
|
|
|
class PresenceUpdateEvent(APIObject, GuildProperty): |
|
264
|
|
|
"""This event is sent when a user's presence or info, |
|
265
|
|
|
such as name or avatar, is updated. |
|
266
|
|
|
|
|
267
|
|
|
Attributes |
|
268
|
|
|
---------- |
|
269
|
|
|
user: :class:`~pincer.objects.user.user.User` |
|
270
|
|
|
The user presence is being updated for |
|
271
|
|
|
guild_id: :class:`~pincer.utils.snowflake.Snowflake` |
|
272
|
|
|
Id of the guild |
|
273
|
|
|
status: :class:`str` |
|
274
|
|
|
Either "idle", "dnd", "online", or "offline" |
|
275
|
|
|
activities: List[:class:`~pincer.objects.events.presence.Activity`] |
|
276
|
|
|
User's current activities' |
|
277
|
|
|
client_status: :class:`~pincer.objects.events.presence.ClientStatus` |
|
278
|
|
|
User's platform-dependent status |
|
279
|
|
|
""" |
|
280
|
|
|
user: User |
|
281
|
|
|
status: str |
|
282
|
|
|
activities: List[Activity] |
|
283
|
|
|
client_status: ClientStatus |
|
284
|
|
|
guild_id: APINullable[Snowflake] = MISSING |
|
285
|
|
|
|