Browse Source

on_status now takes only a member.

pull/1/head
Rapptz 10 years ago
parent
commit
795b8ceffe
  1. 18
      discord/client.py
  2. 6
      discord/server.py
  3. 13
      docs/api.rst

18
discord/client.py

@ -264,17 +264,21 @@ class Client(object):
server = next((s for s in self.servers if s.id == guild_id), None)
if server is not None:
status = data.get('status')
user = User(**data.get('user'))
member_id = data['user']['id']
# check to see if the member is in our server list of members
member = next((u for u in server.members if u == user), None)
member = next((u for u in server.members if u.id == member_id), None)
if member is None:
# create the member if it doesn't exist
member = Member(**data)
if status == 'online':
if member is None:
server.members.append(user)
if status == 'offline' and user in server.members:
server.members.remove(user)
server.members.append(member)
elif status == 'offline' and self.no_offline_members:
server.members.remove(member)
# call the event now
self._invoke_event('on_status', server, user, status, data.get('game_id'))
self._invoke_event('on_status', member)
elif event == 'USER_UPDATE':
self.user = User(**data)
elif event == 'CHANNEL_DELETE':

6
discord/server.py

@ -81,15 +81,15 @@ class Member(User):
The :class:`Server` that the member belongs to.
"""
def __init__(self, deaf, joined_at, user, roles, mute):
def __init__(self, deaf, joined_at, user, roles, mute, **kwargs):
super(Member, self).__init__(**user)
self.deaf = deaf
self.mute = mute
self.joined_at = datetime.datetime(*map(int, re.split(r'[^\d]', joined_at.replace('+00:00', ''))))
self.roles = roles
self.status = 'offline'
self.game_id = None
self.server = None
self.game_id = kwargs.get('game_id', None)
self.server = kwargs.get('server', None)
class Server(object):
"""Represents a Discord server.

13
docs/api.rst

@ -45,7 +45,7 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
:param response: The received message response after gone through ``json.loads``.
.. function:: on_message_delete(message)
.. function:: on_message_edit(before, after)
on_message_edit(before, after)
Called when a message is deleted or edited from any given server. If the message is not found in the
:attr:`Client.messages` cache, then these events will not be called. This happens if the message
@ -56,16 +56,11 @@ All events are 'sandboxed', in that if an exception is thrown while the event is
:param before: A :class:`Message` of the previous version of the message.
:param after: A :class:`Message` of the current version of the message.
.. function:: on_status(server, user, status, game_id):
.. function:: on_status(member):
Called whenever a user changes their status or game playing status.
Called whenever a :class:`Member` changes their status or game playing status.
The status is usually either "idle", "online" or "offline".
:param server: The :class:`Server` the user belongs to.
:param user: The :class:`User` whose status changed.
:param status: The new status of the user.
:param game_id: The game ID that the user is playing. Can be None.
:param server: The :class:`Member` who has had their status changed.
.. function:: on_channel_delete(channel)
on_channel_create(channel)

Loading…
Cancel
Save