Skip to content

Commit a7c85b4

Browse files
committed
Add support for new RPC fields
discord/discord-api-docs#7674
1 parent a005109 commit a7c85b4

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

discord/activity.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union, overload
2929

3030
from .asset import Asset
31-
from .enums import ActivityType, try_enum
31+
from .enums import ActivityType, StatusDisplayType, try_enum
3232
from .colour import Colour
3333
from .partial_emoji import PartialEmoji
3434
from .utils import _get_as_snowflake
@@ -180,8 +180,10 @@ class Activity(BaseActivity):
180180
181181
- ``large_image``: A string representing the ID for the large image asset.
182182
- ``large_text``: A string representing the text when hovering over the large image asset.
183+
- ``large_url``: A string representing the URL of the large image asset.
183184
- ``small_image``: A string representing the ID for the small image asset.
184185
- ``small_text``: A string representing the text when hovering over the small image asset.
186+
- ``small_url``: A string representing the URL of the small image asset.
185187
186188
party: :class:`dict`
187189
A dictionary representing the activity party. It contains the following optional keys:
@@ -195,6 +197,19 @@ class Activity(BaseActivity):
195197
196198
emoji: Optional[:class:`PartialEmoji`]
197199
The emoji that belongs to this activity.
200+
details_url: Optional[:class:`str`]
201+
A URL that is linked to when clicking on the details text of the activity.
202+
203+
... versionadded:: 2.6
204+
state_url: Optional[:class:`str`]
205+
A URL that is linked to when clicking on the state text of the activity.
206+
207+
... versionadded:: 2.6
208+
status_display_type: Optional[:class:`StatusDisplayType`]
209+
Determines which field from the user's status text is displayed
210+
in the members list.
211+
212+
.. versionadded:: 2.6
198213
"""
199214

200215
__slots__ = (
@@ -213,6 +228,9 @@ class Activity(BaseActivity):
213228
'application_id',
214229
'emoji',
215230
'buttons',
231+
'state_url',
232+
'details_url',
233+
'status_display_type',
216234
)
217235

218236
def __init__(self, **kwargs: Any) -> None:
@@ -239,6 +257,16 @@ def __init__(self, **kwargs: Any) -> None:
239257
emoji = kwargs.pop('emoji', None)
240258
self.emoji: Optional[PartialEmoji] = PartialEmoji.from_dict(emoji) if emoji is not None else None
241259

260+
self.state_url: Optional[str] = kwargs.pop('state_url')
261+
self.details_url: Optional[str] = kwargs.pop('details_url')
262+
263+
status_display_type = kwargs.pop('status_display_type', None)
264+
self.status_display_type: Optional[StatusDisplayType] = (
265+
status_display_type
266+
if isinstance(status_display_type, StatusDisplayType)
267+
else try_enum(StatusDisplayType, status_display_type)
268+
)
269+
242270
def __repr__(self) -> str:
243271
attrs = (
244272
('type', self.type),
@@ -255,11 +283,15 @@ def __repr__(self) -> str:
255283

256284
def to_dict(self) -> Dict[str, Any]:
257285
ret: Dict[str, Any] = {}
286+
enums = ('status_display_type',)
258287
for attr in self.__slots__:
259288
value = getattr(self, attr, None)
260289
if value is None:
261290
continue
262291

292+
if attr in enums:
293+
value = int(value.value)
294+
263295
if isinstance(value, dict) and len(value) == 0:
264296
continue
265297

discord/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
'VoiceChannelEffectAnimationType',
7979
'SubscriptionStatus',
8080
'MessageReferenceType',
81+
'StatusDisplayType',
8182
)
8283

8384

@@ -912,6 +913,12 @@ class SubscriptionStatus(Enum):
912913
inactive = 2
913914

914915

916+
class StatusDisplayType(Enum):
917+
NAME = 0
918+
STATE = 1
919+
DETAILS = 2
920+
921+
915922
def create_unknown_value(cls: Type[E], val: Any) -> E:
916923
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
917924
name = f'unknown_{val}'

discord/types/activity.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232

3333
StatusType = Literal['idle', 'dnd', 'online', 'offline']
34+
StatusDisplayType = Literal[0, 1, 2]
3435

3536

3637
class PartialPresenceUpdate(TypedDict):
@@ -62,6 +63,8 @@ class ActivityAssets(TypedDict, total=False):
6263
large_text: str
6364
small_image: str
6465
small_text: str
66+
large_url: str
67+
small_url: str
6568

6669

6770
class ActivitySecrets(TypedDict, total=False):
@@ -104,3 +107,6 @@ class Activity(_BaseActivity, total=False):
104107
instance: bool
105108
buttons: List[str]
106109
sync_id: str
110+
state_url: str
111+
details_url: str
112+
status_display_type: Optional[StatusDisplayType]

docs/api.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,6 +3881,25 @@ of :class:`enum.Enum`.
38813881

38823882
An alias for :attr:`.default`.
38833883

3884+
.. class:: StatusDisplayType
3885+
3886+
Represents which field is of the user's activity is
3887+
displayed in the members list.
3888+
3889+
.. versionadded:: 2.6
3890+
3891+
.. attribute:: NAME
3892+
3893+
The name of the activity is displayed.
3894+
3895+
.. attribute:: STATE
3896+
3897+
The state of the activity is displayed.
3898+
3899+
.. attribute:: DETAILS
3900+
3901+
The details of the activity are displayed.
3902+
38843903
.. _discord-api-audit-logs:
38853904

38863905
Audit Log Data

0 commit comments

Comments
 (0)