pubsub.guild: skip presence events based on flags.presence

This commit is contained in:
Luna 2019-07-20 12:55:14 -03:00
parent dda99c9a6a
commit 4d7e6ec93c
1 changed files with 10 additions and 0 deletions

View File

@ -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)