handle nullable embeds when creating messages

somehow discordcr does that..
This commit is contained in:
Luna 2019-04-04 12:52:41 -03:00
parent 4509ede535
commit a93090ddbc
3 changed files with 9 additions and 4 deletions

View File

@ -191,7 +191,7 @@ async def create_message(channel_id: int, actual_guild_id: int,
data['nonce'], data['nonce'],
MessageType.DEFAULT.value, MessageType.DEFAULT.value,
data.get('embeds', []) data.get('embeds', []) or []
) )
return message_id return message_id
@ -286,7 +286,7 @@ def msg_create_check_content(payload: dict, files: list, *, use_embeds=False):
has_files = len(files) > 0 has_files = len(files) > 0
embed_field = 'embeds' if use_embeds else 'embed' embed_field = 'embeds' if use_embeds else 'embed'
has_embed = embed_field in payload has_embed = embed_field in payload and payload.get(embed_field) is not None
has_total_content = has_content or has_embed or has_files has_total_content = has_content or has_embed or has_files
@ -405,7 +405,8 @@ async def _create_message(channel_id):
# fill_embed takes care of filling proxy and width/height # fill_embed takes care of filling proxy and width/height
'embeds': ([await fill_embed(j['embed'])] 'embeds': ([await fill_embed(j['embed'])]
if 'embed' in j else []), if j.get('embed') is not None
else []),
}) })
# for each file given, we add it as an attachment # for each file given, we add it as an attachment

View File

@ -185,6 +185,9 @@ async def fetch_embed(url, *, config=None, session=None) -> dict:
async def fill_embed(embed: Embed) -> Embed: async def fill_embed(embed: Embed) -> Embed:
"""Fill an embed with more information, such as proxy URLs.""" """Fill an embed with more information, such as proxy URLs."""
if embed is None:
return
embed = sanitize_embed(embed) embed = sanitize_embed(embed)
if path_exists(embed, 'footer.icon_url'): if path_exists(embed, 'footer.icon_url'):

View File

@ -434,7 +434,8 @@ MESSAGE_CREATE = {
'embed': { 'embed': {
'type': 'dict', 'type': 'dict',
'schema': EMBED_OBJECT, 'schema': EMBED_OBJECT,
'required': False 'required': False,
'nullable': True
} }
} }