mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Add Widget.presence_count attribute and fix Widget types
This commit is contained in:
parent
9dea6caf20
commit
124a3ee42a
@ -46,18 +46,15 @@ class WidgetMember(User, total=False):
|
|||||||
suppress: bool
|
suppress: bool
|
||||||
|
|
||||||
|
|
||||||
class _WidgetOptional(TypedDict, total=False):
|
class Widget(TypedDict):
|
||||||
|
id: Snowflake
|
||||||
|
name: str
|
||||||
|
instant_invite: Optional[str]
|
||||||
channels: List[WidgetChannel]
|
channels: List[WidgetChannel]
|
||||||
members: List[WidgetMember]
|
members: List[WidgetMember]
|
||||||
presence_count: int
|
presence_count: int
|
||||||
|
|
||||||
|
|
||||||
class Widget(_WidgetOptional):
|
|
||||||
id: Snowflake
|
|
||||||
name: str
|
|
||||||
instant_invite: str
|
|
||||||
|
|
||||||
|
|
||||||
class WidgetSettings(TypedDict):
|
class WidgetSettings(TypedDict):
|
||||||
enabled: bool
|
enabled: bool
|
||||||
channel_id: Optional[Snowflake]
|
channel_id: Optional[Snowflake]
|
||||||
|
@ -231,7 +231,7 @@ class Widget:
|
|||||||
channels: List[:class:`WidgetChannel`]
|
channels: List[:class:`WidgetChannel`]
|
||||||
The accessible voice channels in the guild.
|
The accessible voice channels in the guild.
|
||||||
members: List[:class:`Member`]
|
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.
|
do not appear in the widget.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
@ -240,10 +240,15 @@ class Widget:
|
|||||||
the users will be "anonymized" with linear IDs and discriminator
|
the users will be "anonymized" with linear IDs and discriminator
|
||||||
information being incorrect. Likewise, the number of members
|
information being incorrect. Likewise, the number of members
|
||||||
retrieved is capped.
|
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:
|
def __init__(self, *, state: ConnectionState, data: WidgetPayload) -> None:
|
||||||
self._state = state
|
self._state = state
|
||||||
@ -268,6 +273,8 @@ class Widget:
|
|||||||
|
|
||||||
self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel))
|
self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel))
|
||||||
|
|
||||||
|
self.presence_count: int = data['presence_count']
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.json_url
|
return self.json_url
|
||||||
|
|
||||||
@ -290,11 +297,11 @@ class Widget:
|
|||||||
return f"https://discord.com/api/guilds/{self.id}/widget.json"
|
return f"https://discord.com/api/guilds/{self.id}/widget.json"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def invite_url(self) -> str:
|
def invite_url(self) -> Optional[str]:
|
||||||
"""Optional[:class:`str`]: The invite URL for the guild, if available."""
|
"""Optional[:class:`str`]: The invite URL for the guild, if available."""
|
||||||
return self._invite
|
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|
|
"""|coro|
|
||||||
|
|
||||||
Retrieves an :class:`Invite` from the widget's invite URL.
|
Retrieves an :class:`Invite` from the widget's invite URL.
|
||||||
@ -310,9 +317,11 @@ class Widget:
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
--------
|
--------
|
||||||
:class:`Invite`
|
Optional[:class:`Invite`]
|
||||||
The invite from the widget's invite URL.
|
The invite from the widget's invite URL, if available.
|
||||||
"""
|
"""
|
||||||
|
if self._invite:
|
||||||
resolved = resolve_invite(self._invite)
|
resolved = resolve_invite(self._invite)
|
||||||
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
|
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
|
||||||
return Invite.from_incomplete(state=self._state, data=data)
|
return Invite.from_incomplete(state=self._state, data=data)
|
||||||
|
return None
|
||||||
|
@ -927,6 +927,7 @@ The following changes have been made:
|
|||||||
|
|
||||||
- :attr:`DMChannel.recipient` may now be ``None``.
|
- :attr:`DMChannel.recipient` may now be ``None``.
|
||||||
- :meth:`Guild.vanity_invite` may now be ``None``. This has been done to fix an issue with the method returning a broken :class:`Invite` object.
|
- :meth:`Guild.vanity_invite` may now be ``None``. This has been done to fix an issue with the method returning a broken :class:`Invite` object.
|
||||||
|
- :meth:`Widget.fetch_invite` may now be ``None``.
|
||||||
- :attr:`Guild.shard_id` is now ``0`` instead of ``None`` if :class:`AutoShardedClient` is not used.
|
- :attr:`Guild.shard_id` is now ``0`` instead of ``None`` if :class:`AutoShardedClient` is not used.
|
||||||
- :attr:`Guild.mfa_level` is now of type :class:`MFALevel`.
|
- :attr:`Guild.mfa_level` is now of type :class:`MFALevel`.
|
||||||
- :attr:`Guild.member_count` is now of type Optional[:class:`int`].
|
- :attr:`Guild.member_count` is now of type Optional[:class:`int`].
|
||||||
|
Loading…
x
Reference in New Issue
Block a user