From c77ffa9c79beb5aeba15e2f6273fb0bf035ebcbf Mon Sep 17 00:00:00 2001 From: dolfies Date: Sun, 2 Apr 2023 20:41:34 -0400 Subject: [PATCH] Cache and update RequiredActionType --- discord/client.py | 11 ++++++++++- discord/enums.py | 12 ++++++++---- discord/state.py | 10 +++++----- docs/api.rst | 41 +++++++++++++++++++++++++++++------------ 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/discord/client.py b/discord/client.py index 143f60c34..30ad764cf 100644 --- a/discord/client.py +++ b/discord/client.py @@ -100,7 +100,7 @@ if TYPE_CHECKING: from .voice_client import VoiceProtocol from .settings import GuildSettings from .billing import BillingAddress - from .enums import PaymentGateway + from .enums import PaymentGateway, RequiredActionType from .metadata import MetadataObject from .types.snowflake import Snowflake as _Snowflake @@ -337,6 +337,15 @@ class Client: """Optional[:class:`.ClientUser`]: Represents the connected client. ``None`` if not logged in.""" return self._connection.user + @property + def required_action(self) -> Optional[RequiredActionType]: + """Optional[:class:`.RequiredActionType`]: The required action for the current user. + A required action is something Discord requires you to do to continue using your account. + + .. versionadded:: 2.0 + """ + return self._connection.required_action + @property def guilds(self) -> Sequence[Guild]: """Sequence[:class:`.Guild`]: The guilds that the connected client is a member of.""" diff --git a/discord/enums.py b/discord/enums.py index 01d37a745..d51d7ce21 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -800,12 +800,16 @@ class UnavailableGuildType(Enum): class RequiredActionType(Enum): - verify_phone = 'REQUIRE_VERIFIED_PHONE' - verify_email = 'REQUIRE_VERIFIED_EMAIL' - complete_captcha = 'REQUIRE_CAPTCHA' update_agreements = 'AGREEMENTS' acknowledge_tos_update = 'TOS_UPDATE_ACKNOWLEDGMENT' - none = None + complete_captcha = 'REQUIRE_CAPTCHA' + verify_email = 'REQUIRE_VERIFIED_EMAIL' + reverify_email = 'REQUIRE_REVERIFIED_EMAIL' + verify_phone = 'REQUIRE_VERIFIED_PHONE' + reverify_phone = 'REQUIRE_REVERIFIED_PHONE' + reverify_email_or_verify_phone = 'REQUIRE_REVERIFIED_EMAIL_OR_VERIFIED_PHONE' + verify_email_or_reverify_phone = 'REQUIRE_VERIFIED_EMAIL_OR_REVERIFIED_PHONE' + reverify_email_or_reverify_phone = 'REQUIRE_REVERIFIED_EMAIL_OR_REVERIFIED_PHONE' class InviteTarget(Enum): diff --git a/discord/state.py b/discord/state.py index 75a884248..9fc2ffbac 100644 --- a/discord/state.py +++ b/discord/state.py @@ -603,6 +603,7 @@ class ConnectionState: self.api_code_version: int = 0 self.session_type: Optional[str] = None self.auth_session_id: Optional[str] = None + self.required_action: Optional[RequiredActionType] = None self._emojis: Dict[int, Emoji] = {} self._stickers: Dict[int, GuildSticker] = {} self._guilds: Dict[int, Guild] = {} @@ -1049,9 +1050,7 @@ class ConnectionState: self.auth_session_id = data.get('auth_session_id_hash') self.connections = {c['id']: Connection(state=self, data=c) for c in data.get('connected_accounts', [])} self.pending_payments = {int(p['id']): Payment(state=self, data=p) for p in data.get('pending_payments', [])} - - if 'required_action' in data: - self.parse_user_required_action_update(data) + self.required_action = try_enum(RequiredActionType, data['required_action']) if 'required_action' in data else None if 'sessions' in data: self.parse_sessions_replace(data['sessions'], from_ready=True) @@ -1314,8 +1313,9 @@ class ConnectionState: settings = GuildSettings(data=data, state=self) self.dispatch('guild_settings_update', old_settings, settings) - def parse_user_required_action_update(self, data: Union[gw.RequiredActionEvent, gw.ReadyEvent]) -> None: - required_action = try_enum(RequiredActionType, data['required_action']) # type: ignore + def parse_user_required_action_update(self, data: gw.RequiredActionEvent) -> None: + required_action = try_enum(RequiredActionType, data['required_action']) if data['required_action'] else None + self.required_action = required_action self.dispatch('required_action_update', required_action) def parse_user_connections_update(self, data: Union[gw.ConnectionEvent, gw.PartialConnectionEvent]) -> None: diff --git a/docs/api.rst b/docs/api.rst index 4d21e1df2..70a0d4dea 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -446,12 +446,12 @@ Client .. function:: on_required_action_update(action) - Called when Discord requires you to do something to verify your account. + Called when Discord requires you to do something to continue using your account. .. versionadded:: 2.0 - :param action: The action required. - :type action: :class:`RequiredActionType` + :param action: The action required. If ``None``, then no further action is required. + :type action: Optional[:class:`RequiredActionType`] Billing ~~~~~~~ @@ -5066,25 +5066,42 @@ of :class:`enum.Enum`. .. versionadded:: 2.0 - .. attribute:: verify_phone + .. attribute:: update_agreements + + The user must update their agreement of Discord's terms of service and privacy policy. + This does not limit the user from using Discord. + + .. attribute:: complete_captcha - The user must verify their phone number. + The user must complete a captcha. .. attribute:: verify_email - The user must verify their email address. + The user must add and verify an email address to their account. - .. attribute:: complete_captcha + .. attribute:: reverify_email - The user must complete a captcha. + The user must reverify their existing email address. - .. attribute:: update_agreements + .. attribute:: verify_phone - The user must update their agreement of Discord's terms of service and privacy policy. + The user must add a phone number to their account. - .. attribute:: none + .. attribute:: reverify_phone + + The user must reverify their existing phone number. + + .. attribute:: reverify_email_or_verify_phone + + The user must reverify their existing email address or add a phone number to their account. + + .. attribute:: verify_email_or_reverify_phone + + The user must add and verify an email address to their account or reverify their existing phone number. + + .. attribute:: reverify_email_or_reverify_phone - The user does not need to take any more actions. + The user must reverify their existing email address or reverify their existing phone number. .. class:: ConnectionType