diff options
| author | Rapptz <[email protected]> | 2017-01-04 05:16:59 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-04 05:16:59 -0500 |
| commit | 808a05ff2dd37c63020d099827e4248b4e49059d (patch) | |
| tree | 558b4198394be13f90e22556b3801e461496e9cd /discord/state.py | |
| parent | Update examples to match the new rewrite API. (diff) | |
| download | discord.py-808a05ff2dd37c63020d099827e4248b4e49059d.tar.xz discord.py-808a05ff2dd37c63020d099827e4248b4e49059d.zip | |
Move global user cache to a WeakValueDictionary.
Diffstat (limited to 'discord/state.py')
| -rw-r--r-- | discord/state.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/discord/state.py b/discord/state.py index e839d5ab..1629b8db 100644 --- a/discord/state.py +++ b/discord/state.py @@ -42,6 +42,7 @@ import copy, enum, math import datetime import asyncio import logging +import weakref class ListenerType(enum.Enum): chunk = 0 @@ -66,8 +67,8 @@ class ConnectionState: self.user = None self.sequence = None self.session_id = None + self._users = weakref.WeakValueDictionary() self._calls = {} - self._users = {} self._emojis = {} self._guilds = {} self._voice_clients = {} @@ -133,6 +134,9 @@ class ConnectionState: self._users[user_id] = user = User(state=self, data=data) return user + def get_user(self, id): + return self._users.get(id) + def store_emoji(self, guild, data): emoji_id = int(data['id']) try: |