From 31f5e12e1ae5fc8522842b099e55cfcd00032a53 Mon Sep 17 00:00:00 2001 From: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:29:34 -0700 Subject: [PATCH] feat: add missing AppInfo attributes (#2520) * feat: add missing AppInfo attributes * fix: add `install_params` to slots * docs: add related documentation * style(pre-commit): auto fixes from pre-commit.com hooks * fix: typing * docs: fix spacing * style(pre-commit): auto fixes from pre-commit.com hooks * fix: add AppInstallParams to `__all__` * fix: invalid scopes typehint * fix: docs types formatting * docs: add changelog entry * style(pre-commit): auto fixes from pre-commit.com hooks * feat: deprecate `AppInfo.summary` * style(pre-commit): auto fixes from pre-commit.com hooks * docs: fix changelog to adhere to conventions * fix: properly deprecate `summary` * docs: fix `tags` typing * style(pre-commit): auto fixes from pre-commit.com hooks * docs: fix summary formatting --------- Signed-off-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil --- CHANGELOG.md | 22 ++++--- discord/appinfo.py | 117 ++++++++++++++++++++++++++++++++-- discord/types/appinfo.py | 5 ++ docs/api/application_info.rst | 5 ++ 4 files changed, 134 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6a54ee88..ef3e6995ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,17 @@ These changes are available on the `master` branch, but have not yet been releas ⚠️ **This Version Removes Support For Python 3.8** ⚠️ +### Added + +- Added `Guild.fetch_role` method. + ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) +- Added the following `AppInfo` attributes: `approximate_guild_count`, + `approximate_user_install_count`, `custom_install_url`, `install_params`, + `interactions_endpoint_url`, `redirect_uris`, `role_connections_verification_url`, and + `tags`. ([#2520](https://github.com/Pycord-Development/pycord/pull/2520)) +- Added `Member.guild_banner` and `Member.display_banner` properties. + ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) + ### Changed - Renamed `cover` property of `ScheduledEvent` and `cover` argument of @@ -20,20 +31,15 @@ These changes are available on the `master` branch, but have not yet been releas - ⚠️ **This Version Removes Support For Python 3.8** ⚠️ ([#2521](https://github.com/Pycord-Development/pycord/pull/2521)) -### Added +### Deprecated -- Added `Guild.fetch_role` method. - ([#2528](https://github.com/Pycord-Development/pycord/pull/2528)) -- Added `Member.guild_banner` and `Member.display_banner` properties. - ([#2556](https://github.com/Pycord-Development/pycord/pull/2556)) +- Deprecated `AppInfo.summary` in favor of `AppInfo.description`. + ([#2520](https://github.com/Pycord-Development/pycord/pull/2520)) ### Fixed - Fixed `EntitlementIterator` behavior with `limit > 100`. ([#2555](https://github.com/Pycord-Development/pycord/pull/2555)) - -### Fixed - - Fixed missing `stacklevel` parameter in `warn_deprecated` function call inside `@utils.deprecated`. ([#2500](https://github.com/Pycord-Development/pycord/pull/2500)) - Fixed the typehint in `ConnectionState._polls` to reflect actual behavior, changing it diff --git a/discord/appinfo.py b/discord/appinfo.py index 9554c96b5d..034b1bb158 100644 --- a/discord/appinfo.py +++ b/discord/appinfo.py @@ -29,11 +29,13 @@ from . import utils from .asset import Asset +from .permissions import Permissions if TYPE_CHECKING: from .guild import Guild from .state import ConnectionState from .types.appinfo import AppInfo as AppInfoPayload + from .types.appinfo import AppInstallParams as AppInstallParamsPayload from .types.appinfo import PartialAppInfo as PartialAppInfoPayload from .types.appinfo import Team as TeamPayload from .user import User @@ -41,6 +43,7 @@ __all__ = ( "AppInfo", "PartialAppInfo", + "AppInstallParams", ) @@ -70,11 +73,6 @@ class AppInfo: grant flow to join. rpc_origins: Optional[List[:class:`str`]] A list of RPC origin URLs, if RPC is enabled. - summary: :class:`str` - If this application is a game sold on Discord, - this field will be the summary field for the store page of its primary SKU. - - .. versionadded:: 1.3 verify_key: :class:`str` The hex encoded key for verification in interactions and the @@ -110,6 +108,48 @@ class AppInfo: The application's privacy policy URL, if set. .. versionadded:: 2.0 + + approximate_guild_count: Optional[:class:`int`] + The approximate count of guilds to which the app has been added, if any. + + .. versionadded:: 2.7 + + approximate_user_install_count: Optional[:class:`int`] + The approximate count of users who have installed the application, if any. + + .. versionadded:: 2.7 + + redirect_uris: Optional[List[:class:`str`]] + The list of redirect URIs for the application, if set. + + .. versionadded:: 2.7 + + interactions_endpoint_url: Optional[:class:`str`] + The interactions endpoint URL for the application, if set. + + .. versionadded:: 2.7 + + role_connections_verification_url: Optional[:class:`str`] + The role connection verification URL for the application, if set. + + .. versionadded:: 2.7 + + install_params: Optional[List[:class:`AppInstallParams`]] + The settings for the application's default in-app authorization link, if set. + + .. versionadded:: 2.7 + + tags: Optional[List[:class:`str`]] + The list of tags describing the content and functionality of the app, if set. + + Maximium of 5 tags. + + .. versionadded:: 2.7 + + custom_install_url: Optional[:class:`str`] + The default custom authorization URL for the application, if set. + + .. versionadded:: 2.7 """ __slots__ = ( @@ -122,7 +162,7 @@ class AppInfo: "bot_require_code_grant", "owner", "_icon", - "summary", + "_summary", "verify_key", "team", "guild_id", @@ -131,6 +171,14 @@ class AppInfo: "_cover_image", "terms_of_service_url", "privacy_policy_url", + "approximate_guild_count", + "approximate_user_install_count", + "redirect_uris", + "interactions_endpoint_url", + "role_connections_verification_url", + "install_params", + "tags", + "custom_install_url", ) def __init__(self, state: ConnectionState, data: AppInfoPayload): @@ -149,7 +197,7 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload): team: TeamPayload | None = data.get("team") self.team: Team | None = Team(state, team) if team else None - self.summary: str = data["summary"] + self._summary: str = data["summary"] self.verify_key: str = data["verify_key"] self.guild_id: int | None = utils._get_as_snowflake(data, "guild_id") @@ -161,6 +209,24 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload): self._cover_image: str | None = data.get("cover_image") self.terms_of_service_url: str | None = data.get("terms_of_service_url") self.privacy_policy_url: str | None = data.get("privacy_policy_url") + self.approximate_guild_count: int | None = data.get("approximate_guild_count") + self.approximate_user_install_count: int | None = data.get( + "approximate_user_install_count" + ) + self.redirect_uris: list[str] | None = data.get("redirect_uris", []) + self.interactions_endpoint_url: str | None = data.get( + "interactions_endpoint_url" + ) + self.role_connections_verification_url: str | None = data.get( + "role_connections_verification_url" + ) + + install_params = data.get("install_params") + self.install_params: AppInstallParams | None = ( + AppInstallParams(install_params) if install_params else None + ) + self.tags: list[str] | None = data.get("tags", []) + self.custom_install_url: str | None = data.get("custom_install_url") def __repr__(self) -> str: return ( @@ -195,6 +261,23 @@ def guild(self) -> Guild | None: """ return self._state._get_guild(self.guild_id) + @property + def summary(self) -> str | None: + """If this application is a game sold on Discord, + this field will be the summary field for the store page of its primary SKU. + + It currently returns an empty string. + + .. versionadded:: 1.3 + .. deprecated:: 2.7 + """ + utils.warn_deprecated( + "summary", + "description", + reference="https://discord.com/developers/docs/resources/application#application-object-application-structure", + ) + return self._summary + class PartialAppInfo: """Represents a partial AppInfo given by :func:`~discord.abc.GuildChannel.create_invite` @@ -257,3 +340,23 @@ def icon(self) -> Asset | None: if self._icon is None: return None return Asset._from_icon(self._state, self.id, self._icon, path="app") + + +class AppInstallParams: + """Represents the settings for the custom authorization URL of an application. + + .. versionadded:: 2.7 + + Attributes + ---------- + scopes: List[:class:`str`] + The list of OAuth2 scopes for adding the application to a guild. + permissions: :class:`Permissions` + The permissions to request for the bot role in the guild. + """ + + __slots__ = ("scopes", "permissions") + + def __init__(self, data: AppInstallParamsPayload) -> None: + self.scopes: list[str] = data.get("scopes", []) + self.permissions: Permissions = Permissions(int(data["permissions"])) diff --git a/discord/types/appinfo.py b/discord/types/appinfo.py index 989d3f7a58..8d891acbed 100644 --- a/discord/types/appinfo.py +++ b/discord/types/appinfo.py @@ -59,3 +59,8 @@ class PartialAppInfo(BaseAppInfo): rpc_origins: NotRequired[list[str]] cover_image: NotRequired[str] flags: NotRequired[int] + + +class AppInstallParams(TypedDict): + scopes: list[str] + permissions: str diff --git a/docs/api/application_info.rst b/docs/api/application_info.rst index a0fe725320..585902b3a4 100644 --- a/docs/api/application_info.rst +++ b/docs/api/application_info.rst @@ -13,6 +13,11 @@ Application Info .. autoclass:: PartialAppInfo() :members: +.. attributetable:: AppInstallParams + +.. autoclass:: AppInstallParams() + :members: + .. attributetable:: Team .. autoclass:: Team()