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
|
|
|
class ActivityFlags: |
|
|
|
|
135
|
|
|
""" |
136
|
|
|
There is no information on what the flags are in the Discord API docs. |
137
|
|
|
https://discord.dev/topics/gateway#activity-object-activity-flags |
138
|
|
|
""" |
139
|
|
|
|
140
|
|
|
def __init__(self, flags) -> None: |
141
|
|
|
self.INSTANCE = bool(flags >> 0 & 1) |
142
|
|
|
self.JOIN = bool(flags >> 1 & 1) |
143
|
|
|
self.SPECTATE = bool(flags >> 2 & 1) |
144
|
|
|
self.JOIN_REQUEST = bool(flags >> 3 & 1) |
145
|
|
|
self.SYNC = bool(flags >> 4 & 1) |
146
|
|
|
self.PLAY = bool(flags >> 5 & 1) |
147
|
|
|
self.PARTY_PRIVACY_FRIENDS = bool(flags >> 6 & 1) |
148
|
|
|
self.PARTY_PRIVACY_VOICE_CHANNEL = bool(flags >> 7 & 1) |
149
|
|
|
self.EMBEDDED = bool(flags >> 8 & 1) |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
@dataclass(repr=False) |
153
|
|
|
class ActivityButton(APIObject): |
154
|
|
|
"""When received over the gateway, the buttons' field is an array |
155
|
|
|
of strings, which are the button labels. Bots cannot access |
156
|
|
|
a user's activity button URLs. When sending, the buttons' field |
157
|
|
|
must be an array of this object. |
158
|
|
|
|
159
|
|
|
Attributes |
160
|
|
|
---------- |
161
|
|
|
label: :class:`str` |
162
|
|
|
The text shown on the button (1-32 characters) |
163
|
|
|
url: :class:`str` |
164
|
|
|
The url opened when clicking the button (1-512 characters) |
165
|
|
|
""" |
166
|
|
|
label: str |
167
|
|
|
url: str |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
@dataclass(repr=False) |
171
|
|
|
class Activity(APIObject): |
|
|
|
|
172
|
|
|
"""Bots are only able to send ``name``, ``type``, and optionally ``url``. |
173
|
|
|
|
174
|
|
|
Attributes |
175
|
|
|
---------- |
176
|
|
|
name: :class:`str` |
177
|
|
|
The activity's name |
178
|
|
|
type: :class:`~pincer.objects.events.presence.ActivityType` |
179
|
|
|
Activity type |
180
|
|
|
created_at: :class:`int` |
181
|
|
|
Unix timestamp (in milliseconds) of when |
182
|
|
|
the activity was added to the user's session |
183
|
|
|
url: APINullable[Optional[:class:`str`]] |
184
|
|
|
Stream url, is validated when type is 1 |
185
|
|
|
timestamps: APINullable[:class:`~pincer.objects.events.presence.ActivityTimestamp`] |
186
|
|
|
Unix timestamps for start and/or end of the game |
187
|
|
|
application_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`] |
188
|
|
|
Application id for the game |
189
|
|
|
details: APINullable[Optional[:class:`str`]] |
190
|
|
|
What the player is currently doing |
191
|
|
|
state: APINullable[Optional[:class:`str`]] |
192
|
|
|
The user's current party status |
193
|
|
|
emoji: APINullable[Optional[:class:`~pincer.objects.events.presence.ActivityEmoji`]] |
194
|
|
|
The emoji used for a custom status |
195
|
|
|
party: APINullable[:class:`~pincer.objects.events.presence.ActivityParty`] |
196
|
|
|
Information for the current party of the player |
197
|
|
|
assets: APINullable[:class:`~pincer.objects.events.presence.ActivityAssets`] |
198
|
|
|
Images for the presence and their hover texts |
199
|
|
|
secrets: APINullable[:class:`~pincer.objects.events.presence.ActivitySecrets`] |
200
|
|
|
Secrets for Rich Presence joining and spectating |
201
|
|
|
instance: APINullable[:class:`bool`] |
202
|
|
|
"nether or not the activity is an instanced game session |
203
|
|
|
flags: APINullable[:class:`~pincer.objects.events.presence.ActivityFlags`] |
204
|
|
|
Activity flags ``OR``\\d together, |
205
|
|
|
describes what the payload includes |
206
|
|
|
buttons: APINullable[List[:class:`~pincer.objects.events.presence.ActivityButton`]] |
207
|
|
|
The url button on an activity. |
208
|
|
|
""" |
209
|
|
|
# noqa: E501 |
210
|
|
|
name: str |
211
|
|
|
type: ActivityType |
212
|
|
|
created_at: int |
213
|
|
|
|
214
|
|
|
url: APINullable[Optional[str]] = MISSING |
215
|
|
|
timestamps: APINullable[ActivityTimestamp] = MISSING |
216
|
|
|
application_id: APINullable[Snowflake] = MISSING |
217
|
|
|
details: APINullable[Optional[str]] = MISSING |
218
|
|
|
state: APINullable[Optional[str]] = MISSING |
219
|
|
|
emoji: APINullable[Optional[ActivityEmoji]] = MISSING |
220
|
|
|
party: APINullable[ActivityParty] = MISSING |
221
|
|
|
assets: APINullable[ActivityAssets] = MISSING |
222
|
|
|
secrets: APINullable[ActivitySecrets] = MISSING |
223
|
|
|
instance: APINullable[bool] = MISSING |
224
|
|
|
flags: APINullable[ActivityFlags] = MISSING |
225
|
|
|
buttons: APINullable[List[ActivityButton]] = MISSING |
226
|
|
|
|
227
|
|
|
|
228
|
|
|
@dataclass(repr=False) |
229
|
|
|
class ClientStatus(APIObject): |
230
|
|
|
"""Active sessions are indicated with an "online", |
231
|
|
|
"idle", or "dnd" string per platform. |
232
|
|
|
If a user is offline or invisible, the corresponding |
233
|
|
|
field is not present. |
234
|
|
|
|
235
|
|
|
Attributes |
236
|
|
|
---------- |
237
|
|
|
desktop: APINullable[:class:`str`] |
238
|
|
|
The user's status set for an active desktop |
239
|
|
|
(Windows, Linux, Mac) application session |
240
|
|
|
mobile: APINullable[:class:`str`] |
241
|
|
|
The user's status set for an active mobile |
242
|
|
|
(iOS, Android) application session |
243
|
|
|
web: APINullable[:class:`str`] |
244
|
|
|
The user's status set for an active web |
245
|
|
|
(browser, bot account) application session |
246
|
|
|
""" |
247
|
|
|
desktop: APINullable[str] = MISSING |
248
|
|
|
mobile: APINullable[str] = MISSING |
249
|
|
|
web: APINullable[str] = MISSING |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
@dataclass(repr=False) |
253
|
|
|
class PresenceUpdateEvent(APIObject, GuildProperty): |
254
|
|
|
"""This event is sent when a user's presence or info, |
255
|
|
|
such as name or avatar, is updated. |
256
|
|
|
|
257
|
|
|
Attributes |
258
|
|
|
---------- |
259
|
|
|
user: :class:`~pincer.objects.user.user.User` |
260
|
|
|
The user presence is being updated for |
261
|
|
|
guild_id: :class:`~pincer.utils.snowflake.Snowflake` |
262
|
|
|
Id of the guild |
263
|
|
|
status: :class:`str` |
264
|
|
|
Either "idle", "dnd", "online", or "offline" |
265
|
|
|
activities: List[:class:`~pincer.objects.events.presence.Activity`] |
266
|
|
|
User's current activities' |
267
|
|
|
client_status: :class:`~pincer.objects.events.presence.ClientStatus` |
268
|
|
|
User's platform-dependent status |
269
|
|
|
""" |
270
|
|
|
user: User |
271
|
|
|
status: str |
272
|
|
|
activities: List[Activity] |
273
|
|
|
client_status: ClientStatus |
274
|
|
|
guild_id: APINullable[Snowflake] = MISSING |
275
|
|
|
|