storage: handle webhook authors in messages

This commit is contained in:
Luna 2019-02-05 18:00:35 -03:00
parent 943a683d86
commit b079dd428a
2 changed files with 18 additions and 8 deletions

View File

@ -48,7 +48,7 @@ class ChannelDispatcher(DispatcherWithState):
# if we are dispatching to a guild channel, # if we are dispatching to a guild channel,
# we should only dispatch to the states / shards # we should only dispatch to the states / shards
# that are connected to the guild (via their shard id). # that are connected to the guild (via their shard id).
# if we aren't, we just get all states tied to the user. # if we aren't, we just get all states tied to the user.
# TODO: make a fetch_states that fetches shards # TODO: make a fetch_states that fetches shards
# - with id 0 (count any) OR # - with id 0 (count any) OR

View File

@ -677,16 +677,29 @@ class Storage:
# i think proxy_url=url is valid. # i think proxy_url=url is valid.
drow['proxy_url'] = drow['url'] drow['proxy_url'] = drow['url']
# TODO: url, proxy_url
res.append(drow) res.append(drow)
return res return res
async def _inject_author(self, res):
"""Inject a pseudo-user object when the message is made by a webhook."""
author_id, webhook_id = res['author_id'], res['webhook_id']
if author_id is not None:
res['author'] = await self.get_user(res['author_id'])
elif webhook_id is not None:
res['author'] = {
'id': webhook_id,
'username': 'a',
'avatar': None
}
res.pop('author_id')
async def get_message(self, message_id: int, user_id=None) -> Dict: async def get_message(self, message_id: int, user_id=None) -> Dict:
"""Get a single message's payload.""" """Get a single message's payload."""
row = await self.fetchrow_with_json(""" row = await self.fetchrow_with_json("""
SELECT id::text, channel_id::text, author_id, content, SELECT id::text, channel_id::text, author_id, webhook_id, content,
created_at AS timestamp, edited_at AS edited_timestamp, created_at AS timestamp, edited_at AS edited_timestamp,
tts, mention_everyone, nonce, message_type, embeds tts, mention_everyone, nonce, message_type, embeds
FROM messages FROM messages
@ -745,11 +758,8 @@ class Storage:
res['reactions'] = await self.get_reactions(message_id, user_id) res['reactions'] = await self.get_reactions(message_id, user_id)
# TODO: handle webhook authors await self._inject_author(res)
res['author'] = await self.get_user(res['author_id'])
res.pop('author_id')
# TODO: res['attachments']
res['attachments'] = await self.get_attachments(message_id) res['attachments'] = await self.get_attachments(message_id)
# TODO: res['member'] for partial member data # TODO: res['member'] for partial member data