Passed
Pull Request — main (#61)
by
unknown
01:33
created

pincer.objects.presence   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 286
Duplicated Lines 0 %

Importance

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