From 5de64a93ee113c23b3e9291a1d5d960c2bb0f9b8 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 4 Dec 2018 21:50:11 -0300 Subject: [PATCH] embed.sanitizer: remove unused _sane function --- litecord/embed/sanitizer.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/litecord/embed/sanitizer.py b/litecord/embed/sanitizer.py index eb9921f..be3e1be 100644 --- a/litecord/embed/sanitizer.py +++ b/litecord/embed/sanitizer.py @@ -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