Browse Source

Add support for multiple activities

pull/1739/head
SnowyLuma 7 years ago
committed by Rapptz
parent
commit
e89e7dfe93
  1. 2
      discord/client.py
  2. 2
      discord/guild.py
  3. 24
      discord/member.py
  4. 2
      discord/shard.py
  5. 4
      docs/locale/ja/LC_MESSAGES/migrating.po
  6. 2
      docs/migrating.rst

2
discord/client.py

@ -833,7 +833,7 @@ class Client:
if me is None:
continue
me.activity = activity
me.activities = (activity,)
me.status = status_enum
# Guild stuff

2
discord/guild.py

@ -246,7 +246,7 @@ class Guild(Hashable):
member = self.get_member(user_id)
if member is not None:
member.status = try_enum(Status, presence['status'])
member.activity = create_activity(presence.get('game'))
member.activities = tuple(map(create_activity, presence.get('activities', [])))
if 'channels' in data:
channels = data['channels']

24
discord/member.py

@ -142,15 +142,15 @@ class Member(discord.abc.Messageable, _BaseUser):
status : :class:`Status`
The member's status. There is a chance that the status will be a :class:`str`
if it is a value that is not recognised by the enumerator.
activity: Union[:class:`Game`, :class:`Streaming`, :class:`Activity`]
The activity that the user is currently doing. Could be None if no activity is being done.
activities: Tuple[Union[:class:`Game`, :class:`Streaming`, :class:`Spotify`, :class:`Activity`]]
The activities that the user is currently doing.
guild: :class:`Guild`
The guild that the member belongs to.
nick: Optional[:class:`str`]
The guild specific nickname of the user.
"""
__slots__ = ('_roles', 'joined_at', 'status', 'activity', 'guild', 'nick', '_user', '_state')
__slots__ = ('_roles', 'joined_at', 'status', 'activities', 'guild', 'nick', '_user', '_state')
def __init__(self, *, data, guild, state):
self._state = state
@ -159,7 +159,7 @@ class Member(discord.abc.Messageable, _BaseUser):
self.joined_at = utils.parse_time(data.get('joined_at'))
self._update_roles(data)
self.status = Status.offline
self.activity = create_activity(data.get('game'))
self.activities = tuple(map(create_activity, data.get('activities', [])))
self.nick = data.get('nick', None)
def __str__(self):
@ -187,7 +187,7 @@ class Member(discord.abc.Messageable, _BaseUser):
self.status = member.status
self.guild = member.guild
self.nick = member.nick
self.activity = member.activity
self.activities = member.activities
self._state = member._state
self._user = User._copy(member._user)
return self
@ -217,7 +217,7 @@ class Member(discord.abc.Messageable, _BaseUser):
def _presence_update(self, data, user):
self.status = try_enum(Status, data['status'])
self.activity = create_activity(data.get('game'))
self.activities = tuple(map(create_activity, data.get('activities', [])))
if len(user) > 1:
u = self._user
@ -286,6 +286,18 @@ class Member(discord.abc.Messageable, _BaseUser):
"""
return self.nick if self.nick is not None else self.name
@property
def activity(self):
"""Returns a class Union[:class:`Game`, :class:`Streaming`, :class:`Spotify`, :class:`Activity`] for the primary
activity the user is currently doing. Could be None if no activity is being done.
.. note::
A user may have multiple activities, these can be accessed under :attr:`activities`.
"""
if self.activities:
return self.activities[0]
def mentioned_in(self, message):
"""Checks if the member is mentioned in the specified message.

2
discord/shard.py

@ -353,5 +353,5 @@ class AutoShardedClient(Client):
if me is None:
continue
me.activity = activity
me.activities = (activity,)
me.status = status_enum

4
docs/locale/ja/LC_MESSAGES/migrating.po

@ -987,8 +987,8 @@ msgid "``Member.game``"
msgstr "``Member.game``"
#: ../../migrating.rst:369
msgid "Use :attr:`Member.activity` instead."
msgstr "代わりに :attr:`Member.activity` 使用してください。"
msgid "Use :attr:`Member.activities` instead."
msgstr "代わりに :attr:`Member.activities` 使用してください。"
#: ../../migrating.rst:371
msgid "``Guild.role_hierarchy`` / ``Server.role_hierarchy``"

2
docs/migrating.rst

@ -366,7 +366,7 @@ They will be enumerated here.
- ``Member.game``
- Use :attr:`Member.activity` instead.
- Use :attr:`Member.activities` instead.
- ``Guild.role_hierarchy`` / ``Server.role_hierarchy``

Loading…
Cancel
Save