Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1062.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement Guest invites.
92 changes: 92 additions & 0 deletions disnake/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"ChannelFlags",
"AutoModKeywordPresets",
"MemberFlags",
"InviteFlags",
)

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


class InviteFlags(BaseFlags):
"""Wraps up a Discord Invite flag value.

See :class:`SystemChannelFlags`.

.. container:: operations

.. describe:: x == y

Checks if two InviteFlags instances are equal.
.. describe:: x != y

Checks if two InviteFlags instances are not equal.
.. describe:: x <= y

Checks if a InviteFlags instance is a subset of another InviteFlags instance.

.. describe:: x >= y

Checks if a InviteFlags instance is a superset of another InviteFlags instance.

.. describe:: x < y

Checks if a InviteFlags instance is a strict subset of another InviteFlags instance.

.. describe:: x > y

Checks if a InviteFlags instance is a strict superset of another InviteFlags instance.

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

Returns a new InviteFlags instance with all enabled flags from both x and y.
(Using ``|=`` will update in place).

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

Returns a new InviteFlags instance with only flags enabled on both x and y.
(Using ``&=`` will update in place).

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

Returns a new InviteFlags instance with only flags enabled on one of x or y, but not both.
(Using ``^=`` will update in place).

.. describe:: ~x

Returns a new InviteFlags instance with all flags from x inverted.

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


Additionally supported are a few operations on class attributes.

.. describe:: InviteFlags.y | InviteFlags.z, InviteFlags(y=True) | InviteFlags.z

Returns a InviteFlags instance with all provided flags enabled.

.. describe:: ~InviteFlags.y

Returns a InviteFlags instance with all flags except ``y`` inverted from their default value.

.. versionadded:: 2.10

Attributes
----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""

__slots__ = ()

if TYPE_CHECKING:

@_generated
def __init__(self, *, guest: bool = ...) -> None:
...

@flag_value
def guest(self):
""":class:`bool`: Returns ``True`` if the invite is a guest invite."""
return 1 << 0
1 change: 1 addition & 0 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Guild(Hashable):
- ``VERIFIED``: Guild is a verified server.
- ``VIP_REGIONS``: Guild has VIP voice regions.
- ``WELCOME_SCREEN_ENABLED``: Guild has enabled the welcome screen.
- ``GUESTS_ENABLED``: Guild has access to guest invites.
premium_progress_bar_enabled: :class:`bool`
Whether the server boost progress bar is enabled.
premium_tier: :class:`int`
Expand Down
12 changes: 12 additions & 0 deletions disnake/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .appinfo import PartialAppInfo
from .asset import Asset
from .enums import ChannelType, InviteTarget, NSFWLevel, VerificationLevel, try_enum
from .flags import InviteFlags
from .guild_scheduled_event import GuildScheduledEvent
from .mixins import Hashable
from .object import Object
Expand Down Expand Up @@ -398,6 +399,7 @@ class Invite(Hashable):
"guild_scheduled_event",
"guild_welcome_screen",
"_state",
"_flags",
)

BASE = "https://discord.gg"
Expand Down Expand Up @@ -466,6 +468,8 @@ def __init__(
else:
self.guild_scheduled_event: Optional[GuildScheduledEvent] = None

self._flags: int = data.get("flags", 0)

@classmethod
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
guild: Optional[Union[Guild, PartialInviteGuild]]
Expand Down Expand Up @@ -565,6 +569,14 @@ def url(self) -> str:
url += f"?event={self.guild_scheduled_event.id}"
return url

@property
def flags(self) -> InviteFlags:
""":class:`InviteFlags`: Invite's flags.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
""":class:`InviteFlags`: Invite's flags.
""":class:`InviteFlags`: Returns the invite's flags.


.. versionadded:: 2.10
"""
return InviteFlags._from_value(self._flags)

async def delete(self, *, reason: Optional[str] = None) -> None:
"""|coro|

Expand Down
10 changes: 10 additions & 0 deletions disnake/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,16 @@ def flags(self) -> MemberFlags:
"""
return MemberFlags._from_value(self._flags)

def is_guest(self) -> bool:
"""Whether this member joined the guild as a guest (i.e., via a guest invite).

Returns
-------
:class:`bool`
Whether the member is a guest.
"""
return self.joined_at is None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a new member flag, IS_GUEST = 1<<4, which should be more reliable for this. A utility method like this which just returns self.flags.is_guest is still useful, though.


@overload
async def ban(
self,
Expand Down
11 changes: 11 additions & 0 deletions docs/api/invites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ PartialInviteChannel
.. autoclass:: PartialInviteChannel()
:members:

Data Classes
------------

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

.. attributetable:: InviteFlags

.. autoclass:: InviteFlags()
:members:

Enumerations
------------

Expand Down