Skip to content

Commit

Permalink
Add platform property to Activity and Game
Browse files Browse the repository at this point in the history
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
  • Loading branch information
giginet and Rapptz committed Dec 10, 2023
1 parent 9b9c93a commit d9f8115
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class Activity(BaseActivity):
The user's current state. For example, "In Game".
details: Optional[:class:`str`]
The detail of the user's current activity.
platform: Optional[:class:`str`]
The user's current platform.
.. versionadded:: 2.4
timestamps: :class:`dict`
A dictionary of timestamps. It contains the following optional keys:
Expand Down Expand Up @@ -197,6 +201,7 @@ class Activity(BaseActivity):
'state',
'details',
'timestamps',
'platform',
'assets',
'party',
'flags',
Expand All @@ -215,6 +220,7 @@ def __init__(self, **kwargs: Any) -> None:
self.state: Optional[str] = kwargs.pop('state', None)
self.details: Optional[str] = kwargs.pop('details', None)
self.timestamps: ActivityTimestamps = kwargs.pop('timestamps', {})
self.platform: Optional[str] = kwargs.pop('platform', None)
self.assets: ActivityAssets = kwargs.pop('assets', {})
self.party: ActivityParty = kwargs.pop('party', {})
self.application_id: Optional[int] = _get_as_snowflake(kwargs, 'application_id')
Expand All @@ -238,6 +244,7 @@ def __repr__(self) -> str:
('type', self.type),
('name', self.name),
('url', self.url),
('platform', self.platform),
('details', self.details),
('application_id', self.application_id),
('session_id', self.session_id),
Expand Down Expand Up @@ -351,13 +358,30 @@ class Game(BaseActivity):
-----------
name: :class:`str`
The game's name.
platform: Optional[:class:`str`]
Where the user is playing from (ie. PS5, Xbox).
.. versionadded:: 2.4
assets: :class:`dict`
A dictionary representing the images and their hover text of a game.
It contains the following optional keys:
- ``large_image``: A string representing the ID for the large image asset.
- ``large_text``: A string representing the text when hovering over the large image asset.
- ``small_image``: A string representing the ID for the small image asset.
- ``small_text``: A string representing the text when hovering over the small image asset.
.. versionadded:: 2.4
"""

__slots__ = ('name', '_end', '_start')
__slots__ = ('name', '_end', '_start', 'platform', 'assets')

def __init__(self, name: str, **extra: Any) -> None:
super().__init__(**extra)
self.name: str = name
self.platform: Optional[str] = extra.get('platform')
self.assets: ActivityAssets = extra.get('assets', {}) or {}

try:
timestamps: ActivityTimestamps = extra['timestamps']
Expand Down Expand Up @@ -408,6 +432,8 @@ def to_dict(self) -> Dict[str, Any]:
'type': ActivityType.playing.value,
'name': str(self.name),
'timestamps': timestamps,
'platform': str(self.platform) if self.platform else None,
'assets': self.assets,
}

def __eq__(self, other: object) -> bool:
Expand Down
1 change: 1 addition & 0 deletions discord/types/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Activity(_BaseActivity, total=False):
state: Optional[str]
details: Optional[str]
timestamps: ActivityTimestamps
platform: Optional[str]
assets: ActivityAssets
party: ActivityParty
application_id: Snowflake
Expand Down

0 comments on commit d9f8115

Please sign in to comment.