From aa51ced65c9d6916f070db3da1ddc637dfe5321c Mon Sep 17 00:00:00 2001 From: dolfies Date: Sat, 25 Mar 2023 22:35:26 -0400 Subject: [PATCH] Add new EmbeddedActivityConfig fields --- discord/application.py | 68 ++++++++++++++++++++++++++++++------ discord/http.py | 34 ++++++++++++++---- discord/types/application.py | 20 +++++++++-- 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/discord/application.py b/discord/application.py index a61374a06..2f466a435 100644 --- a/discord/application.py +++ b/discord/application.py @@ -440,16 +440,33 @@ class EmbeddedActivityConfig: application: :class:`PartialApplication` The application that the configuration is for. supported_platforms: List[:class:`EmbeddedActivityPlatform`] - A list of platforms that the application supports. + A list of platforms that the activity supports. orientation_lock_state: :class:`EmbeddedActivityOrientation` - The mobile orientation lock state of the application. + The mobile orientation lock state of the activity. + tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation` + The mobile orientation lock state of the activity on tablets. + premium_tier_requirement: :class:`int` + The guild premium tier required to use the activity. + requires_age_gate: :class:`bool` + Whether the activity should be blocked from underage users. + shelf_rank: :class:`int` + The sorting rank of the activity in the activity shelf. + free_period_starts_at: Optional[:class:`datetime.datetime`] + When the activity's free availability period starts. + free_period_ends_at: Optional[:class:`datetime.datetime`] + When the activity's free availability period ends. """ __slots__ = ( 'application', 'supported_platforms', 'orientation_lock_state', - 'premium_tier_level', + 'tablet_orientation_lock_state', + 'premium_tier_requirement', + 'requires_age_gate', + 'shelf_rank', + 'free_period_starts_at', + 'free_period_ends_at', '_preview_video_asset_id', ) @@ -457,6 +474,9 @@ class EmbeddedActivityConfig: self.application: PartialApplication = application self._update(data) + def __repr__(self) -> str: + return f'' + def _update(self, data: EmbeddedActivityConfigPayload) -> None: self.supported_platforms: List[EmbeddedActivityPlatform] = [ try_enum(EmbeddedActivityPlatform, platform) for platform in data.get('supported_platforms', []) @@ -464,22 +484,33 @@ class EmbeddedActivityConfig: self.orientation_lock_state: EmbeddedActivityOrientation = try_enum( EmbeddedActivityOrientation, data.get('default_orientation_lock_state', 0) ) - self.premium_tier_level: int = data.get('activity_premium_tier_level', 0) + self.tablet_orientation_lock_state: EmbeddedActivityOrientation = try_enum( + EmbeddedActivityOrientation, data.get('tablet_default_orientation_lock_state', 0) + ) + self.premium_tier_requirement: int = data.get('premium_tier_requirement') or 0 + self.requires_age_gate: bool = data.get('requires_age_gate', False) + self.shelf_rank: int = data.get('shelf_rank', 0) + self.free_period_starts_at: Optional[datetime] = utils.parse_time(data.get('free_period_starts_at')) + self.free_period_ends_at: Optional[datetime] = utils.parse_time(data.get('free_period_ends_at')) self._preview_video_asset_id = utils._get_as_snowflake(data, 'preview_video_asset_id') @property def preview_video_asset(self) -> Optional[ApplicationAsset]: - """Optional[:class:`ApplicationAsset`]: The preview video asset of the embedded activity, if available.""" + """Optional[:class:`ApplicationAsset`]: The preview video asset of the activity, if available.""" if self._preview_video_asset_id is None: return None - app = self.application - return ApplicationAsset._from_embedded_activity_config(app, self._preview_video_asset_id) + return ApplicationAsset._from_embedded_activity_config(self.application, self._preview_video_asset_id) async def edit( self, *, - supported_platforms: List[EmbeddedActivityPlatform] = MISSING, + supported_platforms: Collection[EmbeddedActivityPlatform] = MISSING, orientation_lock_state: EmbeddedActivityOrientation = MISSING, + tablet_orientation_lock_state: EmbeddedActivityOrientation = MISSING, + requires_age_gate: bool = MISSING, + shelf_rank: int = MISSING, + free_period_starts_at: Optional[datetime] = MISSING, + free_period_ends_at: Optional[datetime] = MISSING, preview_video_asset: Optional[Snowflake] = MISSING, ) -> None: """|coro| @@ -489,11 +520,21 @@ class EmbeddedActivityConfig: Parameters ----------- supported_platforms: List[:class:`EmbeddedActivityPlatform`] - A list of platforms that the application supports. + A list of platforms that the activity supports. orientation_lock_state: :class:`EmbeddedActivityOrientation` - The mobile orientation lock state of the application. + The mobile orientation lock state of the activity. + tablet_orientation_lock_state: :class:`EmbeddedActivityOrientation` + The mobile orientation lock state of the activity on tablets. + requires_age_gate: :class:`bool` + Whether the activity should be blocked from underage users. + shelf_rank: :class:`int` + The sorting rank of the activity in the activity shelf. + free_period_starts_at: Optional[:class:`datetime.datetime`] + When the activity's free availability period starts. + free_period_ends_at: Optional[:class:`datetime.datetime`] + When the activity's free availability period ends. preview_video_asset: Optional[:class:`ApplicationAsset`] - The preview video asset of the embedded activity. + The preview video asset of the activity. Raises ------- @@ -506,6 +547,11 @@ class EmbeddedActivityConfig: self.application.id, supported_platforms=[str(x) for x in (supported_platforms or [])], orientation_lock_state=int(orientation_lock_state), + tablet_orientation_lock_state=int(tablet_orientation_lock_state), + requires_age_gate=requires_age_gate, + shelf_rank=shelf_rank, + 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, preview_video_asset_id=(preview_video_asset.id if preview_video_asset else None) if preview_video_asset is not MISSING else None, diff --git a/discord/http.py b/discord/http.py index 7abaa1743..d8f39d3cb 100644 --- a/discord/http.py +++ b/discord/http.py @@ -53,8 +53,6 @@ import weakref import aiohttp -from .types import application - from .enums import RelationshipAction, InviteType from .errors import HTTPException, Forbidden, NotFound, LoginFailure, DiscordServerError, CaptchaRequired from .file import File @@ -87,6 +85,7 @@ if TYPE_CHECKING: from .embeds import Embed from .types import ( + application, audit_log, billing, channel, @@ -2389,7 +2388,9 @@ class HTTPClient: def get_partial_application(self, app_id: Snowflake) -> Response[application.PartialApplication]: return self.request(Route('GET', '/oauth2/applications/{app_id}/rpc', app_id=app_id)) - def get_public_application(self, app_id: Snowflake, with_guild: bool = False) -> Response[application.PartialApplication]: + def get_public_application( + self, app_id: Snowflake, with_guild: bool = False + ) -> Response[application.PartialApplication]: params = {'with_guild': str(with_guild).lower()} return self.request(Route('GET', '/applications/{app_id}/public', app_id=app_id), params=params) @@ -2541,6 +2542,11 @@ class HTTPClient: *, supported_platforms: Optional[List[str]] = None, orientation_lock_state: Optional[int] = None, + tablet_orientation_lock_state: Optional[int] = None, + requires_age_gate: Optional[bool] = None, + shelf_rank: Optional[int] = None, + free_period_starts_at: Optional[str] = None, + free_period_ends_at: Optional[str] = None, preview_video_asset_id: Optional[Snowflake] = MISSING, ) -> Response[application.EmbeddedActivityConfig]: payload = {} @@ -2548,6 +2554,16 @@ class HTTPClient: payload['supported_platforms'] = supported_platforms if orientation_lock_state is not None: payload['default_orientation_lock_state'] = orientation_lock_state + if tablet_orientation_lock_state is not None: + payload['default_tablet_orientation_lock_state'] = tablet_orientation_lock_state + if requires_age_gate is not None: + payload['requires_age_gate'] = requires_age_gate + if shelf_rank is not None: + payload['shelf_rank'] = shelf_rank + if free_period_starts_at is not None: + payload['free_period_starts_at'] = free_period_starts_at + if free_period_ends_at is not None: + payload['free_period_ends_at'] = free_period_ends_at if preview_video_asset_id is not MISSING: payload['activity_preview_video_asset_id'] = preview_video_asset_id @@ -2562,7 +2578,9 @@ class HTTPClient: Route('GET', '/oauth2/applications/{app_id}/allowlist', app_id=app_id), super_properties_to_track=True ) - def add_app_whitelist(self, app_id: Snowflake, username: str, discriminator: str) -> Response[application.WhitelistedUser]: + def add_app_whitelist( + self, app_id: Snowflake, username: str, discriminator: str + ) -> Response[application.WhitelistedUser]: payload = {'username': username, 'discriminator': discriminator} return self.request( @@ -2815,7 +2833,9 @@ class HTTPClient: return self.request(Route('POST', '/branches'), json=payload) - def create_branch_build(self, app_id: Snowflake, branch_id: Snowflake, payload: dict) -> Response[application.CreatedBuild]: + def create_branch_build( + self, app_id: Snowflake, branch_id: Snowflake, payload: dict + ) -> Response[application.CreatedBuild]: return self.request( Route('POST', '/applications/{app_id}/branches/{branch_id}/builds', app_id=app_id, branch_id=branch_id), json=payload, @@ -3229,7 +3249,9 @@ class HTTPClient: super_properties_to_track=True, ) - def edit_achievement(self, app_id: Snowflake, achievement_id: Snowflake, payload: dict) -> Response[application.Achievement]: + def edit_achievement( + self, app_id: Snowflake, achievement_id: Snowflake, payload: dict + ) -> Response[application.Achievement]: return self.request( Route( 'PATCH', '/applications/{app_id}/achievements/{achievement_id}', app_id=app_id, achievement_id=achievement_id diff --git a/discord/types/application.py b/discord/types/application.py index 271097c25..f676fb1f2 100644 --- a/discord/types/application.py +++ b/discord/types/application.py @@ -212,10 +212,26 @@ class GlobalActivityStatistics(TypedDict): updated_at: str +EmbeddedActivityPlatform = Literal['web', 'android', 'ios'] + + +class ClientPlatformConfig(TypedDict): + label_type: int + label_until: Optional[str] + release_phase: str + + class EmbeddedActivityConfig(TypedDict): - supported_platforms: List[Literal['web', 'android', 'ios']] - default_orientation_lock_state: Literal[1, 2, 3] activity_preview_video_asset_id: NotRequired[Optional[Snowflake]] + client_platform_config: Dict[EmbeddedActivityPlatform, ClientPlatformConfig] + default_orientation_lock_state: Literal[1, 2, 3] + tablet_default_orientation_lock_state: Literal[1, 2, 3] + free_period_ends_at: NotRequired[Optional[str]] + free_period_starts_at: NotRequired[Optional[str]] + premium_tier_requirement: NotRequired[Optional[Literal[1, 2, 3]]] + requires_age_gate: bool + shelf_rank: int + supported_platforms: List[EmbeddedActivityPlatform] class ActiveDeveloperWebhook(TypedDict):