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: Implement helper methods for invites #1098

Merged
merged 4 commits into from Oct 8, 2022
Merged
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
4 changes: 1 addition & 3 deletions interactions/api/http/invite.py
Expand Up @@ -24,11 +24,9 @@ async def get_invite(
"""
Gets a Discord invite using its code.

.. note:: with_expiration is currently broken, the API will always return expiration_date.

:param invite_code: A string representing the invite code.
:param with_counts: Whether approximate_member_count and approximate_presence_count are returned.
:param with_expiration: Whether the invite's expiration is returned.
:param with_expiration: Whether the invite's expiration date is returned.
:param guild_scheduled_event_id: A guild scheduled event's ID.
"""
params_set = {
Expand Down
60 changes: 60 additions & 0 deletions interactions/api/models/guild.py
Expand Up @@ -2830,6 +2830,66 @@ async def get_full_audit_logs(

return AuditLogs(**_audit_log_dict)

async def get_invite(
self,
invite_code: str,
with_counts: Optional[bool] = MISSING,
with_expiration: Optional[bool] = MISSING,
guild_scheduled_event_id: Optional[int] = MISSING,
) -> "Invite":
"""
Gets the invite using its code.

:param str invite_code: A string representing the invite code.
:param Optional[bool] with_counts: Whether approximate_member_count and approximate_presence_count are returned.
:param Optional[bool] with_expiration: Whether the invite's expiration date is returned.
:param Optional[int] guild_scheduled_event_id: A guild scheduled event's ID.
:return: An invite
:rtype: Invite
"""
if not self._client:
raise LibraryException(code=13)

_with_counts = with_counts if with_counts is not MISSING else None
_with_expiration = with_expiration if with_expiration is not MISSING else None
_guild_scheduled_event_id = (
guild_scheduled_event_id if guild_scheduled_event_id is not MISSING else None
)

res = await self._client.get_invite(
invite_code=invite_code,
with_counts=_with_counts,
with_expiration=_with_expiration,
guild_scheduled_event_id=_guild_scheduled_event_id,
)

return Invite(**res, _client=self._client)

async def delete_invite(self, invite_code: str, reason: Optional[str] = None) -> None:
"""
Deletes the invite using its code.

:param str invite_code: A string representing the invite code.
:param Optional[str] reason: The reason of the deletion
"""
if not self._client:
raise LibraryException(code=13)

await self._client.delete_invite(invite_code=invite_code, reason=reason)

async def get_invites(self) -> List["Invite"]:
"""
Gets invites of the guild.

:return: A list of guild invites
:rtype: List[Invite]
"""
if not self._client:
raise LibraryException(code=13)

res = await self._client.get_guild_invites(guild_id=int(self.id))
return [Invite(**_, _client=self._client) for _ in res]

@property
def icon_url(self) -> Optional[str]:
"""
Expand Down