From b751ebc861efb569c473c4924beb11f3207307b6 Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Thu, 15 Nov 2018 15:43:53 -0500 Subject: [PATCH] Fix and refactor _get_posts blacklisting logic --- src/cogs/booru.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 104fc98..6a378e2 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -657,9 +657,19 @@ class MsG: async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}): blacklist = set() # Creates temp blacklist based on context - for bl in (self.blacklists['global_blacklist'], self.blacklists['guild_blacklist'].get(guild.id, {}).get(ctx.channel.id, set()), self.blacklists['user_blacklist'].get(ctx.author.id, set())): - for tag in bl: - blacklist.update([tag] + list(self.aliases[tag])) + for lst in ('blacklist', 'aliases'): + default = set() if lst == 'blacklist' else {} + + for bl in (self.blacklists['global'].get(lst, default), + self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, default), + self.blacklists['user'].get(ctx.author.id, {}).get(lst, default)): + if lst == 'aliases': + temp = list(bl.keys()) + [tag for tags in bl.values() for tag in tags] + temp = set(temp) + else: + temp = bl + + blacklist.update(temp) # Checks for, assigns, and removes first order in tags if possible order = [tag for tag in tags if 'order:' in tag] if order: @@ -693,8 +703,9 @@ class MsG: if 'swf' in post['file_ext'] or 'webm' in post['file_ext']: continue try: + post_tags = post['tags'].split(' ') for tag in blacklist: - if tag in post['tags']: + if tag in post_tags: raise exc.Continue except exc.Continue: continue