From e89e7dfe93d758ef522d6db917f08cc4c868ba9a Mon Sep 17 00:00:00 2001 From: SnowyLuma Date: Thu, 25 Oct 2018 15:11:02 +0200 Subject: [PATCH] Add support for multiple activities --- discord/client.py | 2 +- discord/guild.py | 2 +- discord/member.py | 24 ++++++++++++++++++------ discord/shard.py | 2 +- docs/locale/ja/LC_MESSAGES/migrating.po | 4 ++-- docs/migrating.rst | 2 +- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/discord/client.py b/discord/client.py index 50eacb2a3..c0449cc05 100644 --- a/discord/client.py +++ b/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 diff --git a/discord/guild.py b/discord/guild.py index 1a747844d..add31d0fc 100644 --- a/discord/guild.py +++ b/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'] diff --git a/discord/member.py b/discord/member.py index f265a1be7..e8011d47f 100644 --- a/discord/member.py +++ b/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. diff --git a/discord/shard.py b/discord/shard.py index 6fd4e3cb5..0eb5c695f 100644 --- a/discord/shard.py +++ b/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 diff --git a/docs/locale/ja/LC_MESSAGES/migrating.po b/docs/locale/ja/LC_MESSAGES/migrating.po index 3f8f42cfc..2727dcd53 100644 --- a/docs/locale/ja/LC_MESSAGES/migrating.po +++ b/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``" diff --git a/docs/migrating.rst b/docs/migrating.rst index 3e9def24f..34ee1e1c8 100644 --- a/docs/migrating.rst +++ b/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``