Add Widget.presence_count attribute and fix Widget types

This commit is contained in:
metro
2022-03-11 21:51:40 -05:00
committed by GitHub
parent 9dea6caf20
commit 124a3ee42a
3 changed files with 23 additions and 16 deletions

View File

@ -231,7 +231,7 @@ class Widget:
channels: List[:class:`WidgetChannel`]
The accessible voice channels in the guild.
members: List[:class:`Member`]
The online members in the server. Offline members
The online members in the guild. Offline members
do not appear in the widget.
.. note::
@ -240,10 +240,15 @@ class Widget:
the users will be "anonymized" with linear IDs and discriminator
information being incorrect. Likewise, the number of members
retrieved is capped.
presence_count: :class:`int`
The approximate number of online members in the guild.
Offline members are not included in this count.
.. versionadded:: 2.0
"""
__slots__ = ('_state', 'channels', '_invite', 'id', 'members', 'name')
__slots__ = ('_state', 'channels', '_invite', 'id', 'members', 'name', 'presence_count')
def __init__(self, *, state: ConnectionState, data: WidgetPayload) -> None:
self._state = state
@ -268,6 +273,8 @@ class Widget:
self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel))
self.presence_count: int = data['presence_count']
def __str__(self) -> str:
return self.json_url
@ -290,11 +297,11 @@ class Widget:
return f"https://discord.com/api/guilds/{self.id}/widget.json"
@property
def invite_url(self) -> str:
def invite_url(self) -> Optional[str]:
"""Optional[:class:`str`]: The invite URL for the guild, if available."""
return self._invite
async def fetch_invite(self, *, with_counts: bool = True) -> Invite:
async def fetch_invite(self, *, with_counts: bool = True) -> Optional[Invite]:
"""|coro|
Retrieves an :class:`Invite` from the widget's invite URL.
@ -310,9 +317,11 @@ class Widget:
Returns
--------
:class:`Invite`
The invite from the widget's invite URL.
Optional[:class:`Invite`]
The invite from the widget's invite URL, if available.
"""
resolved = resolve_invite(self._invite)
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
return Invite.from_incomplete(state=self._state, data=data)
if self._invite:
resolved = resolve_invite(self._invite)
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
return Invite.from_incomplete(state=self._state, data=data)
return None