Browse Source

Better detection for the everyone role. Fixes #23.

pull/25/head
Rapptz 10 years ago
parent
commit
d2741ca38a
  1. 9
      discord/client.py
  2. 4
      discord/role.py

9
discord/client.py

@ -158,7 +158,7 @@ class ConnectionState(object):
return member
def _add_server(self, guild):
guild['roles'] = [Role(**role) for role in guild['roles']]
guild['roles'] = [Role(everyone=(guild['id'] == role['id']), **role) for role in guild['roles']]
members = guild['members']
owner = guild['owner_id']
for i, member in enumerate(members):
@ -334,7 +334,9 @@ class ConnectionState(object):
def handle_guild_role_create(self, data):
server = self._get_server(data.get('guild_id'))
role = Role(**data.get('role', {}))
role_data = data.get('role', {})
everyone = server.id == role_data.get('id')
role = Role(everyone=everyone, **role_data)
server.roles.append(role)
self.dispatch('server_role_create', server, role)
@ -1183,7 +1185,8 @@ class Client(object):
if is_response_successful(response):
data = response.json()
role = Role(**data)
everyone = server.id == data.get('id')
role = Role(everyone=everyone, **data)
if self.edit_role(server, role, **fields):
# we have to call edit because you can't pass a payload to the
# http request currently.

4
discord/role.py

@ -197,8 +197,7 @@ class Role(object):
A boolean representing if the role will be displayed separately from other members.
.. attribute:: position
The position of the role. This number is usually positive. A non-positive value indicates that
this is the `@everyone` role.
The position of the role. This number is usually positive.
.. attribute:: managed
A boolean indicating if the role is managed by the server through some form of integration
@ -217,6 +216,7 @@ class Role(object):
self.hoist = kwargs.get('hoist', False)
self.managed = kwargs.get('managed', False)
self.color = self.colour
self._is_everyone = kwargs.get('everyone', False)
def is_everyone(self):
"""Checks if the role is the @everyone role."""

Loading…
Cancel
Save