Split Game object to separate Activity subtypes for Rich Presences.

This is a massive breaking change.

* All references to "game" have been renamed to "activity"
* Activity objects contain a majority of the rich presence information
* Game and Streaming are subtypes for memory optimisation purposes for
  the more common cases.
* Introduce a more specialised read-only type, Spotify, for the
  official Spotify integration to make it easier to use.
This commit is contained in:
Rapptz
2018-03-05 11:01:46 -05:00
parent 2f562bd695
commit f8f8f418f3
12 changed files with 708 additions and 150 deletions

View File

@ -32,7 +32,7 @@ import discord.abc
from . import utils
from .user import BaseUser, User
from .game import Game
from .activity import create_activity
from .permissions import Permissions
from .enums import Status, try_enum
from .colour import Colour
@ -137,25 +137,25 @@ class Member(discord.abc.Messageable, _BaseUser):
Attributes
----------
roles
roles: List[:class:`Role`]
A :class:`list` of :class:`Role` that the member belongs to. Note that the first element of this
list is always the default '@everyone' role. These roles are sorted by their position
in the role hierarchy.
joined_at : `datetime.datetime`
joined_at: `datetime.datetime`
A datetime object that specifies the date and time in UTC that the member joined the guild for
the first time.
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.
game : :class:`Game`
The game that the user is currently playing. Could be None if no game is being played.
guild : :class:`Guild`
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.
guild: :class:`Guild`
The guild that the member belongs to.
nick : Optional[:class:`str`]
nick: Optional[:class:`str`]
The guild specific nickname of the user.
"""
__slots__ = ('roles', 'joined_at', 'status', 'game', 'guild', 'nick', '_user', '_state')
__slots__ = ('roles', 'joined_at', 'status', 'activity', 'guild', 'nick', '_user', '_state')
def __init__(self, *, data, guild, state):
self._state = state
@ -164,8 +164,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
game = data.get('game', {})
self.game = Game(**game) if game else None
self.activity = create_activity(data.get('game'))
self.nick = data.get('nick', None)
def __str__(self):
@ -218,8 +217,8 @@ class Member(discord.abc.Messageable, _BaseUser):
def _presence_update(self, data, user):
self.status = try_enum(Status, data['status'])
game = data.get('game', {})
self.game = Game(**game) if game else None
self.activity = create_activity(data.get('game'))
u = self._user
u.name = user.get('username', u.name)
u.avatar = user.get('avatar', u.avatar)