mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-08-11 14:02:13 +00:00
Add support for new RPC Activity fields
This commit is contained in:
parent
348c7d7873
commit
6e7fc133d1
@ -28,7 +28,7 @@ import datetime
|
||||
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Union, overload
|
||||
|
||||
from .asset import Asset
|
||||
from .enums import ActivityType, try_enum
|
||||
from .enums import ActivityType, StatusDisplayType, try_enum
|
||||
from .colour import Colour
|
||||
from .partial_emoji import PartialEmoji
|
||||
from .utils import _get_as_snowflake
|
||||
@ -180,8 +180,10 @@ class Activity(BaseActivity):
|
||||
|
||||
- ``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.
|
||||
- ``large_url``: A string representing the URL of 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.
|
||||
- ``small_url``: A string representing the URL of the small image asset.
|
||||
|
||||
party: :class:`dict`
|
||||
A dictionary representing the activity party. It contains the following optional keys:
|
||||
@ -195,6 +197,19 @@ class Activity(BaseActivity):
|
||||
|
||||
emoji: Optional[:class:`PartialEmoji`]
|
||||
The emoji that belongs to this activity.
|
||||
details_url: Optional[:class:`str`]
|
||||
A URL that is linked to when clicking on the details text of the activity.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
state_url: Optional[:class:`str`]
|
||||
A URL that is linked to when clicking on the state text of the activity.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
status_display_type: Optional[:class:`StatusDisplayType`]
|
||||
Determines which field from the user's status text is displayed
|
||||
in the members list.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
@ -213,6 +228,9 @@ class Activity(BaseActivity):
|
||||
'application_id',
|
||||
'emoji',
|
||||
'buttons',
|
||||
'state_url',
|
||||
'details_url',
|
||||
'status_display_type',
|
||||
)
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
@ -239,6 +257,18 @@ class Activity(BaseActivity):
|
||||
emoji = kwargs.pop('emoji', None)
|
||||
self.emoji: Optional[PartialEmoji] = PartialEmoji.from_dict(emoji) if emoji is not None else None
|
||||
|
||||
self.state_url: Optional[str] = kwargs.pop('state_url')
|
||||
self.details_url: Optional[str] = kwargs.pop('details_url')
|
||||
|
||||
status_display_type = kwargs.pop('status_display_type', None)
|
||||
self.status_display_type: Optional[StatusDisplayType] = (
|
||||
status_display_type
|
||||
if isinstance(status_display_type, StatusDisplayType)
|
||||
else try_enum(StatusDisplayType, status_display_type)
|
||||
if status_display_type is not None
|
||||
else None
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
attrs = (
|
||||
('type', self.type),
|
||||
@ -267,6 +297,8 @@ class Activity(BaseActivity):
|
||||
ret['type'] = int(self.type)
|
||||
if self.emoji:
|
||||
ret['emoji'] = self.emoji.to_dict()
|
||||
if self.status_display_type:
|
||||
ret['status_display_type'] = int(self.status_display_type.value)
|
||||
return ret
|
||||
|
||||
@property
|
||||
|
@ -78,6 +78,7 @@ __all__ = (
|
||||
'VoiceChannelEffectAnimationType',
|
||||
'SubscriptionStatus',
|
||||
'MessageReferenceType',
|
||||
'StatusDisplayType',
|
||||
)
|
||||
|
||||
|
||||
@ -914,6 +915,12 @@ class SubscriptionStatus(Enum):
|
||||
inactive = 2
|
||||
|
||||
|
||||
class StatusDisplayType(Enum):
|
||||
name = 0 # pyright: ignore[reportAssignmentType]
|
||||
state = 1
|
||||
details = 2
|
||||
|
||||
|
||||
def create_unknown_value(cls: Type[E], val: Any) -> E:
|
||||
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
|
||||
name = f'unknown_{val}'
|
||||
|
@ -31,6 +31,7 @@ from .snowflake import Snowflake
|
||||
|
||||
|
||||
StatusType = Literal['idle', 'dnd', 'online', 'offline']
|
||||
StatusDisplayType = Literal[0, 1, 2]
|
||||
|
||||
|
||||
class PartialPresenceUpdate(TypedDict):
|
||||
@ -62,6 +63,8 @@ class ActivityAssets(TypedDict, total=False):
|
||||
large_text: str
|
||||
small_image: str
|
||||
small_text: str
|
||||
large_url: str
|
||||
small_url: str
|
||||
|
||||
|
||||
class ActivitySecrets(TypedDict, total=False):
|
||||
@ -104,3 +107,6 @@ class Activity(_BaseActivity, total=False):
|
||||
instance: bool
|
||||
buttons: List[str]
|
||||
sync_id: str
|
||||
state_url: str
|
||||
details_url: str
|
||||
status_display_type: Optional[StatusDisplayType]
|
||||
|
19
docs/api.rst
19
docs/api.rst
@ -3898,6 +3898,25 @@ of :class:`enum.Enum`.
|
||||
|
||||
An alias for :attr:`.default`.
|
||||
|
||||
.. class:: StatusDisplayType
|
||||
|
||||
Represents which field is of the user's activity is
|
||||
displayed in the members list.
|
||||
|
||||
.. versionadded:: 2.6
|
||||
|
||||
.. attribute:: name
|
||||
|
||||
The name of the activity is displayed.
|
||||
|
||||
.. attribute:: state
|
||||
|
||||
The state of the activity is displayed.
|
||||
|
||||
.. attribute:: details
|
||||
|
||||
The details of the activity are displayed.
|
||||
|
||||
.. _discord-api-audit-logs:
|
||||
|
||||
Audit Log Data
|
||||
|
Loading…
x
Reference in New Issue
Block a user