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

feat: add guest invites #1083

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4629,6 +4629,14 @@ ApplicationFlags
.. autoclass:: ApplicationFlags
:members:

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

.. attributetable:: InviteFlags

.. autoclass:: InviteFlags
:members:

File
~~~~

Expand Down
39 changes: 39 additions & 0 deletions nextcord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"MemberCacheFlags",
"ApplicationFlags",
"ChannelFlags",
"InviteFlags",
)

BF = TypeVar("BF", bound="BaseFlags")
Expand Down Expand Up @@ -1297,3 +1298,41 @@ def active(self):
.. versionadded:: 2.4
"""
return 1 << 24


@fill_with_flags()
class InviteFlags(BaseFlags):
r"""Wraps up the Discord Guild Flags.
spifory marked this conversation as resolved.
Show resolved Hide resolved

.. container:: operations

.. describe:: x == y

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

Checks if two InviteFlags are not equal.
.. 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.

.. versionadded:: 2.6

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 invite is a guest invite.
spifory marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 2.6"""
spifory marked this conversation as resolved.
Show resolved Hide resolved
return 1 << 0
1 change: 1 addition & 0 deletions nextcord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class Guild(Hashable):
- ``DEVELOPER_SUPPORT_SERVER``: Guild has been set as a support server on the App Directory.
- ``DISCOVERABLE``: Guild shows up in Server Discovery.
- ``FEATURABLE``: Guild is able to be featured in Server Discovery.
- ``GUESTS_ENABLED``: Guild has access to guild invites
spifory marked this conversation as resolved.
Show resolved Hide resolved
- ``INVITES_DISABLED``: Guild has paused invites, preventing new users from joining.
- ``INVITE_SPLASH``: Guild's invite page can have a special splash.
- ``MEMBER_VERIFICATION_GATE_ENABLED``: Guild has Membership Screening enabled.
Expand Down
8 changes: 8 additions & 0 deletions nextcord/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .types.invite import (
GatewayInvite as GatewayInvitePayload,
Invite as InvitePayload,
InviteFlags as InviteFlagsPayload,
InviteGuild as InviteGuildPayload,
VanityInvite as VanityInvitePayload,
)
Expand Down Expand Up @@ -293,6 +294,10 @@ class Invite(Hashable):
The embedded application the invite targets, if any.

.. versionadded:: 2.0
flags: Optional[:class:`InviteFlags`]
The invite's flags.

.. versionadded:: 2.6
"""

__slots__ = (
Expand All @@ -313,6 +318,7 @@ class Invite(Hashable):
"approximate_presence_count",
"target_application",
"expires_at",
"flags",
)

BASE = "https://discord.gg"
Expand Down Expand Up @@ -363,6 +369,8 @@ def __init__(
PartialAppInfo(data=application, state=state) if application else None
)

self.flags: Optional[InviteFlagsPayload] = data.get("flags")
spifory marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
guild: Optional[Union[Guild, PartialInviteGuild]]
Expand Down
1 change: 1 addition & 0 deletions nextcord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class UnavailableGuild(TypedDict):
"DEVELOPER_SUPPORT_SERVER",
"DISCOVERABLE",
"FEATURABLE",
"GUESTS_ENABLED",
"INVITES_DISABLED",
"INVITE_SPLASH",
"MEMBER_VERIFICATION_GATE_ENABLED",
Expand Down
3 changes: 3 additions & 0 deletions nextcord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing_extensions import NotRequired

from ..flags import InviteFlags
spifory marked this conversation as resolved.
Show resolved Hide resolved
from .appinfo import PartialAppInfo
from .channel import PartialChannel
from .guild import InviteGuild, _GuildPreviewUnique
Expand Down Expand Up @@ -40,6 +41,7 @@ class Invite(IncompleteInvite, total=False):
target_user: PartialUser
target_type: InviteTargetType
target_application: PartialAppInfo
flags: InviteFlags


class InviteWithCounts(Invite, _GuildPreviewUnique):
Expand All @@ -59,6 +61,7 @@ class GatewayInviteCreate(TypedDict):
target_type: NotRequired[InviteTargetType]
target_user: NotRequired[PartialUser]
target_application: NotRequired[PartialAppInfo]
flags: InviteFlags
spifory marked this conversation as resolved.
Show resolved Hide resolved


class GatewayInviteDelete(TypedDict):
Expand Down