Skip to content

Commit 08019ab

Browse files
feat: add support for editing our own application information
1 parent a34d0f9 commit 08019ab

File tree

3 files changed

+188
-3
lines changed

3 files changed

+188
-3
lines changed

Diff for: disnake/appinfo.py

+98-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, List, Optional
5+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, overload
66

77
from . import utils
8-
from .asset import Asset
8+
from .asset import Asset, AssetBytes
99
from .flags import ApplicationFlags
1010
from .permissions import Permissions
11+
from .utils import MISSING
1112

1213
if TYPE_CHECKING:
1314
from .guild import Guild
@@ -20,6 +21,7 @@
2021
)
2122
from .user import User
2223

24+
2325
__all__ = (
2426
"AppInfo",
2527
"PartialAppInfo",
@@ -64,6 +66,12 @@ def to_url(self) -> str:
6466
"""
6567
return utils.oauth_url(self._app_id, scopes=self.scopes, permissions=self.permissions)
6668

69+
def to_dict(self) -> Dict[str, Any]:
70+
return {
71+
"scopes": self.scopes,
72+
"permissions": self.permissions.value,
73+
}
74+
6775

6876
class AppInfo:
6977
"""Represents the application info for the bot provided by Discord.
@@ -280,6 +288,94 @@ def summary(self) -> str:
280288
)
281289
return self._summary
282290

291+
@overload
292+
async def edit(
293+
self,
294+
*,
295+
description: str = ...,
296+
flags: ApplicationFlags = ...,
297+
icon: Optional[AssetBytes] = ...,
298+
cover_image: Optional[AssetBytes] = ...,
299+
custom_install_url: Optional[str] = ...,
300+
install_params: Optional[InstallParams] = ...,
301+
role_connections_verification_url: str = ...,
302+
interactions_endpoint_url: Optional[str] = ...,
303+
tags: Optional[List[str]] = ...,
304+
) -> AppInfo:
305+
...
306+
307+
@overload
308+
async def edit(self) -> AppInfo:
309+
...
310+
311+
async def edit(
312+
self,
313+
*,
314+
flags: ApplicationFlags = MISSING,
315+
icon: Optional[AssetBytes] = MISSING,
316+
cover_image: Optional[AssetBytes] = MISSING,
317+
install_params: Optional[InstallParams] = MISSING,
318+
**fields: Any,
319+
) -> AppInfo:
320+
"""|coro|
321+
322+
Edit's the application's information.
323+
324+
All parameters are optional.
325+
326+
Returns a new :class:`AppInfo` with the updated information.
327+
328+
.. versionadded:: 2.10
329+
330+
Parameters
331+
----------
332+
description: Optional[:class:`str`]
333+
The application's description.
334+
flags: Optional[:class:`ApplicationFlags`]
335+
The application's public flags.
336+
tags: Optional[List[:class:`str`]]
337+
The application's tags.
338+
install_params: Optional[:class:`InstallParams`]
339+
The installation parameters for this application.
340+
custom_install_url: Optional[:class:`str`]
341+
The custom installation url for this application.
342+
role_connections_verification_url: Optional[:class:`str`]
343+
The application's role connection verification entry point,
344+
which when configured will render the app as a verification method
345+
in the guild role verification configuration.
346+
icon: |resource_type|
347+
Update the application's icon asset, if any.
348+
cover_image: |resource_type|
349+
Retrieves the cover image on a store embed, if any.
350+
351+
Raises
352+
------
353+
HTTPException
354+
Editing the information failed somehow.
355+
356+
Returns
357+
-------
358+
:class:`.AppInfo`
359+
The bot's new application information.
360+
"""
361+
if install_params is not MISSING:
362+
fields["install_params"] = None if install_params is None else install_params.to_dict()
363+
364+
if icon is not MISSING:
365+
fields["icon"] = await utils._assetbytes_to_base64_data(icon)
366+
367+
if cover_image is not MISSING:
368+
fields["cover_image"] = await utils._assetbytes_to_base64_data(cover_image)
369+
370+
if flags is not MISSING:
371+
fields["flags"] = flags.value
372+
373+
data = await self._state.http.edit_application_info(**fields)
374+
375+
if "rpc_origins" not in data:
376+
data["rpc_origins"] = None
377+
return AppInfo(self._state, data)
378+
283379

284380
class PartialAppInfo:
285381
"""Represents a partial AppInfo given by :func:`~disnake.abc.GuildChannel.create_invite`.

Diff for: disnake/client.py

+87-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
ApplicationCommand,
4343
GuildApplicationCommandPermissions,
4444
)
45-
from .appinfo import AppInfo
45+
from .appinfo import AppInfo, InstallParams
4646
from .application_role_connection import ApplicationRoleConnectionMetadata
4747
from .backoff import ExponentialBackoff
4848
from .channel import PartialMessageable, _threaded_channel_factory
@@ -2372,6 +2372,92 @@ async def application_info(self) -> AppInfo:
23722372
data["rpc_origins"] = None
23732373
return AppInfo(self._connection, data)
23742374

2375+
@overload
2376+
async def edit_application_info(
2377+
self,
2378+
*,
2379+
description: str = ...,
2380+
flags: ApplicationFlags = ...,
2381+
icon: Optional[AssetBytes] = ...,
2382+
cover_image: Optional[AssetBytes] = ...,
2383+
custom_install_url: Optional[str] = ...,
2384+
install_params: Optional[InstallParams] = ...,
2385+
role_connections_verification_url: str = ...,
2386+
interactions_endpoint_url: Optional[str] = ...,
2387+
tags: Optional[List[str]] = ...,
2388+
) -> AppInfo:
2389+
...
2390+
2391+
@overload
2392+
async def edit_application_info(self) -> AppInfo:
2393+
...
2394+
2395+
async def edit_application_info(
2396+
self,
2397+
*,
2398+
flags: ApplicationFlags = MISSING,
2399+
icon: Optional[AssetBytes] = MISSING,
2400+
cover_image: Optional[AssetBytes] = MISSING,
2401+
install_params: Optional[InstallParams] = MISSING,
2402+
**fields: Any,
2403+
) -> AppInfo:
2404+
"""|coro|
2405+
2406+
Edit's the application's information.
2407+
2408+
All parameters are optional.
2409+
2410+
.. versionadded:: 2.10
2411+
2412+
Parameters
2413+
----------
2414+
description: Optional[:class:`str`]
2415+
The application's description.
2416+
flags: Optional[:class:`.ApplicationFlags`]
2417+
The application's public flags.
2418+
tags: Optional[List[:class:`str`]]
2419+
The application's tags.
2420+
install_params: Optional[:class:`.InstallParams`]
2421+
The installation parameters for this application.
2422+
custom_install_url: Optional[:class:`str`]
2423+
The custom installation url for this application.
2424+
role_connections_verification_url: Optional[:class:`str`]
2425+
The application's role connection verification entry point,
2426+
which when configured will render the app as a verification method
2427+
in the guild role verification configuration.
2428+
icon: |resource_type|
2429+
Update the application's icon asset, if any.
2430+
cover_image: |resource_type|
2431+
Retrieves the cover image on a store embed, if any.
2432+
2433+
Raises
2434+
------
2435+
HTTPException
2436+
Editing the information failed somehow.
2437+
2438+
Returns
2439+
-------
2440+
:class:`.AppInfo`
2441+
The bot's application information.
2442+
"""
2443+
if install_params is not MISSING:
2444+
fields["install_params"] = None if install_params is None else install_params.to_dict()
2445+
2446+
if icon is not MISSING:
2447+
fields["icon"] = await utils._assetbytes_to_base64_data(icon)
2448+
2449+
if cover_image is not MISSING:
2450+
fields["cover_image"] = await utils._assetbytes_to_base64_data(cover_image)
2451+
2452+
if flags is not MISSING:
2453+
fields["flags"] = flags.value
2454+
2455+
data = await self.http.edit_application_info(**fields)
2456+
2457+
if "rpc_origins" not in data:
2458+
data["rpc_origins"] = None
2459+
return AppInfo(self._connection, data)
2460+
23752461
async def fetch_user(self, user_id: int, /) -> User:
23762462
"""|coro|
23772463

Diff for: disnake/http.py

+3
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,9 @@ def get_voice_regions(self) -> Response[List[voice.VoiceRegion]]:
27942794
def application_info(self) -> Response[appinfo.AppInfo]:
27952795
return self.request(Route("GET", "/oauth2/applications/@me"))
27962796

2797+
def edit_application_info(self, **fields: Any) -> Response[appinfo.AppInfo]:
2798+
return self.request(Route("PATCH", "/applications/@me"), json=fields)
2799+
27972800
def get_application_role_connection_metadata_records(
27982801
self, application_id: Snowflake
27992802
) -> Response[List[application_role_connection.ApplicationRoleConnectionMetadata]]:

0 commit comments

Comments
 (0)