Skip to content

Commit

Permalink
Add type attribute to Invite
Browse files Browse the repository at this point in the history
  • Loading branch information
Puncher1 committed May 17, 2024
1 parent b0024dc commit b9dc85e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,12 @@ class PollLayoutType(Enum):
default = 1


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}'
Expand Down
10 changes: 8 additions & 2 deletions discord/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -374,6 +378,7 @@ class Invite(Hashable):
'expires_at',
'scheduled_event',
'scheduled_event_id',
'type',
)

BASE = 'https://discord.gg'
Expand All @@ -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)
Expand Down Expand Up @@ -496,7 +502,7 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return (
f'<Invite code={self.code!r} guild={self.guild!r} '
f'<Invite type={self.type} code={self.code!r} guild={self.guild!r} '
f'online={self.approximate_presence_count} '
f'members={self.approximate_member_count}>'
)
Expand Down
2 changes: 2 additions & 0 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from .appinfo import PartialAppInfo

InviteTargetType = Literal[1, 2]
InviteType = Literal[0, 1, 2]


class _InviteMetadata(TypedDict, total=False):
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3623,6 +3623,26 @@ of :class:`enum.Enum`.

The default layout.


.. 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
Expand Down

0 comments on commit b9dc85e

Please sign in to comment.