aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-11-27 17:29:36 -0500
committerRapptz <[email protected]>2015-11-27 17:29:36 -0500
commite884119cd99e8a9c461d373598d0aa0239fef511 (patch)
treef417e25c52b6e3fbb0fbb9342f65c818313c657f
parentAdd LoginFailure exception for a clearer failure in Client.login (diff)
downloaddiscord.py-e884119cd99e8a9c461d373598d0aa0239fef511.tar.xz
discord.py-e884119cd99e8a9c461d373598d0aa0239fef511.zip
Performance improvements in on_typing event.
-rw-r--r--discord/client.py15
-rw-r--r--docs/api.rst5
2 files changed, 10 insertions, 10 deletions
diff --git a/discord/client.py b/discord/client.py
index 203664dc..b26cf6f4 100644
--- a/discord/client.py
+++ b/discord/client.py
@@ -401,16 +401,15 @@ class ConnectionState(object):
if channel is not None:
member = None
user_id = data.get('user_id')
- if not getattr(channel, 'is_private', True):
+ is_private = getattr(channel, 'is_private', None)
+ if is_private == None:
+ return
+
+ if is_private:
+ member = channel.user
+ else:
members = channel.server.members
member = utils.find(lambda m: m.id == user_id, members)
- else:
- # At the moment we can make the assumption that if we are
- # in a private channel then the user belongs to one of our
- # already existing server member lists.
- # This might change when we get friend lists.
- gen = (m for s in self.servers for m in s.members)
- member = utils.find(lambda m: m.id == user_id, gen)
if member is not None:
timestamp = datetime.datetime.utcfromtimestamp(data.get('timestamp'))
diff --git a/docs/api.rst b/docs/api.rst
index 3463e2f8..d5dc0e2f 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -251,10 +251,11 @@ to handle it, which defaults to print a traceback and ignore the exception.
Called when someone begins typing a message.
The ``channel`` parameter could either be a :class:`PrivateChannel` or a
- :class:`Channel`.
+ :class:`Channel`. If ``channel`` is a :class:`PrivateChannel` then the
+ ``user`` parameter is a :class:`User`, otherwise it is a :class:`Member`.
:param channel: The location where the typing originated from.
- :param user: The :class:`Member` that started typing.
+ :param user: The user that started typing.
:param when: A ``datetime.datetime`` object representing when typing started.