Expose more information from partial invites, along with counts.

This adds the following information.

* `PartialInviteGuild` to replace `Object` patching
* `PartialInviteChannel` to replace `Object` patching
* Invite.approximate_member_count and Invite.approximate_presence_count

The new partial objects provide better documentation on what is
expected when you fetch random invites.

Fixes #1830
This commit is contained in:
Rapptz
2019-02-12 20:21:29 -05:00
parent e2478b17c9
commit 5d78f43e55
6 changed files with 187 additions and 27 deletions

View File

@ -882,7 +882,7 @@ class Client:
# Invite management
async def get_invite(self, url):
async def get_invite(self, url, *, with_counts=True):
"""|coro|
Gets an :class:`Invite` from a discord.gg URL or ID.
@ -890,13 +890,17 @@ class Client:
Note
------
If the invite is for a guild you have not joined, the guild and channel
attributes of the returned invite will be :class:`Object` with the names
patched in.
attributes of the returned :class:`Invite` will be :class:`PartialInviteGuild` and
:class:`PartialInviteChannel` respectively.
Parameters
-----------
url : str
url: :class:`str`
The discord invite ID or URL (must be a discord.gg URL).
with_counts: :class:`bool`
Whether to include count information in the invite. This fills the
:attr:`Invite.approximate_member_count` and :attr:`Invite.approximate_presence_count`
fields.
Raises
-------
@ -912,7 +916,7 @@ class Client:
"""
invite_id = self._resolve_invite(url)
data = await self.http.get_invite(invite_id)
data = await self.http.get_invite(invite_id, with_counts=with_counts)
return Invite.from_incomplete(state=self._connection, data=data)
async def delete_invite(self, invite):