Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for invite flags, guest invite. #9476

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 64 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'ChannelFlags',
'AutoModPresets',
'MemberFlags',
'InviteFlags',
)

BF = TypeVar('BF', bound='BaseFlags')
Expand Down Expand Up @@ -1810,3 +1811,66 @@ def bypasses_verification(self):
def started_onboarding(self):
""":class:`bool`: Returns ``True`` if the member has started onboarding."""
return 1 << 3


@fill_with_flags()
class InviteFlags(BaseFlags):
r"""Wraps up the Discord Invite flags

.. versionadded:: 2.4

.. container:: operations

.. describe:: x == y

Checks if two InviteFlags are equal.

.. describe:: x != y

Checks if two InviteFlags are not equal.

.. describe:: x | y, x |= y

Returns a InviteFlags instance with all enabled flags from
both x and y.

.. describe:: x & y, x &= y

Returns a InviteFlags instance with only flags enabled on
both x and y.

.. describe:: x ^ y, x ^= y

Returns a InviteFlags instance with only flags enabled on
only one of x or y, not on both.

.. describe:: ~x

Returns a InviteFlags instance with all flags inverted from x.

.. describe:: hash(x)

Return the flag's hash.

.. describe:: iter(x)

Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.

.. describe:: bool(b)

Returns whether any flag is set to ``True``.


Attributes
-----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""

@flag_value
def guest(self):
""":class:`bool`: Returns ``True`` if the invite is a guest invite."""
return 1 << 0
8 changes: 8 additions & 0 deletions discord/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
from __future__ import annotations

from typing import List, Optional, Union, TYPE_CHECKING

from .asset import Asset
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 .appinfo import PartialAppInfo
from .scheduled_event import ScheduledEvent
from .flags import InviteFlags

__all__ = (
'PartialInviteChannel',
Expand Down Expand Up @@ -351,6 +353,10 @@ class Invite(Hashable):
The ID of the scheduled event associated with this invite, if any.

.. versionadded:: 2.0
flags: :class:`InviteFlags`
Additional flags for the invite.

.. versionadded:: 2.4
"""

__slots__ = (
Expand All @@ -373,6 +379,7 @@ class Invite(Hashable):
'expires_at',
'scheduled_event',
'scheduled_event_id',
'flags',
)

BASE = 'https://discord.gg'
Expand Down Expand Up @@ -425,6 +432,7 @@ def __init__(
else None
)
self.scheduled_event_id: Optional[int] = self.scheduled_event.id if self.scheduled_event else None
self.flags: InviteFlags = InviteFlags._from_value(data.get('flags', 0))

@classmethod
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
Expand Down
1 change: 1 addition & 0 deletions discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class UnavailableGuild(TypedDict):
'VIP_REGIONS',
'WELCOME_SCREEN_ENABLED',
'RAID_ALERTS_DISABLED',
'GUESTS_ENABLED',
]


Expand Down
1 change: 1 addition & 0 deletions discord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Invite(IncompleteInvite, total=False):
target_type: InviteTargetType
target_application: PartialAppInfo
guild_scheduled_event: GuildScheduledEvent
flags: int


class InviteWithCounts(Invite, _GuildPreviewUnique):
Expand Down
8 changes: 8 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4970,6 +4970,14 @@ MemberFlags
.. autoclass:: MemberFlags
:members:

InviteFlags
~~~~~~~~~~~~

.. attributetable:: InviteFlags

.. autoclass:: InviteFlags
:members:

ForumTag
~~~~~~~~~

Expand Down