Passed
Pull Request — main (#339)
by
unknown
01:48
created

pincer.objects.events.presence   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 287
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 97
dl 0
loc 287
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ActivityFlags.__init__() 0 12 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
    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:
0 ignored issues
show
best-practice introduced by
Too many instance attributes (9/7)
Loading history...
136
    """
137
    There is no information on what the flags are on 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
        print(self.__repr__())
162
163
164
@dataclass(repr=False)
165
class ActivityButton(APIObject):
166
    """When received over the gateway, the buttons' field is an array
167
    of strings, which are the button labels. Bots cannot access
168
    a user's activity button URLs. When sending, the buttons' field
169
    must be an array of this object.
170
171
    Attributes
172
    ----------
173
    label: :class:`str`
174
        The text shown on the button (1-32 characters)
175
    url: :class:`str`
176
        The url opened when clicking the button (1-512 characters)
177
    """
178
    label: str
179
    url: str
180
181
182
@dataclass(repr=False)
183
class Activity(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (15/7)
Loading history...
184
    """Bots are only able to send ``name``, ``type``, and optionally ``url``.
185
186
    Attributes
187
    ----------
188
    name: :class:`str`
189
        The activity's name
190
    type: :class:`~pincer.objects.events.presence.ActivityType`
191
        Activity type
192
    created_at: :class:`int`
193
        Unix timestamp (in milliseconds) of when
194
        the activity was added to the user's session
195
    url: APINullable[Optional[:class:`str`]]
196
        Stream url, is validated when type is 1
197
    timestamps: APINullable[:class:`~pincer.objects.events.presence.ActivityTimestamp`]
198
        Unix timestamps for start and/or end of the game
199
    application_id: APINullable[:class:`~pincer.utils.snowflake.Snowflake`]
200
        Application id for the game
201
    details: APINullable[Optional[:class:`str`]]
202
        What the player is currently doing
203
    state: APINullable[Optional[:class:`str`]]
204
        The user's current party status
205
    emoji: APINullable[Optional[:class:`~pincer.objects.events.presence.ActivityEmoji`]]
206
        The emoji used for a custom status
207
    party: APINullable[:class:`~pincer.objects.events.presence.ActivityParty`]
208
        Information for the current party of the player
209
    assets: APINullable[:class:`~pincer.objects.events.presence.ActivityAssets`]
210
        Images for the presence and their hover texts
211
    secrets: APINullable[:class:`~pincer.objects.events.presence.ActivitySecrets`]
212
        Secrets for Rich Presence joining and spectating
213
    instance: APINullable[:class:`bool`]
214
        "nether or not the activity is an instanced game session
215
    flags: APINullable[:class:`~pincer.objects.events.presence.ActivityFlags`]
216
        Activity flags ``OR``\\d together,
217
        describes what the payload includes
218
    buttons: APINullable[List[:class:`~pincer.objects.events.presence.ActivityButton`]]
219
        The url button on an activity.
220
    """
221
    # noqa: E501
222
    name: str
223
    type: ActivityType
224
    created_at: int
225
226
    url: APINullable[Optional[str]] = MISSING
227
    timestamps: APINullable[ActivityTimestamp] = MISSING
228
    application_id: APINullable[Snowflake] = MISSING
229
    details: APINullable[Optional[str]] = MISSING
230
    state: APINullable[Optional[str]] = MISSING
231
    emoji: APINullable[Optional[ActivityEmoji]] = MISSING
232
    party: APINullable[ActivityParty] = MISSING
233
    assets: APINullable[ActivityAssets] = MISSING
234
    secrets: APINullable[ActivitySecrets] = MISSING
235
    instance: APINullable[bool] = MISSING
236
    flags: APINullable[ActivityFlags] = MISSING
237
    buttons: APINullable[List[ActivityButton]] = MISSING
238
239
240
@dataclass(repr=False)
241
class ClientStatus(APIObject):
242
    """Active sessions are indicated with an "online",
243
    "idle", or "dnd" string per platform.
244
    If a user is offline or invisible, the corresponding
245
    field is not present.
246
247
    Attributes
248
    ----------
249
    desktop: APINullable[:class:`str`]
250
        The user's status set for an active desktop
251
        (Windows, Linux, Mac) application session
252
    mobile: APINullable[:class:`str`]
253
        The user's status set for an active mobile
254
        (iOS, Android) application session
255
    web: APINullable[:class:`str`]
256
        The user's status set for an active web
257
        (browser, bot account) application session
258
    """
259
    desktop: APINullable[str] = MISSING
260
    mobile: APINullable[str] = MISSING
261
    web: APINullable[str] = MISSING
262
263
264
@dataclass(repr=False)
265
class PresenceUpdateEvent(APIObject, GuildProperty):
266
    """This event is sent when a user's presence or info,
267
    such as name or avatar, is updated.
268
269
    Attributes
270
    ----------
271
    user: :class:`~pincer.objects.user.user.User`
272
        The user presence is being updated for
273
    guild_id: :class:`~pincer.utils.snowflake.Snowflake`
274
        Id of the guild
275
    status: :class:`str`
276
        Either "idle", "dnd", "online", or "offline"
277
    activities: List[:class:`~pincer.objects.events.presence.Activity`]
278
        User's current activities'
279
    client_status: :class:`~pincer.objects.events.presence.ClientStatus`
280
        User's platform-dependent status
281
    """
282
    user: User
283
    status: str
284
    activities: List[Activity]
285
    client_status: ClientStatus
286
    guild_id: APINullable[Snowflake] = MISSING
287