Passed
Push — main ( 8be509...207edf )
by
unknown
01:42
created

pincer.objects.events.presence   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 298
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 79
dl 0
loc 298
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# MIT License
3
#
4
# Copyright (c) 2021 Pincer
5
#
6
# Permission is hereby granted, free of charge, to any person obtaining
7
# a copy of this software and associated documentation files
8
# (the "Software"), to deal in the Software without restriction,
9
# including without limitation the rights to use, copy, modify, merge,
10
# publish, distribute, sublicense, and/or sell copies of the Software,
11
# and to permit persons to whom the Software is furnished to do so,
12
# subject to the following conditions:
13
#
14
# The above copyright notice and this permission notice shall be
15
# included in all copies or substantial portions of the Software.
16
#
17
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
from dataclasses import dataclass
26
from enum import IntEnum
27
from typing import List, Optional, Tuple
28
29
from pincer.objects.user import User
30
from pincer.utils.api_object import APIObject
31
from pincer.utils.snowflake import Snowflake
32
from pincer.utils.types import MISSING, APINullable
33
34
35
class ActivityType(IntEnum):
36
    """
37
    :param GAME:
38
        Playing {name}
39
        e.g. "Playing Rocket League"
40
41
    :param STREAMING:
42
        Streaming {details}
43
        e.g. "Streaming Rocket League"
44
        Only supports Twitch and YouTube.
45
46
    :param LISTENING:
47
        Listening to {name}
48
        e.g. "Listening to Spotify"
49
50
    :param WATCHING:
51
        Watching {name}
52
        e.g. "Watching YouTube Together"
53
54
    :param CUSTOM:
55
        {emoji} {name}
56
        e.g. ":smiley: I am cool"
57
58
    :param COMPETING:
59
        Competing in {name}
60
        e.g. "Competing in Arena World Champions"
61
    """
62
    GAME = 0
63
    STREAMING = 1
64
    LISTENING = 2
65
    WATCHING = 3
66
    CUSTOM = 4
67
    COMPETING = 5
68
69
70
@dataclass
71
class ActivityTimestamp(APIObject):
72
    """
73
    :param start:
74
        unix time (in milliseconds) of when the activity started
75
76
    :param end:
77
        unix time (in milliseconds) of when the activity ends
78
    """
79
    start: APINullable[int] = MISSING
80
    end: APINullable[int] = MISSING
81
82
83
@dataclass
84
class ActivityEmoji(APIObject):
85
    """
86
    :param name:
87
        the name of the emoji
88
89
    :param id:
90
        the id of the emoji
91
92
    :param animated:
93
        whether this emoji is animated
94
    """
95
    name: str
96
    id: APINullable[Snowflake] = MISSING
97
    animated: APINullable[bool] = MISSING
98
99
100
@dataclass
101
class ActivityParty(APIObject):
102
    """
103
    :param id:
104
        the id of the party
105
106
    :param size:
107
        array of two integers (current_size, max_size)
108
    """
109
    id: APINullable[str] = MISSING
110
    size: APINullable[Tuple[int, int]] = MISSING
111
112
113
@dataclass
114
class ActivityAssets(APIObject):
115
    """
116
    :param large_image:
117
        the id for a large asset of the activity, usually a snowflake
118
119
    :param large_text:
120
        text displayed when hovering over
121
        the large image of the activity
122
123
    :param small_image:
124
        the id for a small asset of the activity, usually a snowflake
125
126
    :param small_text:
127
        text displayed when hovering over
128
        the small image of the activity
129
    """
130
    large_image: APINullable[str] = MISSING
131
    large_text: APINullable[str] = MISSING
132
    small_image: APINullable[str] = MISSING
133
    small_text: APINullable[str] = MISSING
134
135
136
@dataclass
137
class ActivitySecrets(APIObject):
138
    """
139
    :param join:
140
        the secret for joining a party
141
142
    :param spectate:
143
        the secret for spectating a game
144
145
    :param match:
146
        the secret for a specific instanced match
147
    """
148
    join: APINullable[str] = MISSING
149
    spectate: APINullable[str] = MISSING
150
    match_: APINullable[str] = MISSING
151
152
153
class ActivityFlags(IntEnum):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
154
    INSTANCE = 1 << 0
155
    JOIN = 1 << 1
156
    SPECTATE = 1 << 2
157
    JOIN_REQUEST = 1 << 3
158
    SYNC = 1 << 4
159
    PLAY = 1 << 5
160
161
162
@dataclass
163
class ActivityButton(APIObject):
164
    """
165
    When received over the gateway, the buttons field is an array
166
    of strings, which are the button labels. Bots cannot access
167
    a user's activity button URLs. When sending, the buttons field
168
    must be an array of this object.
169
170
    :param label:
171
        the text shown on the button (1-32 characters)
172
173
    :param url:
174
        the url opened when clicking the button (1-512 characters)
175
    """
176
    label: str
177
    url: str
178
179
180
@dataclass
0 ignored issues
show
best-practice introduced by
Too many instance attributes (15/7)
Loading history...
181
class Activity(APIObject):
182
    """
183
    Bots are only able to send `name`, `type`, and optionally `url`.
184
185
    :param name:
186
        the activity's name
187
188
    :param type:
189
        activity type
190
191
    :param url:
192
        stream url, is validated when type is 1
193
194
    :param created_at:
195
        unix timestamp (in milliseconds) of when
196
        the activity was added to the user's session
197
198
    :param timestamps:
199
        unix timestamps for start and/or end of the game
200
201
    :param application_id:
202
        application id for the game
203
204
    :param details:
205
        what the player is currently doing
206
207
    :param state:
208
        the user's current party status
209
210
    :param emoji:
211
        the emoji used for a custom status
212
213
    :param party:
214
        information for the current party of the player
215
216
    :param assets:
217
        images for the presence and their hover texts
218
219
    :param secrets:
220
        secrets for Rich Presence joining and spectating
221
222
    :param instance:
223
        whether or not the activity is an instanced game session
224
225
    :param flags:
226
        activity flags `OR`d together,
227
        describes what the payload includes
228
    """
229
    name: str
230
    type: ActivityType
231
    created_at: int
232
233
    url: APINullable[Optional[str]] = MISSING
234
    timestamps: APINullable[ActivityTimestamp] = MISSING
235
    application_id: APINullable[Snowflake] = MISSING
236
    details: APINullable[Optional[str]] = MISSING
237
    state: APINullable[Optional[str]] = MISSING
238
    emoji: APINullable[Optional[ActivityEmoji]] = MISSING
239
    party: APINullable[ActivityParty] = MISSING
240
    assets: APINullable[ActivityAssets] = MISSING
241
    secrets: APINullable[ActivitySecrets] = MISSING
242
    instance: APINullable[bool] = MISSING
243
    flags: APINullable[ActivityFlags] = MISSING
244
    buttons: APINullable[List[ActivityButton]] = MISSING
245
246
247
@dataclass
248
class ClientStatus(APIObject):
249
    """
250
    Active sessions are indicated with an "online",
251
    "idle", or "dnd" string per platform.
252
    If a user is offline or invisible, the corresponding
253
    field is not present.
254
255
    :param desktop:
256
        the user's status set for an active desktop
257
        (Windows, Linux, Mac) application session
258
259
    :param mobile:
260
        the user's status set for an active mobile
261
        (iOS, Android) application session
262
263
    :param web:
264
        the user's status set for an active web
265
        (browser, bot account) application session
266
    """
267
    desktop: APINullable[str] = MISSING
268
    mobile: APINullable[str] = MISSING
269
    web: APINullable[str] = MISSING
270
271
272
@dataclass
273
class PresenceUpdateEvent(APIObject):
274
    """
275
    This event is sent when a user's presence or info,
276
    such as name or avatar, is updated.
277
278
    :param user:
279
        the user presence is being updated for
280
281
    :param guild_id:
282
        id of the guild
283
284
    :param status:
285
        either "idle", "dnd", "online", or "offline"
286
287
    :param activities:
288
        user's current activities
289
290
    :param client_status:
291
        user's platform-dependent status
292
    """
293
    user: User
294
    guild_id: Snowflake
295
    status: str
296
    activities: List[Activity]
297
    client_status: ClientStatus
298