pincer.objects.events.presence   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 285
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 86
dl 0
loc 285
rs 10
c 0
b 0
f 0

1 Method

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