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

@ -72,8 +72,8 @@ class Client:
.. _ProxyConnector: http://aiohttp.readthedocs.org/en/stable/client_reference.html#proxyconnector
Parameters
----------
max_messages : Optional[int]
-----------
max_messages : Optional[:class:`int`]
The maximum number of messages to store in the internal message cache.
This defaults to 5000. Passing in `None` or a value less than 100
will use the default instead of the passed in value.
@ -82,24 +82,24 @@ class Client:
in which case the default event loop is used via ``asyncio.get_event_loop()``.
connector : aiohttp.BaseConnector
The `connector`_ to use for connection pooling.
proxy : Optional[str]
proxy : Optional[:class:`str`]
Proxy URL.
proxy_auth : Optional[aiohttp.BasicAuth]
An object that represents proxy HTTP Basic Authorization.
shard_id : Optional[int]
shard_id : Optional[:class:`int`]
Integer starting at 0 and less than shard_count.
shard_count : Optional[int]
shard_count : Optional[:class:`int`]
The total number of shards.
fetch_offline_members: bool
fetch_offline_members: :class:`bool`
Indicates if :func:`on_ready` should be delayed to fetch all offline
members from the guilds the bot belongs to. If this is ``False``\, then
no offline members are received and :meth:`request_offline_members`
must be used to fetch the offline members of the guild.
game: Optional[:class:`Game`]
A game to start your presence with upon logging on to Discord.
status: Optional[:class:`Status`]
A status to start your presence with upon logging on to Discord.
heartbeat_timeout: float
activity: Optional[Union[:class:`Activity`, :class:`Game`, :class:`Streaming`]]
An activity to start your presence with upon logging on to Discord.
heartbeat_timeout: :class:`float`
The maximum numbers of seconds before timing out and restarting the
WebSocket in the case of not receiving a HEARTBEAT_ACK. Useful if
processing the initial packets take too long to the point of disconnecting
@ -794,23 +794,24 @@ class Client:
return self.event(coro)
@asyncio.coroutine
def change_presence(self, *, game=None, status=None, afk=False):
def change_presence(self, *, activity=None, status=None, afk=False):
"""|coro|
Changes the client's presence.
The game parameter is a Game object (not a string) that represents
a game being played currently.
The activity parameter is a :class:`Activity` object (not a string) that represents
the activity being done currently. This could also be the slimmed down versions,
:class:`Game` and :class:`Streaming`.
Example: ::
game = discord.Game(name="with the API")
await client.change_presence(status=discord.Status.idle, game=game)
game = discord.Game("with the API")
await client.change_presence(status=discord.Status.idle, activity=game)
Parameters
----------
game: Optional[:class:`Game`]
The game being played. None if no game is being played.
activity: Optional[Union[:class:`Game`, :class:`Streaming`, :class:`Activity`]]
The activity being done. ``None`` if no currently active activity is done.
status: Optional[:class:`Status`]
Indicates what status to change to. If None, then
:attr:`Status.online` is used.
@ -822,7 +823,7 @@ class Client:
Raises
------
InvalidArgument
If the ``game`` parameter is not :class:`Game` or None.
If the ``activity`` parameter is not the proper type.
"""
if status is None:
@ -835,14 +836,14 @@ class Client:
status_enum = status
status = str(status)
yield from self.ws.change_presence(game=game, status=status, afk=afk)
yield from self.ws.change_presence(activity=activity, status=status, afk=afk)
for guild in self._connection.guilds:
me = guild.me
if me is None:
continue
me.game = game
me.activity = activity
me.status = status_enum
# Guild stuff