Browse Source

Implement embedded activity platform configs

pull/10109/head
dolfies 2 years ago
parent
commit
cc152c0892
  1. 129
      discord/application.py
  2. 20
      discord/enums.py
  3. 5
      discord/http.py
  4. 7
      discord/types/application.py
  5. 49
      docs/api.rst

129
discord/application.py

@ -25,19 +25,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations from __future__ import annotations
from datetime import datetime from datetime import datetime
from typing import ( from typing import TYPE_CHECKING, Any, AsyncIterator, Collection, List, Mapping, Optional, Sequence, Tuple, Union, overload
TYPE_CHECKING,
Any,
AsyncIterator,
Collection,
List,
Mapping,
Optional,
Sequence,
Tuple,
Union,
overload,
)
from urllib.parse import quote from urllib.parse import quote
from . import utils from . import utils
@ -51,8 +39,10 @@ from .enums import (
ApplicationType, ApplicationType,
ApplicationVerificationState, ApplicationVerificationState,
Distributor, Distributor,
EmbeddedActivityLabelType,
EmbeddedActivityOrientation, EmbeddedActivityOrientation,
EmbeddedActivityPlatform, EmbeddedActivityPlatform,
EmbeddedActivityReleasePhase,
Locale, Locale,
OperatingSystem, OperatingSystem,
RPCApplicationState, RPCApplicationState,
@ -72,6 +62,8 @@ from .utils import _bytes_to_base64_data, _parse_localizations
if TYPE_CHECKING: if TYPE_CHECKING:
from datetime import date from datetime import date
from typing_extensions import Self
from .abc import Snowflake, SnowflakeTime from .abc import Snowflake, SnowflakeTime
from .enums import SKUAccessLevel, SKUFeature, SKUGenre, SKUType from .enums import SKUAccessLevel, SKUFeature, SKUGenre, SKUType
from .file import File from .file import File
@ -92,6 +84,8 @@ if TYPE_CHECKING:
Build as BuildPayload, Build as BuildPayload,
Company as CompanyPayload, Company as CompanyPayload,
EmbeddedActivityConfig as EmbeddedActivityConfigPayload, EmbeddedActivityConfig as EmbeddedActivityConfigPayload,
EmbeddedActivityPlatform as EmbeddedActivityPlatformValues,
EmbeddedActivityPlatformConfig as EmbeddedActivityPlatformConfigPayload,
GlobalActivityStatistics as GlobalActivityStatisticsPayload, GlobalActivityStatistics as GlobalActivityStatisticsPayload,
Manifest as ManifestPayload, Manifest as ManifestPayload,
ManifestLabel as ManifestLabelPayload, ManifestLabel as ManifestLabelPayload,
@ -107,6 +101,7 @@ __all__ = (
'EULA', 'EULA',
'Achievement', 'Achievement',
'ThirdPartySKU', 'ThirdPartySKU',
'EmbeddedActivityPlatformConfig',
'EmbeddedActivityConfig', 'EmbeddedActivityConfig',
'ApplicationBot', 'ApplicationBot',
'ApplicationExecutable', 'ApplicationExecutable',
@ -436,6 +431,61 @@ class ThirdPartySKU:
return f'<ThirdPartySKU distributor={self.distributor!r} id={self.id!r} sku_id={self.sku_id!r}>' return f'<ThirdPartySKU distributor={self.distributor!r} id={self.id!r} sku_id={self.sku_id!r}>'
class EmbeddedActivityPlatformConfig:
"""Represents an application's embedded activity configuration for a specific platform.
.. versionadded:: 2.1
Attributes
-----------
platform: :class:`EmbeddedActivityPlatform`
The platform that the configuration is for.
label_type: :class:`EmbeddedActivityLabelType`
The current label shown on the activity.
label_until: Optional[:class:`datetime.datetime`]
When the current label expires.
release_phase: :class:`EmbeddedActivityReleasePhase`
The current release phase of the activity.
"""
__slots__ = ('platform', 'label_type', 'label_until', 'release_phase')
def __init__(
self,
platform: EmbeddedActivityPlatform,
*,
label_type: EmbeddedActivityLabelType = EmbeddedActivityLabelType.none,
label_until: Optional[datetime] = None,
release_phase: EmbeddedActivityReleasePhase = EmbeddedActivityReleasePhase.global_launch,
):
self.platform = platform
self.label_type = label_type
self.label_until = label_until
self.release_phase = release_phase
@classmethod
def from_data(cls, *, data: EmbeddedActivityPlatformConfigPayload, platform: EmbeddedActivityPlatformValues) -> Self:
return cls(
try_enum(EmbeddedActivityPlatform, platform),
label_type=try_enum(EmbeddedActivityLabelType, data.get('label_type', 0)),
label_until=utils.parse_time(data.get('label_until')),
release_phase=try_enum(EmbeddedActivityReleasePhase, data.get('release_phase', 'global_launch')),
)
def __repr__(self) -> str:
return (
f'<EmbeddedActivityPlatformConfig platform={self.platform!r} label_type={self.label_type!r} '
f'label_until={self.label_until!r} release_phase={self.release_phase!r}>'
)
def to_dict(self) -> EmbeddedActivityPlatformConfigPayload:
return {
'label_type': self.label_type.value,
'label_until': self.label_until.isoformat() if self.label_until else None,
'release_phase': self.release_phase.value,
}
class EmbeddedActivityConfig: class EmbeddedActivityConfig:
"""Represents an application's embedded activity configuration. """Represents an application's embedded activity configuration.
@ -447,6 +497,10 @@ class EmbeddedActivityConfig:
The application that the configuration is for. The application that the configuration is for.
supported_platforms: List[:class:`EmbeddedActivityPlatform`] supported_platforms: List[:class:`EmbeddedActivityPlatform`]
A list of platforms that the activity supports. A list of platforms that the activity supports.
platform_configs: List[:class:`EmbeddedActivityPlatformConfig`]
A list of configurations for each supported activity platform.
.. versionadded:: 2.1
orientation_lock_state: :class:`EmbeddedActivityOrientation` orientation_lock_state: :class:`EmbeddedActivityOrientation`
The mobile orientation lock state of the activity. The mobile orientation lock state of the activity.
tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation` tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation`
@ -466,6 +520,7 @@ class EmbeddedActivityConfig:
__slots__ = ( __slots__ = (
'application', 'application',
'supported_platforms', 'supported_platforms',
'platform_configs',
'orientation_lock_state', 'orientation_lock_state',
'tablet_orientation_lock_state', 'tablet_orientation_lock_state',
'premium_tier_requirement', 'premium_tier_requirement',
@ -487,6 +542,10 @@ class EmbeddedActivityConfig:
self.supported_platforms: List[EmbeddedActivityPlatform] = [ self.supported_platforms: List[EmbeddedActivityPlatform] = [
try_enum(EmbeddedActivityPlatform, platform) for platform in data.get('supported_platforms', []) try_enum(EmbeddedActivityPlatform, platform) for platform in data.get('supported_platforms', [])
] ]
self.platform_configs: List[EmbeddedActivityPlatformConfig] = [
EmbeddedActivityPlatformConfig.from_data(platform=platform, data=config)
for platform, config in data.get('client_platform_config', {}).items()
]
self.orientation_lock_state: EmbeddedActivityOrientation = try_enum( self.orientation_lock_state: EmbeddedActivityOrientation = try_enum(
EmbeddedActivityOrientation, data.get('default_orientation_lock_state', 0) EmbeddedActivityOrientation, data.get('default_orientation_lock_state', 0)
) )
@ -511,6 +570,7 @@ class EmbeddedActivityConfig:
self, self,
*, *,
supported_platforms: Collection[EmbeddedActivityPlatform] = MISSING, supported_platforms: Collection[EmbeddedActivityPlatform] = MISSING,
platform_configs: Collection[EmbeddedActivityPlatformConfig] = MISSING,
orientation_lock_state: EmbeddedActivityOrientation = MISSING, orientation_lock_state: EmbeddedActivityOrientation = MISSING,
tablet_orientation_lock_state: EmbeddedActivityOrientation = MISSING, tablet_orientation_lock_state: EmbeddedActivityOrientation = MISSING,
requires_age_gate: bool = MISSING, requires_age_gate: bool = MISSING,
@ -527,6 +587,10 @@ class EmbeddedActivityConfig:
----------- -----------
supported_platforms: List[:class:`EmbeddedActivityPlatform`] supported_platforms: List[:class:`EmbeddedActivityPlatform`]
A list of platforms that the activity supports. A list of platforms that the activity supports.
platform_configs: List[:class:`EmbeddedActivityPlatformConfig`]
A list of configurations for each supported activity platform.
.. versionadded:: 2.1
orientation_lock_state: :class:`EmbeddedActivityOrientation` orientation_lock_state: :class:`EmbeddedActivityOrientation`
The mobile orientation lock state of the activity. The mobile orientation lock state of the activity.
tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation` tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation`
@ -551,16 +615,21 @@ class EmbeddedActivityConfig:
""" """
data = await self.application._state.http.edit_embedded_activity_config( data = await self.application._state.http.edit_embedded_activity_config(
self.application.id, self.application.id,
supported_platforms=[str(x) for x in (supported_platforms or [])], supported_platforms=[str(x) for x in (supported_platforms)] if supported_platforms is not MISSING else None,
orientation_lock_state=int(orientation_lock_state), platform_config={c.platform.value: c.to_dict() for c in (platform_configs)}
tablet_orientation_lock_state=int(tablet_orientation_lock_state), if platform_configs is not MISSING
requires_age_gate=requires_age_gate, else None,
shelf_rank=shelf_rank, orientation_lock_state=int(orientation_lock_state) if orientation_lock_state is not MISSING else None,
tablet_orientation_lock_state=int(tablet_orientation_lock_state)
if tablet_orientation_lock_state is not MISSING
else None,
requires_age_gate=requires_age_gate if requires_age_gate is not MISSING else None,
shelf_rank=shelf_rank if shelf_rank is not MISSING else None,
free_period_starts_at=free_period_starts_at.isoformat() if free_period_starts_at else None, free_period_starts_at=free_period_starts_at.isoformat() if free_period_starts_at else None,
free_period_ends_at=free_period_ends_at.isoformat() if free_period_ends_at else None, free_period_ends_at=free_period_ends_at.isoformat() if free_period_ends_at else None,
preview_video_asset_id=(preview_video_asset.id if preview_video_asset else None) preview_video_asset_id=(preview_video_asset.id if preview_video_asset else None)
if preview_video_asset is not MISSING if preview_video_asset is not MISSING
else None, else MISSING,
) )
self._update(data) self._update(data)
@ -3387,6 +3456,7 @@ class Application(PartialApplication):
self, self,
*, *,
supported_platforms: Collection[EmbeddedActivityPlatform] = MISSING, supported_platforms: Collection[EmbeddedActivityPlatform] = MISSING,
platform_configs: Collection[EmbeddedActivityPlatformConfig] = MISSING,
orientation_lock_state: EmbeddedActivityOrientation = MISSING, orientation_lock_state: EmbeddedActivityOrientation = MISSING,
tablet_orientation_lock_state: EmbeddedActivityOrientation = MISSING, tablet_orientation_lock_state: EmbeddedActivityOrientation = MISSING,
requires_age_gate: bool = MISSING, requires_age_gate: bool = MISSING,
@ -3403,6 +3473,10 @@ class Application(PartialApplication):
----------- -----------
supported_platforms: List[:class:`EmbeddedActivityPlatform`] supported_platforms: List[:class:`EmbeddedActivityPlatform`]
A list of platforms that the activity supports. A list of platforms that the activity supports.
platform_configs: List[:class:`EmbeddedActivityPlatformConfig`]
A list of configurations for each supported activity platform.
.. versionadded:: 2.1
orientation_lock_state: :class:`EmbeddedActivityOrientation` orientation_lock_state: :class:`EmbeddedActivityOrientation`
The mobile orientation lock state of the activity. The mobile orientation lock state of the activity.
tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation` tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation`
@ -3432,16 +3506,21 @@ class Application(PartialApplication):
""" """
data = await self._state.http.edit_embedded_activity_config( data = await self._state.http.edit_embedded_activity_config(
self.id, self.id,
supported_platforms=[str(x) for x in (supported_platforms or [])], supported_platforms=[str(x) for x in (supported_platforms)] if supported_platforms is not MISSING else None,
orientation_lock_state=int(orientation_lock_state), platform_config={c.platform.value: c.to_dict() for c in (platform_configs)}
tablet_orientation_lock_state=int(tablet_orientation_lock_state), if platform_configs is not MISSING
requires_age_gate=requires_age_gate, else None,
shelf_rank=shelf_rank, orientation_lock_state=int(orientation_lock_state) if orientation_lock_state is not MISSING else None,
tablet_orientation_lock_state=int(tablet_orientation_lock_state)
if tablet_orientation_lock_state is not MISSING
else None,
requires_age_gate=requires_age_gate if requires_age_gate is not MISSING else None,
shelf_rank=shelf_rank if shelf_rank is not MISSING else None,
free_period_starts_at=free_period_starts_at.isoformat() if free_period_starts_at else None, free_period_starts_at=free_period_starts_at.isoformat() if free_period_starts_at else None,
free_period_ends_at=free_period_ends_at.isoformat() if free_period_ends_at else None, free_period_ends_at=free_period_ends_at.isoformat() if free_period_ends_at else None,
preview_video_asset_id=(preview_video_asset.id if preview_video_asset else None) preview_video_asset_id=(preview_video_asset.id if preview_video_asset else None)
if preview_video_asset is not MISSING if preview_video_asset is not MISSING
else None, else MISSING,
) )
if self.embedded_activity_config is not None: if self.embedded_activity_config is not None:
self.embedded_activity_config._update(data) self.embedded_activity_config._update(data)

20
discord/enums.py

@ -1009,6 +1009,26 @@ class EmbeddedActivityOrientation(Enum):
return self.value return self.value
class EmbeddedActivityLabelType(Enum):
none = 0
new = 1
updated = 2
def __int__(self) -> int:
return self.value
class EmbeddedActivityReleasePhase(Enum):
in_development = 'in_development'
activities_team = 'activities_team'
employee_release = 'employee_release'
soft_launch = 'soft_launch'
global_launch = 'global_launch'
def __str__(self) -> str:
return self.value
T = TypeVar('T') T = TypeVar('T')

5
discord/http.py

@ -3155,6 +3155,9 @@ class HTTPClient:
app_id: Snowflake, app_id: Snowflake,
*, *,
supported_platforms: Optional[List[str]] = None, supported_platforms: Optional[List[str]] = None,
platform_config: Optional[
Dict[application.EmbeddedActivityPlatform, application.EmbeddedActivityPlatformConfig]
] = None,
orientation_lock_state: Optional[int] = None, orientation_lock_state: Optional[int] = None,
tablet_orientation_lock_state: Optional[int] = None, tablet_orientation_lock_state: Optional[int] = None,
requires_age_gate: Optional[bool] = None, requires_age_gate: Optional[bool] = None,
@ -3166,6 +3169,8 @@ class HTTPClient:
payload = {} payload = {}
if supported_platforms is not None: if supported_platforms is not None:
payload['supported_platforms'] = supported_platforms payload['supported_platforms'] = supported_platforms
if platform_config is not None:
payload['client_platform_config'] = platform_config
if orientation_lock_state is not None: if orientation_lock_state is not None:
payload['default_orientation_lock_state'] = orientation_lock_state payload['default_orientation_lock_state'] = orientation_lock_state
if tablet_orientation_lock_state is not None: if tablet_orientation_lock_state is not None:

7
discord/types/application.py

@ -249,16 +249,15 @@ class GlobalActivityStatistics(TypedDict):
EmbeddedActivityPlatform = Literal['web', 'android', 'ios'] EmbeddedActivityPlatform = Literal['web', 'android', 'ios']
EmbeddedActivityPlatformLabelType = Literal[0, 1, 2] EmbeddedActivityPlatformReleasePhase = Literal[
EmbedddedActivityPlatformReleasePhase = Literal[
'in_development', 'activities_team', 'employee_release', 'soft_launch', 'global_launch' 'in_development', 'activities_team', 'employee_release', 'soft_launch', 'global_launch'
] ]
class EmbeddedActivityPlatformConfig(TypedDict): class EmbeddedActivityPlatformConfig(TypedDict):
label_type: EmbeddedActivityPlatformLabelType label_type: Literal[0, 1, 2]
label_until: Optional[str] label_until: Optional[str]
release_phase: EmbedddedActivityPlatformReleasePhase release_phase: EmbeddedActivityPlatformReleasePhase
class EmbeddedActivityConfig(TypedDict): class EmbeddedActivityConfig(TypedDict):

49
docs/api.rst

@ -3457,6 +3457,50 @@ of :class:`enum.Enum`.
The activity is locked to landscape. The activity is locked to landscape.
.. class:: EmbeddedActivityLabelType
Represents the label shown by an embedded activity.
.. versionadded:: 2.1
.. attribute:: none
No special label.
.. attribute:: new
The activity is new.
.. attribute:: updated
The activity has been recently updated.
.. class:: EmbeddedActivityReleasePhase
Represents the release phase of an embedded activity for a specific :class:`EmbeddedActivityPlatform`.
.. versionadded:: 2.1
.. attribute:: in_development
The activity is still in development.
.. attribute:: activities_team
The activity is available to guilds with the `ACTIVITIES_INTERNAL_DEV` guild feature.
.. attribute:: employee_release
The activity is available to guilds with the `ACTIVITIES_EMPLOYEE` guild feature.
.. attribute:: soft_launch
The activity is available to guilds with the `ACTIVITIES_ALPHA` guild feature.
.. attribute:: global_launch
The activity is available to all guilds.
.. class:: PayoutAccountStatus .. class:: PayoutAccountStatus
Represents the status of a team payout account. Represents the status of a team payout account.
@ -6765,6 +6809,11 @@ Application
.. autoclass:: EmbeddedActivityConfig() .. autoclass:: EmbeddedActivityConfig()
:members: :members:
.. attributetable:: EmbeddedActivityPlatformConfig
.. autoclass:: EmbeddedActivityPlatformConfig()
:members:
.. attributetable:: UnverifiedApplication .. attributetable:: UnverifiedApplication
.. autoclass:: UnverifiedApplication() .. autoclass:: UnverifiedApplication()

Loading…
Cancel
Save