From 4828355f9ea4be18abad7067217236a90d0e22ba Mon Sep 17 00:00:00 2001 From: Andrin S <65789180+Puncher1@users.noreply.github.com> Date: Thu, 30 Mar 2023 14:37:34 +0200 Subject: [PATCH] Change and add params in AppInfo and PartialAppInfo --- discord/appinfo.py | 42 +++++++++++++++++++++++++++++++++++++++- discord/client.py | 2 -- discord/types/appinfo.py | 17 ++++++++-------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/discord/appinfo.py b/discord/appinfo.py index 18c97228b..129e543cb 100644 --- a/discord/appinfo.py +++ b/discord/appinfo.py @@ -166,7 +166,7 @@ class AppInfo: self.name: str = data['name'] self.description: str = data['description'] self._icon: Optional[str] = data['icon'] - self.rpc_origins: List[str] = data['rpc_origins'] + self.rpc_origins: Optional[List[str]] = data.get('rpc_origins') self.bot_public: bool = data['bot_public'] self.bot_require_code_grant: bool = data['bot_require_code_grant'] self.owner: User = state.create_user(data['owner']) @@ -255,6 +255,24 @@ class PartialAppInfo: The application's terms of service URL, if set. privacy_policy_url: Optional[:class:`str`] The application's privacy policy URL, if set. + approximate_guild_count: :class:`int` + The approximate count of the guilds the bot was added to. + + .. versionadded:: 2.3 + redirect_uris: List[:class:`str`] + A list of authentication redirect URIs. + + .. versionadded:: 2.3 + interactions_endpoint_url: Optional[:class:`str`] + The interactions endpoint url of the application to receive interactions over this endpoint rather than + over the gateway, if configured. + + .. versionadded:: 2.3 + role_connections_verification_url: Optional[:class:`str`] + The application's connection verification URL which will render the application as + a verification method in the guild's role verification configuration. + + .. versionadded:: 2.3 """ __slots__ = ( @@ -268,6 +286,11 @@ class PartialAppInfo: 'privacy_policy_url', '_icon', '_flags', + '_cover_image', + 'approximate_guild_count', + 'redirect_uris', + 'interactions_endpoint_url', + 'role_connections_verification_url', ) def __init__(self, *, state: ConnectionState, data: PartialAppInfoPayload): @@ -276,11 +299,16 @@ class PartialAppInfo: self.name: str = data['name'] self._icon: Optional[str] = data.get('icon') self._flags: int = data.get('flags', 0) + self._cover_image: Optional[str] = data.get('cover_image') self.description: str = data['description'] self.rpc_origins: Optional[List[str]] = data.get('rpc_origins') self.verify_key: str = data['verify_key'] self.terms_of_service_url: Optional[str] = data.get('terms_of_service_url') self.privacy_policy_url: Optional[str] = data.get('privacy_policy_url') + self.approximate_guild_count: int = data.get('approximate_guild_count', 0) + self.redirect_uris: List[str] = data.get('redirect_uris', []) + self.interactions_endpoint_url: Optional[str] = data.get('interactions_endpoint_url') + self.role_connections_verification_url: Optional[str] = data.get('role_connections_verification_url') def __repr__(self) -> str: return f'<{self.__class__.__name__} id={self.id} name={self.name!r} description={self.description!r}>' @@ -292,6 +320,18 @@ class PartialAppInfo: return None return Asset._from_icon(self._state, self.id, self._icon, path='app') + @property + def cover_image(self) -> Optional[Asset]: + """Optional[:class:`.Asset`]: Retrieves the cover image of the application's default rich presence. + + This is only available if the application is a game sold on Discord. + + .. versionadded:: 2.3 + """ + if self._cover_image is None: + return None + return Asset._from_cover_image(self._state, self.id, self._cover_image) + @property def flags(self) -> ApplicationFlags: """:class:`ApplicationFlags`: The application's flags. diff --git a/discord/client.py b/discord/client.py index a3b76b32a..298959b21 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2486,8 +2486,6 @@ class Client: The bot's application information. """ data = await self.http.application_info() - if 'rpc_origins' not in data: - data['rpc_origins'] = None return AppInfo(self._connection, data) async def fetch_user(self, user_id: int, /) -> User: diff --git a/discord/types/appinfo.py b/discord/types/appinfo.py index 640fe1be7..87bafc6d2 100644 --- a/discord/types/appinfo.py +++ b/discord/types/appinfo.py @@ -44,10 +44,14 @@ class BaseAppInfo(TypedDict): icon: Optional[str] summary: str description: str + flags: int + cover_image: NotRequired[str] + terms_of_service_url: NotRequired[str] + privacy_policy_url: NotRequired[str] + rpc_origins: NotRequired[List[str]] class AppInfo(BaseAppInfo): - rpc_origins: List[str] owner: User bot_public: bool bot_require_code_grant: bool @@ -55,8 +59,6 @@ class AppInfo(BaseAppInfo): guild_id: NotRequired[Snowflake] primary_sku_id: NotRequired[Snowflake] slug: NotRequired[str] - terms_of_service_url: NotRequired[str] - privacy_policy_url: NotRequired[str] hook: NotRequired[bool] max_participants: NotRequired[int] tags: NotRequired[List[str]] @@ -66,13 +68,12 @@ class AppInfo(BaseAppInfo): class PartialAppInfo(BaseAppInfo, total=False): - rpc_origins: List[str] - cover_image: str hook: bool - terms_of_service_url: str - privacy_policy_url: str max_participants: int - flags: int + approximate_guild_count: int + redirect_uris: List[str] + interactions_endpoint_url: Optional[str] + role_connections_verification_url: Optional[str] class GatewayAppInfo(TypedDict):