diff options
| author | Rapptz <[email protected]> | 2016-07-15 22:03:22 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-07-15 22:03:22 -0400 |
| commit | 91351a3238c8b0ddf9710a870e3933323bcceabc (patch) | |
| tree | 3c2c880cce48f4f9b41b2e19184b754b31f20672 | |
| parent | Make PrivateChannel.__str__ more useful for groups. (diff) | |
| download | discord.py-91351a3238c8b0ddf9710a870e3933323bcceabc.tar.xz discord.py-91351a3238c8b0ddf9710a870e3933323bcceabc.zip | |
Handle adding and removal of group members.
| -rw-r--r-- | discord/state.py | 17 | ||||
| -rw-r--r-- | docs/api.rst | 9 |
2 files changed, 25 insertions, 1 deletions
diff --git a/discord/state.py b/discord/state.py index 7a8fc466..cf2af379 100644 --- a/discord/state.py +++ b/discord/state.py @@ -325,6 +325,22 @@ class ConnectionState: self.dispatch('channel_create', channel) + def parse_channel_recipient_add(self, data): + channel = self._get_private_channel(data.get('channel_id')) + user = User(**data.get('user', {})) + channel.recipients.append(user) + self.dispatch('group_join', channel, user) + + def parse_channel_recipient_remove(self, data): + channel = self._get_private_channel(data.get('channel_id')) + user = User(**data.get('user', {})) + try: + channel.recipients.remove(user) + except ValueError: + pass + else: + self.dispatch('group_remove', channel, user) + def _make_member(self, server, data): roles = [server.default_role] for roleid in data.get('roles', []): @@ -480,7 +496,6 @@ class ConnectionState: self._remove_server(server) 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 diff --git a/docs/api.rst b/docs/api.rst index e597e6d7..5ac83bef 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -331,6 +331,15 @@ to handle it, which defaults to print a traceback and ignore the exception. :param user: The user that started typing. :param when: A ``datetime.datetime`` object representing when typing started. +.. function:: on_group_join(channel, user) + on_group_remove(channel, user) + + Called when someone joins or leaves a group, i.e. a :class:`PrivateChannel` + with a :attr:`PrivateChannel.type` of :attr:`ChannelType.group`. + + :param channel: The group that the user joined or left. + :param user: The user that joined or left. + .. _discord-api-utils: Utility Functions |