mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 14:27:27 +00:00
Fix _remove logic and remove output of skipped tags
This commit is contained in:
parent
c0f72cd503
commit
eab73cb62b
1 changed files with 22 additions and 23 deletions
|
@ -1571,31 +1571,30 @@ class MsG:
|
||||||
await ctx.send('**Invalid blacklist**')
|
await ctx.send('**Invalid blacklist**')
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
|
||||||
def _remove(self, tags, lst):
|
def _remove(self, remove, lst):
|
||||||
removed = []
|
removed = set()
|
||||||
skipped = []
|
|
||||||
|
|
||||||
if tags:
|
if remove:
|
||||||
if type(lst) is set:
|
if type(lst) is set:
|
||||||
temp = set()
|
for tag in remove:
|
||||||
for tag in tags:
|
with suppress(KeyError):
|
||||||
if tag not in tags:
|
lst.remove(tag)
|
||||||
temp.add(tag)
|
removed.add(tag)
|
||||||
else:
|
|
||||||
removed.append(tag)
|
|
||||||
else:
|
else:
|
||||||
temp = {}
|
temp = copy.deepcopy(lst)
|
||||||
for k, v in lst.items():
|
for k in temp.keys():
|
||||||
temp[k] = set()
|
if k in remove:
|
||||||
for tag in v:
|
with suppress(KeyError):
|
||||||
if tag not in tags:
|
del lst[k]
|
||||||
temp[k].add(tag)
|
removed.add(k)
|
||||||
else:
|
else:
|
||||||
removed.append(tag)
|
lst[k] = set([tag for tag in lst[k] if tag not in remove])
|
||||||
lst.update(temp)
|
lst = temp
|
||||||
|
removed.update([tag for k, v in lst.items() for tag in v if tag in remove])
|
||||||
|
|
||||||
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
return removed, skipped
|
return removed
|
||||||
|
|
||||||
@remove_tags.command(
|
@remove_tags.command(
|
||||||
name='global',
|
name='global',
|
||||||
|
@ -1609,7 +1608,7 @@ class MsG:
|
||||||
default = set() if lst == 'blacklist' else {}
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
removed, skipped = self._remove(
|
removed = self._remove(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['global'].get(lst, default))
|
self.blacklists['global'].get(lst, default))
|
||||||
|
|
||||||
|
@ -1630,7 +1629,7 @@ class MsG:
|
||||||
default = set() if lst == 'blacklist' else {}
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
removed, skipped = self._remove(
|
removed = self._remove(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, default))
|
self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, default))
|
||||||
|
|
||||||
|
@ -1650,7 +1649,7 @@ class MsG:
|
||||||
default = set() if lst == 'blacklist' else {}
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
removed, skipped = self._remove(
|
removed = self._remove(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['user'].get(ctx.author.id, {}).get(lst, default))
|
self.blacklists['user'].get(ctx.author.id, {}).get(lst, default))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue