Skip to content

Commit

Permalink
feat: add missing AppInfo attributes (#2520)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <[email protected]>
  • Loading branch information
3 people authored Sep 2, 2024
1 parent eb3ac6b commit 31f5e12
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 15 deletions.
22 changes: 14 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
117 changes: 110 additions & 7 deletions discord/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@

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

__all__ = (
"AppInfo",
"PartialAppInfo",
"AppInstallParams",
)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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__ = (
Expand All @@ -122,7 +162,7 @@ class AppInfo:
"bot_require_code_grant",
"owner",
"_icon",
"summary",
"_summary",
"verify_key",
"team",
"guild_id",
Expand All @@ -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):
Expand All @@ -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")
Expand All @@ -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 (
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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"]))
5 changes: 5 additions & 0 deletions discord/types/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions docs/api/application_info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Application Info
.. autoclass:: PartialAppInfo()
:members:

.. attributetable:: AppInstallParams

.. autoclass:: AppInstallParams()
:members:

.. attributetable:: Team

.. autoclass:: Team()
Expand Down

0 comments on commit 31f5e12

Please sign in to comment.