aboutsummaryrefslogtreecommitdiff
path: root/discord/shard.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-01-08 01:51:10 -0500
committerRapptz <[email protected]>2017-01-08 01:51:10 -0500
commit4bc6625739ba5166d26e927489f2c8317c8e9016 (patch)
tree403063a7c4226e7a1f60eec456e24fe73e891c49 /discord/shard.py
parentChange the way shards are launched in AutoShardedClient. (diff)
downloaddiscord.py-4bc6625739ba5166d26e927489f2c8317c8e9016.tar.xz
discord.py-4bc6625739ba5166d26e927489f2c8317c8e9016.zip
Add AutoShardedClient.change_presence.
Diffstat (limited to 'discord/shard.py')
-rw-r--r--discord/shard.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/discord/shard.py b/discord/shard.py
index df0973b3..53e90785 100644
--- a/discord/shard.py
+++ b/discord/shard.py
@@ -29,6 +29,7 @@ from .client import Client
from .gateway import *
from .errors import ConnectionClosed
from . import compat
+from .enums import Status
import asyncio
import logging
@@ -224,3 +225,62 @@ class AutoShardedClient(Client):
yield from self.http.close()
self._closed.set()
self._is_ready.clear()
+
+ @asyncio.coroutine
+ def change_presence(self, *, game=None, status=None, afk=False, shard_id=None):
+ """|coro|
+
+ Changes the client's presence.
+
+ The game parameter is a Game object (not a string) that represents
+ a game being played currently.
+
+ Parameters
+ ----------
+ game: Optional[:class:`Game`]
+ The game being played. None if no game is being played.
+ status: Optional[:class:`Status`]
+ Indicates what status to change to. If None, then
+ :attr:`Status.online` is used.
+ afk: bool
+ Indicates if you are going AFK. This allows the discord
+ client to know how to handle push notifications better
+ for you in case you are actually idle and not lying.
+ shard_id: Optional[int]
+ The shard_id to change the presence to. If not specified
+ or ``None``, then it will change the presence of every
+ shard the bot can see.
+
+ Raises
+ ------
+ InvalidArgument
+ If the ``game`` parameter is not :class:`Game` or None.
+ """
+
+ if status is None:
+ status = 'online'
+ status_enum = Status.online
+ elif status is Status.offline:
+ status = 'invisible'
+ status_enum = Status.offline
+ else:
+ status_enum = status
+ status = str(status)
+
+ if shard_id is None:
+ for shard in self.shards.values():
+ yield from shard.ws.change_presence(game=game, status=status, afk=afk)
+
+ guilds = self.connection.guilds
+ else:
+ shard = self.shards[shard_id]
+ yield from shard.ws.change_presence(game=game, status=status, afk=afk)
+ guilds = [g for g in self.connection.guilds if g.shard_id == shard_id]
+
+ for guild in guilds:
+ me = guild.me
+ if me is None:
+ continue
+
+ me.game = game
+ me.status = status_enum