pubsub.lazy_guild: fix fetching user id from item

- pubsub.lazy_guild: fix get_state on unknown session id
This commit is contained in:
Luna Mendes 2018-11-07 19:08:31 -03:00
parent bd9c4cb26c
commit 773ab8fd18
1 changed files with 15 additions and 11 deletions

View File

@ -364,14 +364,13 @@ class GuildMemberList:
self._set_empty_list()
def get_state(self, session_id: str):
try:
state = self.state_man.fetch_raw(session_id)
if not state:
return state
except KeyError:
self.unsub(session_id)
return
return state
async def _dispatch_sess(self, session_ids: List[str],
operations: List[Operation]):
@ -394,10 +393,16 @@ class GuildMemberList:
}
states = map(self.get_state, session_ids)
dispatched = []
for state in (s for s in states if s is not None):
await state.ws.dispatch(
'GUILD_MEMBER_LIST_UPDATE', payload)
dispatched.append(state.session_id)
return dispatched
async def shard_query(self, session_id: str, ranges: list):
"""Send a GUILD_MEMBER_LIST_UPDATE event
for a shard that is querying about the member list.
@ -468,13 +473,14 @@ class GuildMemberList:
presences[p_idx].update(partial_presence)
def _get_id(p):
return p.get('member', {}).get('user', {}).get('id')
item_index = index_by_func(
lambda p: p.get('user', {}).get('id') == str(user_id),
lambda p: _get_id(p) == str(user_id),
self.items
)
pprint.pprint(self.items)
if not item_index:
log.warning('lazy guild got invalid pres update uid={}',
user_id)
@ -493,7 +499,7 @@ class GuildMemberList:
session_ids = filter(_is_in, self.state.keys())
await self._dispatch_sess(
return await self._dispatch_sess(
session_ids,
[
Operation('UPDATE', {
@ -503,8 +509,6 @@ class GuildMemberList:
]
)
return list(session_ids)
async def dispatch(self, event: str, data: Any):
"""Modify the member list and dispatch the respective
events to subscribed shards.