2424
2525from __future__ import annotations
2626
27- from typing import List , TYPE_CHECKING , Optional
27+ from typing import List , TYPE_CHECKING , Literal , Optional
2828
2929from . import utils
3030from .asset import Asset
4141 PartialAppInfo as PartialAppInfoPayload ,
4242 Team as TeamPayload ,
4343 InstallParams as InstallParamsPayload ,
44+ AppIntegrationTypeConfig as AppIntegrationTypeConfigPayload ,
4445 )
4546 from .user import User
4647 from .state import ConnectionState
4950 'AppInfo' ,
5051 'PartialAppInfo' ,
5152 'AppInstallParams' ,
53+ 'IntegrationTypeConfig' ,
5254)
5355
5456
@@ -180,6 +182,7 @@ class AppInfo:
180182 'redirect_uris' ,
181183 'approximate_guild_count' ,
182184 'approximate_user_install_count' ,
185+ '_integration_types_config' ,
183186 )
184187
185188 def __init__ (self , state : ConnectionState , data : AppInfoPayload ):
@@ -218,6 +221,9 @@ def __init__(self, state: ConnectionState, data: AppInfoPayload):
218221 self .redirect_uris : List [str ] = data .get ('redirect_uris' , [])
219222 self .approximate_guild_count : int = data .get ('approximate_guild_count' , 0 )
220223 self .approximate_user_install_count : Optional [int ] = data .get ('approximate_user_install_count' )
224+ self ._integration_types_config : Dict [Literal ['0' , '1' ], AppIntegrationTypeConfigPayload ] = data .get (
225+ 'integration_types_config' , {}
226+ )
221227
222228 def __repr__ (self ) -> str :
223229 return (
@@ -260,6 +266,36 @@ def flags(self) -> ApplicationFlags:
260266 """
261267 return ApplicationFlags ._from_value (self ._flags )
262268
269+ @property
270+ def guild_integration_config (self ) -> Optional [IntegrationTypeConfig ]:
271+ """Optional[:class:`IntegrationTypeConfig`]: The default settings for the
272+ application's installation context in a guild.
273+
274+ .. versionadded:: 2.5
275+ """
276+ if not self ._integration_types_config :
277+ return None
278+
279+ try :
280+ return IntegrationTypeConfig (self ._integration_types_config ['0' ])
281+ except KeyError :
282+ return None
283+
284+ @property
285+ def user_integration_config (self ) -> Optional [IntegrationTypeConfig ]:
286+ """Optional[:class:`IntegrationTypeConfig`]: The default settings for the
287+ application's installation context as a user.
288+
289+ .. versionadded:: 2.5
290+ """
291+ if not self ._integration_types_config :
292+ return None
293+
294+ try :
295+ return IntegrationTypeConfig (self ._integration_types_config ['1' ])
296+ except KeyError :
297+ return None
298+
263299 async def edit (
264300 self ,
265301 * ,
@@ -274,6 +310,10 @@ async def edit(
274310 cover_image : Optional [bytes ] = MISSING ,
275311 interactions_endpoint_url : Optional [str ] = MISSING ,
276312 tags : Optional [List [str ]] = MISSING ,
313+ guild_install_scopes : Optional [List [str ]] = MISSING ,
314+ guild_install_permissions : Optional [Permissions ] = MISSING ,
315+ user_install_scopes : Optional [List [str ]] = MISSING ,
316+ user_install_permissions : Optional [Permissions ] = MISSING ,
277317 ) -> AppInfo :
278318 r"""|coro|
279319
@@ -315,6 +355,24 @@ async def edit(
315355 over the gateway. Can be ``None`` to remove the URL.
316356 tags: Optional[List[:class:`str`]]
317357 The new list of tags describing the functionality of the application. Can be ``None`` to remove the tags.
358+ guild_install_scopes: Optional[List[:class:`str`]]
359+ The new list of :ddocs:`OAuth2 scopes <topics/oauth2#shared-resources-oauth2-scopes>` of
360+ the default guild installation context. Can be ``None`` to remove the scopes.
361+
362+ .. versionadded: 2.5
363+ guild_install_permissions: Optional[:class:`Permissions`]
364+ The new permissions of the default guild installation context. Can be ``None`` to remove the permissions.
365+
366+ .. versionadded: 2.5
367+ user_install_scopes: Optional[List[:class:`str`]]
368+ The new list of :ddocs:`OAuth2 scopes <topics/oauth2#shared-resources-oauth2-scopes>` of
369+ the default user installation context. Can be ``None`` to remove the scopes.
370+
371+ .. versionadded: 2.5
372+ user_install_permissions: Optional[:class:`Permissions`]
373+ The new permissions of the default user installation context. Can be ``None`` to remove the permissions.
374+
375+ .. versionadded: 2.5
318376 reason: Optional[:class:`str`]
319377 The reason for editing the application. Shows up on the audit log.
320378
@@ -324,7 +382,8 @@ async def edit(
324382 Editing the application failed
325383 ValueError
326384 The image format passed in to ``icon`` or ``cover_image`` is invalid. This is also raised
327- when ``install_params_scopes`` and ``install_params_permissions`` are incompatible with each other.
385+ when ``install_params_scopes`` and ``install_params_permissions`` are incompatible with each other,
386+ or when ``guild_install_scopes`` and ``guild_install_permissions`` are incompatible with each other.
328387
329388 Returns
330389 -------
@@ -364,7 +423,7 @@ async def edit(
364423
365424 else :
366425 if install_params_permissions is not MISSING :
367- raise ValueError (" install_params_scopes must be set if install_params_permissions is set" )
426+ raise ValueError (' install_params_scopes must be set if install_params_permissions is set' )
368427
369428 if flags is not MISSING :
370429 if flags is None :
@@ -389,6 +448,51 @@ async def edit(
389448
390449 if tags is not MISSING :
391450 payload ['tags' ] = tags
451+
452+ integration_types_config : Dict [str , Any ] = {}
453+ if guild_install_scopes is not MISSING or guild_install_permissions is not MISSING :
454+ guild_install_params : Optional [Dict [str , Any ]] = {}
455+ if guild_install_scopes in (None , MISSING ):
456+ guild_install_scopes = []
457+
458+ if 'bot' not in guild_install_scopes and guild_install_permissions is not MISSING :
459+ raise ValueError ("'bot' must be in guild_install_scopes if guild_install_permissions is set" )
460+
461+ if guild_install_permissions in (None , MISSING ):
462+ guild_install_params ['permissions' ] = 0
463+ else :
464+ guild_install_params ['permissions' ] = guild_install_permissions .value
465+
466+ guild_install_params ['scopes' ] = guild_install_scopes
467+
468+ integration_types_config ['0' ] = {'oauth2_install_params' : guild_install_params or None }
469+ else :
470+ if guild_install_permissions is not MISSING :
471+ raise ValueError ('guild_install_scopes must be set if guild_install_permissions is set' )
472+
473+ if user_install_scopes is not MISSING or user_install_permissions is not MISSING :
474+ user_install_params : Optional [Dict [str , Any ]] = {}
475+ if user_install_scopes in (None , MISSING ):
476+ user_install_scopes = []
477+
478+ if 'bot' not in user_install_scopes and user_install_permissions is not MISSING :
479+ raise ValueError ("'bot' must be in user_install_scopes if user_install_permissions is set" )
480+
481+ if user_install_permissions in (None , MISSING ):
482+ user_install_params ['permissions' ] = 0
483+ else :
484+ user_install_params ['permissions' ] = user_install_permissions .value
485+
486+ user_install_params ['scopes' ] = user_install_scopes
487+
488+ integration_types_config ['1' ] = {'oauth2_install_params' : user_install_params or None }
489+ else :
490+ if user_install_permissions is not MISSING :
491+ raise ValueError ('user_install_scopes must be set if user_install_permissions is set' )
492+
493+ if integration_types_config :
494+ payload ['integration_types_config' ] = integration_types_config
495+
392496 data = await self ._state .http .edit_application_info (reason = reason , payload = payload )
393497 return AppInfo (data = data , state = self ._state )
394498
@@ -520,3 +624,22 @@ class AppInstallParams:
520624 def __init__ (self , data : InstallParamsPayload ) -> None :
521625 self .scopes : List [str ] = data .get ('scopes' , [])
522626 self .permissions : Permissions = Permissions (int (data ['permissions' ]))
627+
628+
629+ class IntegrationTypeConfig :
630+ """Represents the default settings for the application's installation context.
631+
632+ .. versionadded:: 2.5
633+
634+ Attributes
635+ ----------
636+ oauth2_install_params: Optional[:class:`AppInstallParams`]
637+ The install params for this installation context's default in-app authorization link.
638+ """
639+
640+ def __init__ (self , data : AppIntegrationTypeConfigPayload ) -> None :
641+ self .oauth2_install_params : Optional [AppInstallParams ] = None
642+ try :
643+ self .oauth2_install_params = AppInstallParams (data ['oauth2_install_params' ]) # type: ignore # EAFP
644+ except KeyError :
645+ pass
0 commit comments