From 9004f6f0d9e03d5a694b23665b7670d49c6a9bd6 Mon Sep 17 00:00:00 2001 From: dolfies Date: Mon, 7 Mar 2022 19:02:01 -0500 Subject: [PATCH] Parse ApplicationType and document ApplicationBot --- discord/appinfo.py | 29 ++++++++++++++++++++++++++--- discord/enums.py | 9 +++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/discord/appinfo.py b/discord/appinfo.py index 934b6f80b..ad8d30fd8 100644 --- a/discord/appinfo.py +++ b/discord/appinfo.py @@ -28,7 +28,7 @@ from typing import List, TYPE_CHECKING, Optional from . import utils from .asset import Asset -from .enums import ApplicationVerificationState, RPCApplicationState, StoreApplicationState, try_enum +from .enums import ApplicationType, ApplicationVerificationState, RPCApplicationState, StoreApplicationState, try_enum from .flags import ApplicationFlags from .user import User @@ -52,6 +52,21 @@ MISSING = utils.MISSING class ApplicationBot(User): + """Represents a bot attached to an application. + + Attributes + ----------- + application: :class:`Application` + The application that the bot is attached to. + public: :class:`bool` + Whether the bot can be invited by anyone or if it is locked + to the application owner. + require_code_grant: :class:`bool` + Whether the bot requires the completion of the full OAuth2 code + grant flow to join. + token: Optional[:class:`str`] + The bot's token. Only accessible when reset. + """ __slots__ = ('token', 'public', 'require_code_grant') def __init__(self, *, data, state: ConnectionState, application: Application): @@ -70,10 +85,16 @@ class ApplicationBot(User): ------ HTTPException Resetting the token failed. + + Returns + ------- + :class:`str` + The new token. """ data = await self._state.http.reset_token(self.application.id) - self.token = data['token'] + self.token = token = data['token'] self._update(data) + return token async def edit( self, @@ -148,6 +169,8 @@ class PartialApplication: premium_tier_level: Optional[:class:`int`] The required premium tier level to launch the activity. Only available for embedded activities. + type: :class:`ApplicationType` + The type of application. """ __slots__ = ( @@ -188,7 +211,7 @@ class PartialApplication: self.terms_of_service_url: Optional[str] = data.get('terms_of_service_url') self.privacy_policy_url: Optional[str] = data.get('privacy_policy_url') self._flags: int = data.get('flags', 0) - self.type: Optional[int] = data.get('type') + self.type: ApplicationType = try_enum(ApplicationType, data.get('type')) self.hook: bool = data.get('hook', False) self.max_participants: Optional[int] = data.get('max_participants') self.premium_tier_level: Optional[int] = data.get('embedded_activity_config', {}).get('activity_premium_tier_level') diff --git a/discord/enums.py b/discord/enums.py index 44865db80..f6de01d79 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -74,6 +74,7 @@ __all__ = ( 'InviteType', 'ScheduledEventStatus', 'ScheduledEventEntityType', + 'ApplicationType', ) @@ -804,6 +805,14 @@ class RPCApplicationState(Enum, comparable=True): rejected = 4 +class ApplicationType(Enum): + none = None + game = 1 + music = 2 + ticketed_events = 3 + guild_role_subscriptions = 4 + + T = TypeVar('T')