embed.sanitizer: remove unused _sane function

This commit is contained in:
Luna 2018-12-04 21:50:11 -03:00
parent 5db633b797
commit 5de64a93ee
1 changed files with 16 additions and 9 deletions

View File

@ -12,41 +12,46 @@ log = Logger(__name__)
Embed = Dict[str, Any]
def _sane(v):
if isinstance(v, EmbedURL):
return v.to_json
return v
def sanitize_embed(embed: Embed) -> Embed:
"""Sanitize an embed object."""
"""Sanitize an embed object.
This is non-complex sanitization as it doesn't
need the app object.
"""
return {**embed, **{
'type': 'rich'
}}
def path_exists(embed: Embed, components: str):
"""Tell if a given path exists in an embed.
"""Tell if a given path exists in an embed (or any dictionary).
The components string is formatted like this:
key1.key2.key3.key4. <...> .keyN
with each key going deeper and deeper into the embed.
"""
# get the list of components given
if isinstance(components, str):
components = components.split('.')
else:
components = list(components)
# if there are no components, we reached the end of recursion
# and can return true
if not components:
return True
# extract current component
current = components[0]
# if it exists, then we go down a level inside the dict
# (via recursion)
if current in embed:
return path_exists(embed[current], components[1:])
# if it doesn't exist, return False
return False
@ -63,6 +68,8 @@ async def fill_embed(embed: Embed) -> Embed:
log.warning('embed with footer.image_url, ignoring')
if path_exists(embed, 'author.icon_url'):
# TODO: should we check icon_url and convert it into
# a proxied icon url?
log.warning('embed with author.icon_url, ignoring')
return embed