From 3d03dbc45179f645b59838729047e896cc387049 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 24 Sep 2018 21:05:41 -0400 Subject: Change internal role storage in Guild to a dict instead of a list. This adds the following APIs: * Guild.get_role This removes the following APIs: * Guild.role_hierarchy To compensate for the removed APIs, Guild.roles is now a sorted list based on hierarchy. The first element will always be the @everyone role. This speeds up access at the cost of some memory, theoretically. --- discord/state.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'discord/state.py') diff --git a/discord/state.py b/discord/state.py index ea6b89de..7180509a 100644 --- a/discord/state.py +++ b/discord/state.py @@ -743,10 +743,9 @@ class ConnectionState: guild = self._get_guild(int(data['guild_id'])) if guild is not None: role_id = int(data['role_id']) - role = utils.find(lambda r: r.id == role_id, guild.roles) try: - guild._remove_role(role) - except ValueError: + role = guild._remove_role(role_id) + except KeyError: return else: self.dispatch('guild_role_delete', role) @@ -758,7 +757,7 @@ class ConnectionState: if guild is not None: role_data = data['role'] role_id = int(role_data['id']) - role = utils.find(lambda r: r.id == role_id, guild.roles) + role = guild.get_role(role_id) if role is not None: old_role = copy.copy(role) role._update(role_data) -- cgit v1.2.3