mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Fix and refactor _get_posts blacklisting logic
This commit is contained in:
parent
024949390e
commit
b751ebc861
1 changed files with 15 additions and 4 deletions
|
@ -657,9 +657,19 @@ class MsG:
|
||||||
async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
||||||
blacklist = set()
|
blacklist = set()
|
||||||
# Creates temp blacklist based on context
|
# 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 lst in ('blacklist', 'aliases'):
|
||||||
for tag in bl:
|
default = set() if lst == 'blacklist' else {}
|
||||||
blacklist.update([tag] + list(self.aliases[tag]))
|
|
||||||
|
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
|
# Checks for, assigns, and removes first order in tags if possible
|
||||||
order = [tag for tag in tags if 'order:' in tag]
|
order = [tag for tag in tags if 'order:' in tag]
|
||||||
if order:
|
if order:
|
||||||
|
@ -693,8 +703,9 @@ class MsG:
|
||||||
if 'swf' in post['file_ext'] or 'webm' in post['file_ext']:
|
if 'swf' in post['file_ext'] or 'webm' in post['file_ext']:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
post_tags = post['tags'].split(' ')
|
||||||
for tag in blacklist:
|
for tag in blacklist:
|
||||||
if tag in post['tags']:
|
if tag in post_tags:
|
||||||
raise exc.Continue
|
raise exc.Continue
|
||||||
except exc.Continue:
|
except exc.Continue:
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue