mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Keep track of Emoji instances myself.
WeakValueDictionary cleans up too late and brings too little benefit. Also clean up the state when the first READY is encountered for AutoShardedClient and when any READY is encountered in regular Client.
This commit is contained in:
parent
e1c32626ba
commit
7f58853e3a
@ -73,7 +73,7 @@ class Emoji(Hashable):
|
||||
A list of :class:`Role` that is allowed to use this emoji. If roles is empty,
|
||||
the emoji is unrestricted.
|
||||
"""
|
||||
__slots__ = ('require_colons', 'managed', 'id', 'name', 'roles', 'guild', '_state', '__weakref__')
|
||||
__slots__ = ('require_colons', 'managed', 'id', 'name', 'roles', 'guild', '_state')
|
||||
|
||||
def __init__(self, *, guild, state, data):
|
||||
self.guild = guild
|
||||
|
@ -70,7 +70,7 @@ class ConnectionState:
|
||||
def clear(self):
|
||||
self.user = None
|
||||
self._users = weakref.WeakValueDictionary()
|
||||
self._emojis = weakref.WeakValueDictionary()
|
||||
self._emojis = {}
|
||||
self._calls = {}
|
||||
self._guilds = {}
|
||||
self._voice_clients = {}
|
||||
@ -157,6 +157,11 @@ class ConnectionState:
|
||||
def _remove_guild(self, guild):
|
||||
self._guilds.pop(guild.id, None)
|
||||
|
||||
for emoji in guild.emojis:
|
||||
self._emojis.pop(emoji.id, None)
|
||||
|
||||
del guild
|
||||
|
||||
@property
|
||||
def emojis(self):
|
||||
return list(self._emojis.values())
|
||||
@ -249,6 +254,7 @@ class ConnectionState:
|
||||
|
||||
def parse_ready(self, data):
|
||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
||||
self.clear()
|
||||
self.user = ClientUser(state=self, data=data['user'])
|
||||
|
||||
guilds = self._ready_state.guilds
|
||||
@ -760,7 +766,6 @@ class ConnectionState:
|
||||
class AutoShardedConnectionState(ConnectionState):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
||||
self._ready_task = None
|
||||
|
||||
@asyncio.coroutine
|
||||
@ -817,6 +822,7 @@ class AutoShardedConnectionState(ConnectionState):
|
||||
def parse_ready(self, data):
|
||||
if not hasattr(self, '_ready_state'):
|
||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
||||
self.clear()
|
||||
|
||||
self.user = ClientUser(state=self, data=data['user'])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user