Add support for "Do Not Disturb" and "Invisible" statuses.
This deprecates Client.change_status in favour of the newer and more correct Client.change_presence.
This commit is contained in:
@ -29,7 +29,7 @@ import websockets
|
||||
import asyncio
|
||||
import aiohttp
|
||||
from . import utils, compat
|
||||
from .enums import Status
|
||||
from .enums import Status, try_enum
|
||||
from .game import Game
|
||||
from .errors import GatewayNotFound, ConnectionClosed, InvalidArgument
|
||||
import logging
|
||||
@ -406,18 +406,25 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
raise ConnectionClosed(e) from e
|
||||
|
||||
@asyncio.coroutine
|
||||
def change_presence(self, *, game=None, idle=None):
|
||||
def change_presence(self, *, game=None, status=None, afk=False, since=0.0, idle=None):
|
||||
if game is not None and not isinstance(game, Game):
|
||||
raise InvalidArgument('game must be of Game or None')
|
||||
|
||||
idle_since = None if idle == False else int(time.time() * 1000)
|
||||
if idle:
|
||||
status = 'idle'
|
||||
|
||||
if status == 'idle':
|
||||
since = int(time.time() * 1000)
|
||||
|
||||
sent_game = dict(game) if game else None
|
||||
|
||||
payload = {
|
||||
'op': self.PRESENCE,
|
||||
'd': {
|
||||
'game': sent_game,
|
||||
'idle_since': idle_since
|
||||
'afk': afk,
|
||||
'since': since,
|
||||
'status': status
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,14 +432,17 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
log.debug('Sending "{}" to change status'.format(sent))
|
||||
yield from self.send(sent)
|
||||
|
||||
status_enum = try_enum(Status, status)
|
||||
if status_enum is Status.invisible:
|
||||
status_enum = Status.offline
|
||||
|
||||
for server in self._connection.servers:
|
||||
me = server.me
|
||||
if me is None:
|
||||
continue
|
||||
|
||||
me.game = game
|
||||
status = Status.idle if idle_since else Status.online
|
||||
me.status = status
|
||||
me.status = status_enum
|
||||
|
||||
@asyncio.coroutine
|
||||
def request_sync(self, guild_ids):
|
||||
|
Reference in New Issue
Block a user