From 4d7e6ec93c4e2aaf792a5dd4ed8b3216e514b720 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 20 Jul 2019 12:55:14 -0300 Subject: [PATCH] pubsub.guild: skip presence events based on flags.presence --- litecord/pubsub/guild.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/litecord/pubsub/guild.py b/litecord/pubsub/guild.py index 069b664..c03a5db 100644 --- a/litecord/pubsub/guild.py +++ b/litecord/pubsub/guild.py @@ -114,6 +114,15 @@ class GuildDispatcher(DispatcherWithState): await self.unsub(guild_id, user_id) continue + # skip the given subscriber if event starts with PRESENCE_ + # and the flags say they don't want it. + + # note that this does not equate to any unsubscription + # of the channel. + flags = self.flags[guild_id][user_id] + if event.startswith('PRESENCE_') and not flags.get('presence'): + continue + # filter the ones that matter states = list(filter( lambda state: func(state.session_id), states @@ -121,6 +130,7 @@ class GuildDispatcher(DispatcherWithState): cur_sess = await self._dispatch_states( states, event, data) + sessions.extend(cur_sess) dispatched += len(cur_sess)