Skip to content

Commit

Permalink
Add missing fields for Application (#1420)
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa authored Jan 1, 2023
1 parent f847b06 commit b461fb1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changes/1420.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add missing `Application` fields:
- `Application.custom_install_url`
- `Application.tags`
- `Application.install_parameters`
21 changes: 21 additions & 0 deletions hikari/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,18 @@ def make_cover_image_url(self, *, ext: str = "png", size: int = 4096) -> typing.
)


@attr_extensions.with_copy
@attr.define(hash=True, kw_only=True, weakref_slot=False)
class ApplicationInstallParameters:
"""Represents the application install parameters."""

scopes: typing.Sequence[str] = attr.field(eq=True, repr=False, hash=True)
"""The scopes to authorize the bot for."""

permissions: permissions_.Permissions = attr.field(eq=True, repr=False, hash=True)
"""The permissions to add the bot to guild with."""


@attr_extensions.with_copy
@attr.define(hash=True, kw_only=True, weakref_slot=False)
class Application(guilds.PartialApplication):
Expand Down Expand Up @@ -575,6 +587,15 @@ class Application(guilds.PartialApplication):
privacy_policy_url: typing.Optional[str] = attr.field(eq=False, hash=False, repr=False)
"""The URL of this application's privacy policy."""

custom_install_url: typing.Optional[str] = attr.field(eq=False, hash=False, repr=False)
"""The URL of this application's custom authorization link."""

tags: typing.Sequence[str] = attr.field(eq=False, hash=False, repr=False)
"""A sequence of tags describing the content and functionality of the application."""

install_parameters: typing.Optional[ApplicationInstallParameters] = attr.field(eq=False, hash=False, repr=False)
"""Settings for the application's default in-app authorization link, if enabled."""

@property
def cover_image_url(self) -> typing.Optional[files.URL]:
"""Rich presence cover image URL for this application, if set."""
Expand Down
10 changes: 10 additions & 0 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,13 @@ def deserialize_application(self, payload: data_binding.JSONObject) -> applicati
owner_id=snowflakes.Snowflake(team_payload["owner_user_id"]),
)

install_parameters: typing.Optional[application_models.ApplicationInstallParameters] = None
if (install_payload := payload.get("install_params")) is not None:
install_parameters = application_models.ApplicationInstallParameters(
scopes=[application_models.OAuth2Scope(scope) for scope in install_payload["scopes"]],
permissions=permission_models.Permissions(install_payload["permissions"]),
)

return application_models.Application(
app=self._app,
id=snowflakes.Snowflake(payload["id"]),
Expand All @@ -625,6 +632,9 @@ def deserialize_application(self, payload: data_binding.JSONObject) -> applicati
cover_image_hash=payload.get("cover_image"),
privacy_policy_url=payload.get("privacy_policy_url"),
terms_of_service_url=payload.get("terms_of_service_url"),
custom_install_url=payload.get("custom_install_url"),
tags=payload.get("tags") or [],
install_parameters=install_parameters,
)

def deserialize_authorization_information(
Expand Down
20 changes: 20 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,12 @@ def application_payload(self, owner_payload, user_payload):
"cover_image": "hashmebaby",
"privacy_policy_url": "hahaha://hahaha",
"terms_of_service_url": "haha2:2h2h2h2",
"custom_install_url": "https://dontinstallme.com",
"tags": ["i", "like", "hikari"],
"install_params": {
"scopes": ["bot", "applications.commands"],
"permissions": 8,
},
}

def test_deserialize_application(
Expand All @@ -970,7 +976,16 @@ def test_deserialize_application(
assert application.flags == application_models.ApplicationFlags.VERIFICATION_PENDING_GUILD_LIMIT
assert application.privacy_policy_url == "hahaha://hahaha"
assert application.terms_of_service_url == "haha2:2h2h2h2"
assert application.custom_install_url == "https://dontinstallme.com"
assert application.tags == ["i", "like", "hikari"]
assert application.icon_hash == "iwiwiwiwiw"
# Install Parameters
assert application.install_parameters.scopes == [
application_models.OAuth2Scope.BOT,
application_models.OAuth2Scope.APPLICATIONS_COMMANDS,
]
assert application.install_parameters.permissions == permission_models.Permissions.ADMINISTRATOR
assert isinstance(application.install_parameters, application_models.ApplicationInstallParameters)
# Team
assert application.team.id == 202020202
assert application.team.name == "Hikari Development"
Expand Down Expand Up @@ -1028,8 +1043,13 @@ def test_deserialize_application_with_null_fields(self, entity_factory_impl, moc

assert application.description is None
assert application.icon_hash is None
assert application.terms_of_service_url is None
assert application.privacy_policy_url is None
assert application.custom_install_url is None
assert application.cover_image_hash is None
assert application.team is None
assert application.install_parameters is None
assert application.tags == []

@pytest.fixture()
def invite_application_payload(self):
Expand Down

0 comments on commit b461fb1

Please sign in to comment.