From f9da1527a00f515f121f726568e5b46f340cb6a5 Mon Sep 17 00:00:00 2001 From: Puncher <65789180+Puncher1@users.noreply.github.com> Date: Tue, 12 Dec 2023 22:28:15 +0100 Subject: [PATCH] Add type attribute to Invite --- discord/enums.py | 6 ++++++ discord/invite.py | 10 ++++++++-- discord/types/invite.py | 2 ++ docs/api.rst | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index e30a87503c9c..96ec556a01aa 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -800,6 +800,12 @@ class EntitlementOwnerType(Enum): user = 2 +class InviteType(Enum): + guild = 0 + group_dm = 1 + friend = 2 + + def create_unknown_value(cls: Type[E], val: Any) -> E: value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below name = f'unknown_{val}' diff --git a/discord/invite.py b/discord/invite.py index 1c18e41875d4..1d8dd1c8ef73 100644 --- a/discord/invite.py +++ b/discord/invite.py @@ -29,7 +29,7 @@ from .utils import parse_time, snowflake_time, _get_as_snowflake from .object import Object from .mixins import Hashable -from .enums import ChannelType, NSFWLevel, VerificationLevel, InviteTarget, try_enum +from .enums import ChannelType, NSFWLevel, VerificationLevel, InviteTarget, InviteType, try_enum from .appinfo import PartialAppInfo from .scheduled_event import ScheduledEvent @@ -296,6 +296,10 @@ class Invite(Hashable): Attributes ----------- + type: :class:`InviteType` + The type of the invite. + + .. versionadded: 2.4 max_age: Optional[:class:`int`] How long before the invite expires in seconds. A value of ``0`` indicates that it doesn't expire. @@ -374,6 +378,7 @@ class Invite(Hashable): 'expires_at', 'scheduled_event', 'scheduled_event_id', + 'type', ) BASE = 'https://discord.gg' @@ -387,6 +392,7 @@ def __init__( channel: Optional[Union[PartialInviteChannel, GuildChannel]] = None, ): self._state: ConnectionState = state + self.type: InviteType = try_enum(InviteType, data.get('type', 0)) self.max_age: Optional[int] = data.get('max_age') self.code: str = data['code'] self.guild: Optional[InviteGuildType] = self._resolve_guild(data.get('guild'), guild) @@ -496,7 +502,7 @@ def __str__(self) -> str: def __repr__(self) -> str: return ( - f'' ) diff --git a/discord/types/invite.py b/discord/types/invite.py index b53ca374c6b2..f5f00078e950 100644 --- a/discord/types/invite.py +++ b/discord/types/invite.py @@ -35,6 +35,7 @@ from .appinfo import PartialAppInfo InviteTargetType = Literal[1, 2] +InviteType = Literal[0, 1, 2] class _InviteMetadata(TypedDict, total=False): @@ -63,6 +64,7 @@ class Invite(IncompleteInvite, total=False): target_type: InviteTargetType target_application: PartialAppInfo guild_scheduled_event: GuildScheduledEvent + type: InviteType class InviteWithCounts(Invite, _GuildPreviewUnique): diff --git a/docs/api.rst b/docs/api.rst index 75cad32c0640..8c4c3c436b15 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3511,6 +3511,25 @@ of :class:`enum.Enum`. The entitlement owner is a user. +.. class:: InviteType + + Represents the type of an invite. + + .. versionadded:: 2.4 + + .. attribute:: guild + + The invite is a guild invite. + + .. attribute:: group_dm + + The invite is a group DM invite. + + .. attribute:: friend + + The invite is a friend invite. + + .. _discord-api-audit-logs: Audit Log Data