Browse Source

Members now have status info.

pull/1/head
Rapptz 10 years ago
parent
commit
3aa8cc93a7
  1. 16
      discord/client.py
  2. 10
      discord/server.py

16
discord/client.py

@ -61,6 +61,8 @@ class Client(object):
A number of options can be passed to the :class:`Client` via keyword arguments.
:param int max_length: The maximum number of messages to store in :attr:`messages`. Defaults to 5000.
:param bool no_offline_members: If this is set to True, then the :attr:`Server.member` lists
will only have members that are online. Defaults to False.
Instance attributes:
@ -87,6 +89,7 @@ class Client(object):
self.private_channels = []
self.token = ''
self.messages = deque([], maxlen=kwargs.get('max_length', 5000))
self.no_offline_members = kwargs.get('no_offline_members', False)
self.events = {
'on_ready': _null_event,
'on_disconnect': _null_event,
@ -167,6 +170,19 @@ class Client(object):
roles[j] = role
members[i] = Member(**member)
for presence in guild['presences']:
user_id = presence['user']['id']
member = next((m for m in members if member.id == user_id), None)
if member is not None:
member.status = presence['status']
member.game_id = presence['game_id']
# prune offline lists if wanted
if self.no_offline_members:
pruned = filter(lambda m: m.status == 'offline', members)
for member in pruned:
members.remove(member)
server = Server(**guild)
for channel in guild['channels']:
changed_roles = []

10
discord/server.py

@ -68,8 +68,14 @@ class Member(User):
An array of :class:`Role` that the member belongs to.
.. attribute:: joined_at
A datetime object that specifies the date and time that the member joined the server for
A datetime object that specifies the date and time in UTC that the member joined the server for
the first time.
,, attribute:: status
A string that denotes the user's status. Can be 'online', 'offline' or 'idle'.
.. attribute:: game_id
The game ID that the user is currently playing. Could be None if no game is being played.
"""
def __init__(self, deaf, joined_at, user, roles, mute):
@ -78,6 +84,8 @@ class Member(User):
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
class Server(object):
"""Represents a Discord server.

Loading…
Cancel
Save