Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing AppInfo attributes #2520

Merged
merged 24 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61ee1ef
feat: add missing AppInfo attributes
JustaSqu1d Aug 9, 2024
52f77c3
fix: add `install_params` to slots
JustaSqu1d Aug 9, 2024
b0a2423
docs: add related documentation
JustaSqu1d Aug 9, 2024
7cff3a3
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2024
aa879a4
fix: typing
JustaSqu1d Aug 9, 2024
d244d5d
docs: fix spacing
JustaSqu1d Aug 9, 2024
56ad873
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 9, 2024
681788c
fix: add AppInstallParams to `__all__`
JustaSqu1d Aug 10, 2024
239120a
fix: invalid scopes typehint
JustaSqu1d Aug 10, 2024
27ee402
fix: docs types formatting
JustaSqu1d Aug 10, 2024
06a5eca
docs: add changelog entry
JustaSqu1d Aug 12, 2024
4def83d
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 12, 2024
d79de90
feat: deprecate `AppInfo.summary`
JustaSqu1d Aug 12, 2024
0a0cd4c
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 12, 2024
c06d396
Merge branch 'master' into patch-3
JustaSqu1d Aug 12, 2024
fde6560
Merge branch 'master' into patch-3
JustaSqu1d Aug 15, 2024
2ea37c0
docs: fix changelog to adhere to conventions
JustaSqu1d Aug 15, 2024
c987ab5
fix: properly deprecate `summary`
JustaSqu1d Aug 15, 2024
a62d301
docs: fix `tags` typing
JustaSqu1d Aug 15, 2024
626bf3c
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2024
ea13c49
docs: fix summary formatting
JustaSqu1d Aug 15, 2024
6f10c5f
Merge branch 'patch-3' of https://github.com/JustaSqu1d/pycord into p…
JustaSqu1d Aug 15, 2024
9e6dbf8
Merge branch 'master' into patch-3
Lulalaby Aug 16, 2024
004bf4a
Merge branch 'master' into patch-3
JustaSqu1d Sep 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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