|
2 | 2 |
|
3 | 3 | from __future__ import annotations
|
4 | 4 |
|
5 |
| -from typing import TYPE_CHECKING, List, Optional |
| 5 | +from typing import TYPE_CHECKING, Any, Dict, List, Optional, overload |
6 | 6 |
|
7 | 7 | from . import utils
|
8 |
| -from .asset import Asset |
| 8 | +from .asset import Asset, AssetBytes |
9 | 9 | from .flags import ApplicationFlags
|
10 | 10 | from .permissions import Permissions
|
| 11 | +from .utils import MISSING |
11 | 12 |
|
12 | 13 | if TYPE_CHECKING:
|
13 | 14 | from .guild import Guild
|
|
20 | 21 | )
|
21 | 22 | from .user import User
|
22 | 23 |
|
| 24 | + |
23 | 25 | __all__ = (
|
24 | 26 | "AppInfo",
|
25 | 27 | "PartialAppInfo",
|
@@ -64,6 +66,12 @@ def to_url(self) -> str:
|
64 | 66 | """
|
65 | 67 | return utils.oauth_url(self._app_id, scopes=self.scopes, permissions=self.permissions)
|
66 | 68 |
|
| 69 | + def to_dict(self) -> Dict[str, Any]: |
| 70 | + return { |
| 71 | + "scopes": self.scopes, |
| 72 | + "permissions": self.permissions.value, |
| 73 | + } |
| 74 | + |
67 | 75 |
|
68 | 76 | class AppInfo:
|
69 | 77 | """Represents the application info for the bot provided by Discord.
|
@@ -280,6 +288,94 @@ def summary(self) -> str:
|
280 | 288 | )
|
281 | 289 | return self._summary
|
282 | 290 |
|
| 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 | + |
283 | 379 |
|
284 | 380 | class PartialAppInfo:
|
285 | 381 | """Represents a partial AppInfo given by :func:`~disnake.abc.GuildChannel.create_invite`.
|
|
0 commit comments