-
Notifications
You must be signed in to change notification settings - Fork 139
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 support for editing our own application information #1237
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add new :meth:`Client.edit_application_info` and :meth:`AppInfo.edit` methods. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,12 +2,13 @@ | |||||
|
||||||
from __future__ import annotations | ||||||
|
||||||
from typing import TYPE_CHECKING, List, Optional | ||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional | ||||||
|
||||||
from . import utils | ||||||
from .asset import Asset | ||||||
from .asset import Asset, AssetBytes | ||||||
from .flags import ApplicationFlags | ||||||
from .permissions import Permissions | ||||||
from .utils import MISSING | ||||||
|
||||||
if TYPE_CHECKING: | ||||||
from .guild import Guild | ||||||
|
@@ -20,6 +21,7 @@ | |||||
) | ||||||
from .user import User | ||||||
|
||||||
|
||||||
__all__ = ( | ||||||
"AppInfo", | ||||||
"PartialAppInfo", | ||||||
|
@@ -64,6 +66,12 @@ def to_url(self) -> str: | |||||
""" | ||||||
return utils.oauth_url(self._app_id, scopes=self.scopes, permissions=self.permissions) | ||||||
|
||||||
def to_dict(self) -> Dict[str, Any]: | ||||||
return { | ||||||
"scopes": self.scopes, | ||||||
"permissions": self.permissions.value, | ||||||
} | ||||||
|
||||||
|
||||||
class AppInfo: | ||||||
"""Represents the application info for the bot provided by Discord. | ||||||
|
@@ -280,6 +288,95 @@ def summary(self) -> str: | |||||
) | ||||||
return self._summary | ||||||
|
||||||
async def edit( | ||||||
self, | ||||||
*, | ||||||
description: Optional[str] = MISSING, | ||||||
flags: ApplicationFlags = MISSING, | ||||||
icon: Optional[AssetBytes] = MISSING, | ||||||
cover_image: Optional[AssetBytes] = MISSING, | ||||||
custom_install_url: Optional[str] = MISSING, | ||||||
install_params: Optional[InstallParams] = MISSING, | ||||||
role_connections_verification_url: Optional[str] = MISSING, | ||||||
interactions_endpoint_url: Optional[str] = MISSING, | ||||||
tags: Optional[List[str]] = MISSING, | ||||||
) -> AppInfo: | ||||||
"""|coro| | ||||||
|
||||||
Edit's the application's information. | ||||||
|
||||||
All parameters are optional. | ||||||
|
||||||
Returns a new :class:`AppInfo` with the updated information. | ||||||
Comment on lines
+309
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
.. versionadded:: 2.10 | ||||||
|
||||||
Parameters | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the docstring is missing |
||||||
---------- | ||||||
description: Optional[:class:`str`] | ||||||
The application's description. | ||||||
flags: Optional[:class:`ApplicationFlags`] | ||||||
The application's public flags. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should note that this is limited to specific flags only |
||||||
tags: Optional[List[:class:`str`]] | ||||||
The application's tags. | ||||||
install_params: Optional[:class:`InstallParams`] | ||||||
The installation parameters for this application. | ||||||
custom_install_url: Optional[:class:`str`] | ||||||
The custom installation url for this application. | ||||||
role_connections_verification_url: Optional[:class:`str`] | ||||||
The application's role connection verification entry point, | ||||||
which when configured will render the app as a verification method | ||||||
in the guild role verification configuration. | ||||||
icon: |resource_type| | ||||||
Update the application's icon asset, if any. | ||||||
cover_image: |resource_type| | ||||||
Retrieves the cover image on a store embed, if any. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this description is outdated |
||||||
|
||||||
Raises | ||||||
------ | ||||||
HTTPException | ||||||
Editing the information failed somehow. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Returns | ||||||
------- | ||||||
:class:`.AppInfo` | ||||||
The bot's new application information. | ||||||
""" | ||||||
fields: Dict[str, Any] = {} | ||||||
|
||||||
if install_params is not MISSING: | ||||||
fields["install_params"] = None if install_params is None else install_params.to_dict() | ||||||
|
||||||
if icon is not MISSING: | ||||||
fields["icon"] = await utils._assetbytes_to_base64_data(icon) | ||||||
|
||||||
if cover_image is not MISSING: | ||||||
fields["cover_image"] = await utils._assetbytes_to_base64_data(cover_image) | ||||||
|
||||||
if flags is not MISSING: | ||||||
fields["flags"] = flags.value | ||||||
|
||||||
if description is not MISSING: | ||||||
fields["description"] = description | ||||||
|
||||||
if custom_install_url is not MISSING: | ||||||
fields["custom_install_url"] = custom_install_url | ||||||
|
||||||
if role_connections_verification_url is not MISSING: | ||||||
fields["role_connections_verification_url"] = role_connections_verification_url | ||||||
|
||||||
if interactions_endpoint_url is not MISSING: | ||||||
fields["interactions_endpoint_url"] = interactions_endpoint_url | ||||||
|
||||||
if tags is not MISSING: | ||||||
fields["tags"] = tags | ||||||
|
||||||
data = await self._state.http.edit_application_info(**fields) | ||||||
|
||||||
if "rpc_origins" not in data: | ||||||
data["rpc_origins"] = None | ||||||
return AppInfo(self._state, data) | ||||||
|
||||||
|
||||||
class PartialAppInfo: | ||||||
"""Represents a partial AppInfo given by :func:`~disnake.abc.GuildChannel.create_invite`. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
ApplicationCommand, | ||
GuildApplicationCommandPermissions, | ||
) | ||
from .appinfo import AppInfo | ||
from .appinfo import AppInfo, InstallParams | ||
from .application_role_connection import ApplicationRoleConnectionMetadata | ||
from .backoff import ExponentialBackoff | ||
from .channel import PartialMessageable, _threaded_channel_factory | ||
|
@@ -2372,6 +2372,93 @@ async def application_info(self) -> AppInfo: | |
data["rpc_origins"] = None | ||
return AppInfo(self._connection, data) | ||
|
||
async def edit_application_info( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having the same method on |
||
self, | ||
*, | ||
description: Optional[str] = MISSING, | ||
flags: ApplicationFlags = MISSING, | ||
icon: Optional[AssetBytes] = MISSING, | ||
cover_image: Optional[AssetBytes] = MISSING, | ||
custom_install_url: Optional[str] = MISSING, | ||
install_params: Optional[InstallParams] = MISSING, | ||
role_connections_verification_url: Optional[str] = MISSING, | ||
interactions_endpoint_url: Optional[str] = MISSING, | ||
tags: Optional[List[str]] = MISSING, | ||
) -> AppInfo: | ||
"""|coro| | ||
|
||
Edit's the application's information. | ||
|
||
All parameters are optional. | ||
|
||
.. versionadded:: 2.10 | ||
|
||
Parameters | ||
---------- | ||
description: Optional[:class:`str`] | ||
The application's description. | ||
flags: Optional[:class:`.ApplicationFlags`] | ||
The application's public flags. | ||
tags: Optional[List[:class:`str`]] | ||
The application's tags. | ||
install_params: Optional[:class:`.InstallParams`] | ||
The installation parameters for this application. | ||
custom_install_url: Optional[:class:`str`] | ||
The custom installation url for this application. | ||
role_connections_verification_url: Optional[:class:`str`] | ||
The application's role connection verification entry point, | ||
which when configured will render the app as a verification method | ||
in the guild role verification configuration. | ||
icon: |resource_type| | ||
Update the application's icon asset, if any. | ||
cover_image: |resource_type| | ||
Retrieves the cover image on a store embed, if any. | ||
|
||
Raises | ||
------ | ||
HTTPException | ||
Editing the information failed somehow. | ||
|
||
Returns | ||
------- | ||
:class:`.AppInfo` | ||
The bot's application information. | ||
""" | ||
fields: Dict[str, Any] = {} | ||
|
||
if install_params is not MISSING: | ||
fields["install_params"] = None if install_params is None else install_params.to_dict() | ||
|
||
if icon is not MISSING: | ||
fields["icon"] = await utils._assetbytes_to_base64_data(icon) | ||
|
||
if cover_image is not MISSING: | ||
fields["cover_image"] = await utils._assetbytes_to_base64_data(cover_image) | ||
|
||
if flags is not MISSING: | ||
fields["flags"] = flags.value | ||
|
||
if description is not MISSING: | ||
fields["description"] = description | ||
|
||
if custom_install_url is not MISSING: | ||
fields["custom_install_url"] = custom_install_url | ||
|
||
if role_connections_verification_url is not MISSING: | ||
fields["role_connections_verification_url"] = role_connections_verification_url | ||
|
||
if interactions_endpoint_url is not MISSING: | ||
fields["interactions_endpoint_url"] = interactions_endpoint_url | ||
|
||
if tags is not MISSING: | ||
fields["tags"] = tags | ||
|
||
data = await self.http.edit_application_info(**fields) | ||
|
||
if "rpc_origins" not in data: | ||
data["rpc_origins"] = None | ||
return AppInfo(self._connection, data) | ||
|
||
async def fetch_user(self, user_id: int, /) -> User: | ||
"""|coro| | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured this is worth mentioning - most of these fields, other than
icon
andcover_image
, aren't marked as nullable in the documentation.However considering that they are optional in the application object structure itself, clearly only setting them to
null
would reset the fields. So I assume this is fine?