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 14 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
40 changes: 40 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,42 @@ def active(self):
.. versionadded:: 2.4
"""
return 1 << 24


@fill_with_flags()
class InviteFlags(BaseFlags):
r"""Wraps up the Invite Flags.

.. 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 the invite is a guest invite.

.. versionadded:: 2.6
"""
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 guest invites
- ``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
12 changes: 12 additions & 0 deletions nextcord/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing_extensions import Self

from .abc import GuildChannel
from .flags import InviteFlags
from .guild import Guild
from .state import ConnectionState
from .types.channel import PartialChannel as InviteChannelPayload
Expand Down Expand Up @@ -313,6 +314,7 @@ class Invite(Hashable):
"approximate_presence_count",
"target_application",
"expires_at",
"_flags",
)

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

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

@classmethod
def from_incomplete(cls, *, state: ConnectionState, data: InvitePayload) -> Self:
guild: Optional[Union[Guild, PartialInviteGuild]]
Expand Down Expand Up @@ -486,3 +490,11 @@ async def delete(self, *, reason: Optional[str] = None) -> None:
return

await self._state.http.delete_invite(self.code, reason=reason)

@property
def flags(self) -> InviteFlags:
""":class:`InviteFlags`: The avaliable flags the invite has.

.. versionadded:: 2.6
"""
return InviteFlags._from_value(self._flags)
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
2 changes: 2 additions & 0 deletions nextcord/types/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Invite(IncompleteInvite, total=False):
target_user: PartialUser
target_type: InviteTargetType
target_application: PartialAppInfo
flags: int


class InviteWithCounts(Invite, _GuildPreviewUnique):
Expand All @@ -59,6 +60,7 @@ class GatewayInviteCreate(TypedDict):
target_type: NotRequired[InviteTargetType]
target_user: NotRequired[PartialUser]
target_application: NotRequired[PartialAppInfo]
flags: int


class GatewayInviteDelete(TypedDict):
Expand Down