From 19201517fdaca6429cafb5d1eb4ef6edacb5e76f Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 28 Mar 2017 17:36:06 -0700 Subject: [PATCH] Fix smashing important state on GUILD_UPDATEs GUILD_UPDATES are cool and special and of course they are partial. Although this is logical, our type/models autoinitialize some fields by default (which is actually fairly sane). However when this happens, we smash these new blank mappings over the previously updated state. Instead we should just ignore fields that don't come in GUILD_UPDATEs, and save our state. --- disco/state.py | 7 ++++++- disco/types/base.py | 5 ++++- disco/types/channel.py | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/disco/state.py b/disco/state.py index 75531f7..689ab62 100644 --- a/disco/state.py +++ b/disco/state.py @@ -193,7 +193,12 @@ class State(object): event.guild.sync() def on_guild_update(self, event): - self.guilds[event.guild.id].update(event.guild) + self.guilds[event.guild.id].update(event.guild, ignored=[ + 'channels', + 'members', + 'voice_states', + 'presences' + ]) def on_guild_delete(self, event): if event.id in self.guilds: diff --git a/disco/types/base.py b/disco/types/base.py index 1d1341a..c3a061b 100644 --- a/disco/types/base.py +++ b/disco/types/base.py @@ -327,8 +327,11 @@ class Model(six.with_metaclass(ModelMeta, AsyncChainable)): value = field.try_convert(raw, self.client) setattr(inst, field.dst_name, value) - def update(self, other): + def update(self, other, ignored=None): for name in six.iterkeys(self._fields): + if ignored and name in ignored: + continue + if hasattr(other, name) and not getattr(other, name) is UNSET: setattr(self, name, getattr(other, name)) diff --git a/disco/types/channel.py b/disco/types/channel.py index 4c91d3c..311ca5c 100644 --- a/disco/types/channel.py +++ b/disco/types/channel.py @@ -149,8 +149,8 @@ class Channel(SlottedModel, Permissible): if not self.guild_id: return Permissions.ADMINISTRATOR - member = self.guild.members.get(user.id) - base = self.guild.get_permissions(user) + member = self.guild.get_member(user) + base = self.guild.get_permissions(member) for ow in six.itervalues(self.overwrites): if ow.id != user.id and ow.id not in member.roles: