Browse Source

Add on_member_ban and on_member_unban events.

Fixes #58.
pull/60/head
Rapptz 9 years ago
parent
commit
9075d46efd
  1. 3
      discord/client.py
  2. 20
      discord/state.py
  3. 15
      docs/api.rst

3
discord/client.py

@ -344,7 +344,8 @@ class Client:
'GUILD_MEMBER_ADD', 'GUILD_MEMBER_REMOVE', 'GUILD_UPDATE'
'GUILD_MEMBER_UPDATE', 'GUILD_CREATE', 'GUILD_DELETE',
'GUILD_ROLE_CREATE', 'GUILD_ROLE_DELETE', 'TYPING_START',
'GUILD_ROLE_UPDATE', 'VOICE_STATE_UPDATE'):
'GUILD_ROLE_UPDATE', 'VOICE_STATE_UPDATE',
'GUILD_BAN_ADD', 'GUILD_BAN_REMOVE'):
parser = 'parse_' + event.lower()
getattr(self.connection, parser)(data)
else:

20
discord/state.py

@ -251,6 +251,26 @@ class ConnectionState:
else:
self.dispatch('server_remove', server)
def parse_guild_ban_add(self, data):
# we make the assumption that GUILD_BAN_ADD is done
# before GUILD_MEMBER_REMOVE is called
# hence we don't remove it from cache or do anything
# strange with it, the main purpose of this event
# is mainly to dispatch to another event worth listening to for logging
server = self._get_server(data.get('guild_id'))
if server is not None:
user_id = data.get('user', {}).get('id')
member = utils.get(server.members, id=user_id)
if member is not None:
self.dispatch('member_ban', member)
def parse_guild_ban_remove(self, data):
server = self._get_server(data.get('guild_id'))
if server is not None:
if 'user' in data:
user = User(**data['user'])
self.dispatch('member_unban', server, user)
def parse_guild_role_create(self, data):
server = self._get_server(data.get('guild_id'))
role_data = data.get('role', {})

15
docs/api.rst

@ -319,6 +319,21 @@ to handle it, which defaults to print a traceback and ignore the exception.
:param before: The :class:`Member` whose voice state changed prior to the changes.
:param after: The :class:`Member` whose voice state changed after the changes.
.. function:: on_member_ban(member)
Called when a :class:`Member` gets banned from a :class:`Server`.
You can access the server that the member got banned from via :attr:`Member.server`.
:param member: The member that got banned.
.. function:: on_member_unban(server, user)
Called when a :class:`User` gets unbanned from a :class:`Server`.
:param server: The server the user got unbanned from.
:param user: The user that got unbanned.
.. function:: on_typing(channel, user, when)
Called when someone begins typing a message.

Loading…
Cancel
Save