Browse Source

Some widget fixes.

pull/2014/head
Rapptz 6 years ago
parent
commit
2ce42b5b50
  1. 22
      discord/widget.py
  2. 19
      docs/api.rst

22
discord/widget.py

@ -26,7 +26,7 @@ DEALINGS IN THE SOFTWARE.
from .utils import snowflake_time, _get_as_snowflake, resolve_invite from .utils import snowflake_time, _get_as_snowflake, resolve_invite
from .user import BaseUser from .user import BaseUser
from .activity import Activity from .activity import create_activity
from .invite import Invite from .invite import Invite
from .enums import Status, try_enum from .enums import Status, try_enum
from collections import namedtuple from collections import namedtuple
@ -115,7 +115,7 @@ class WidgetMember(BaseUser):
The member's nickname. The member's nickname.
avatar: Optional[:class:`str`] avatar: Optional[:class:`str`]
The member's avatar hash. The member's avatar hash.
activity: Optional[:class:`Activity`] activity: Optional[Union[:class:`Activity`, :class:`Game`, :class:`Streaming`, :class:`Spotify`]]
The member's activity. The member's activity.
deafened: Optional[:class:`bool`] deafened: Optional[:class:`bool`]
Whether the member is currently deafened. Whether the member is currently deafened.
@ -138,9 +138,12 @@ class WidgetMember(BaseUser):
self.muted = data.get('mute', False) or data.get('self_mute', False) self.muted = data.get('mute', False) or data.get('self_mute', False)
self.suppress = data.get('suppress', False) self.suppress = data.get('suppress', False)
game = data.get('game') try:
if game: game = data['game']
self.activity = Activity(**game) except KeyError:
self.activity = None
else:
self.activity = create_activity(game)
self.connected_channel = connected_channel self.connected_channel = connected_channel
@ -211,14 +214,19 @@ class Widget:
@property @property
def created_at(self): def created_at(self):
"""Returns the member's creation time in UTC.""" """:class:`datetime.datetime`: Returns the member's creation time in UTC."""
return snowflake_time(self.id) return snowflake_time(self.id)
@property @property
def json_url(self): def json_url(self):
"""The JSON URL of the widget.""" """:class:`str`: The JSON URL of the widget."""
return "https://discordapp.com/api/guilds/{0.id}/widget.json".format(self) return "https://discordapp.com/api/guilds/{0.id}/widget.json".format(self)
@property
def invite_url(self):
"""Optiona[:class:`str`]: The invite URL for the guild, if available."""
return self._invite
async def fetch_invite(self, *, with_counts=True): async def fetch_invite(self, *, with_counts=True):
"""|coro| """|coro|

19
docs/api.rst

@ -2074,6 +2074,25 @@ Invite
.. autoclass:: Invite() .. autoclass:: Invite()
:members: :members:
WidgetChannel
~~~~~~~~~~~~~~~
.. autoclass:: WidgetChannel()
:members:
WidgetMember
~~~~~~~~~~~~~
.. autoclass:: WidgetMember()
:members:
:inherited-members:
Widget
~~~~~~~
.. autoclass:: Widget()
:members:
RawMessageDeleteEvent RawMessageDeleteEvent
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~

Loading…
Cancel
Save