mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Merge branch 'dev'
This commit is contained in:
commit
1b5e2fc0c4
2 changed files with 61 additions and 60 deletions
|
@ -1400,6 +1400,8 @@ class MsG:
|
||||||
'**Use a flag to manage blacklists.**\n'
|
'**Use a flag to manage blacklists.**\n'
|
||||||
f'*Type* `{ctx.prefix}help bl` *for more info.*')
|
f'*Type* `{ctx.prefix}help bl` *for more info.*')
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
await ctx.message.add_reaction('\N{CROSS MARK}')
|
||||||
|
elif not ctx.args:
|
||||||
|
await ctx.send('\N{CROSS MARK} **Missing arguments**')
|
||||||
|
|
||||||
@blacklist.group(
|
@blacklist.group(
|
||||||
name='get',
|
name='get',
|
||||||
|
@ -1420,11 +1422,12 @@ class MsG:
|
||||||
'In accordance with Discord\'s ToS: cub, related tags, and their aliases are blacklisted')
|
'In accordance with Discord\'s ToS: cub, related tags, and their aliases are blacklisted')
|
||||||
async def get_global_blacklist(self, ctx, *args):
|
async def get_global_blacklist(self, ctx, *args):
|
||||||
args, lst = u.kwargs(args)
|
args, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
self.blacklists['global'].get(lst, set()),
|
self.blacklists['global'].get(lst, default),
|
||||||
start=f'\N{NO ENTRY SIGN} **Global {lst}:**\n')
|
start=f'\N{NO ENTRY SIGN} **Global {lst}:**')
|
||||||
|
|
||||||
@get_blacklist.command(
|
@get_blacklist.command(
|
||||||
name='channel',
|
name='channel',
|
||||||
|
@ -1433,11 +1436,12 @@ class MsG:
|
||||||
description='Get channel blacklist')
|
description='Get channel blacklist')
|
||||||
async def get_channel_blacklist(self, ctx, *args):
|
async def get_channel_blacklist(self, ctx, *args):
|
||||||
args, lst = u.kwargs(args)
|
args, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, set()),
|
self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, default),
|
||||||
start=f'\N{NO ENTRY SIGN} {ctx.channel.mention} **{lst}:**\n')
|
start=f'\N{NO ENTRY SIGN} {ctx.channel.mention} **{lst}:**')
|
||||||
|
|
||||||
@get_blacklist.command(
|
@get_blacklist.command(
|
||||||
name='me',
|
name='me',
|
||||||
|
@ -1446,11 +1450,12 @@ class MsG:
|
||||||
description='Get your personal blacklist')
|
description='Get your personal blacklist')
|
||||||
async def get_user_blacklist(self, ctx, *args):
|
async def get_user_blacklist(self, ctx, *args):
|
||||||
args, lst = u.kwargs(args)
|
args, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
self.blacklists['user'].get(ctx.author.id, {}).get(lst, set()),
|
self.blacklists['user'].get(ctx.author.id, {}).get(lst, default),
|
||||||
start=f'\N{NO ENTRY SIGN} {ctx.author.mention}**\'s {lst}:**\n')
|
start=f'\N{NO ENTRY SIGN} {ctx.author.mention}**\'s {lst}:**')
|
||||||
|
|
||||||
@blacklist.group(
|
@blacklist.group(
|
||||||
name='add',
|
name='add',
|
||||||
|
@ -1499,17 +1504,18 @@ class MsG:
|
||||||
@cmds.is_owner()
|
@cmds.is_owner()
|
||||||
async def add_global_tags(self, ctx, *args):
|
async def add_global_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
added = await self._add(
|
added = await self._add(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['global'].setdefault(lst, set() if lst == 'blacklist' else {}),
|
self.blacklists['global'].setdefault(lst, default),
|
||||||
alias=True if lst == 'aliases' else False)
|
alias=True if lst == 'aliases' else False)
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
added,
|
added,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Added to global {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Added to global {lst}:**')
|
||||||
|
|
||||||
@add_tags.command(
|
@add_tags.command(
|
||||||
name='channel',
|
name='channel',
|
||||||
|
@ -1520,17 +1526,18 @@ class MsG:
|
||||||
@cmds.has_permissions(manage_channels=True)
|
@cmds.has_permissions(manage_channels=True)
|
||||||
async def add_channel_tags(self, ctx, *args):
|
async def add_channel_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
added = await self._add(
|
added = await self._add(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['channel'].setdefault(ctx.channel.id, {}).setdefault(lst, set() if lst == 'blacklist' else {}),
|
self.blacklists['channel'].setdefault(ctx.channel.id, {}).setdefault(lst, default),
|
||||||
alias=True if lst == 'aliases' else False)
|
alias=True if lst == 'aliases' else False)
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
added,
|
added,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Added to {ctx.channel.mention} {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Added to {ctx.channel.mention} {lst}:**')
|
||||||
|
|
||||||
@add_tags.command(
|
@add_tags.command(
|
||||||
name='me',
|
name='me',
|
||||||
|
@ -1540,17 +1547,18 @@ class MsG:
|
||||||
usage='[tags...]')
|
usage='[tags...]')
|
||||||
async def add_user_tags(self, ctx, *args):
|
async def add_user_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
default = set() if lst == 'blacklist' else {}
|
||||||
|
|
||||||
async with ctx.channel.typing():
|
async with ctx.channel.typing():
|
||||||
added = await self._add(
|
added = await self._add(
|
||||||
tags,
|
tags,
|
||||||
self.blacklists['user'].setdefault(ctx.author.id, {}).setdefault(lst, set() if lst == 'blacklist' else {}),
|
self.blacklists['user'].setdefault(ctx.author.id, {}).setdefault(lst, default),
|
||||||
alias=True if lst == 'aliases' else False)
|
alias=True if lst == 'aliases' else False)
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
added,
|
added,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Added to {ctx.author.mention}\'s {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Added to {ctx.author.mention}\'s {lst}:**')
|
||||||
|
|
||||||
@blacklist.group(
|
@blacklist.group(
|
||||||
name='remove',
|
name='remove',
|
||||||
|
@ -1563,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',
|
||||||
|
@ -1598,21 +1605,17 @@ class MsG:
|
||||||
@cmds.is_owner()
|
@cmds.is_owner()
|
||||||
async def remove_global_tags(self, ctx, *args):
|
async def remove_global_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
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, set()))
|
self.blacklists['global'].get(lst, default))
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
removed,
|
removed,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from global {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from global {lst}:**')
|
||||||
if skipped:
|
|
||||||
await formatter.paginate(
|
|
||||||
ctx,
|
|
||||||
skipped,
|
|
||||||
start=f'\N{CROSS MARK} **Not in global {lst}:**\n')
|
|
||||||
|
|
||||||
@remove_tags.command(
|
@remove_tags.command(
|
||||||
name='channel',
|
name='channel',
|
||||||
|
@ -1623,21 +1626,17 @@ class MsG:
|
||||||
@cmds.has_permissions(manage_channels=True)
|
@cmds.has_permissions(manage_channels=True)
|
||||||
async def remove_channel_tags(self, ctx, *args):
|
async def remove_channel_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
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, set()))
|
self.blacklists['channel'].get(ctx.channel.id, {}).get(lst, default))
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
removed,
|
removed,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from {ctx.channel.mention} {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from {ctx.channel.mention} {lst}:**')
|
||||||
if skipped:
|
|
||||||
await formatter.paginate(
|
|
||||||
ctx,
|
|
||||||
skipped,
|
|
||||||
start=f'\N{CROSS MARK} **Not in {ctx.channel.mention} {lst}:**\n')
|
|
||||||
|
|
||||||
@remove_tags.command(
|
@remove_tags.command(
|
||||||
name='me',
|
name='me',
|
||||||
|
@ -1647,21 +1646,17 @@ class MsG:
|
||||||
usage='[tags...]')
|
usage='[tags...]')
|
||||||
async def remove_user_tags(self, ctx, *args):
|
async def remove_user_tags(self, ctx, *args):
|
||||||
tags, lst = u.kwargs(args)
|
tags, lst = u.kwargs(args)
|
||||||
|
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, set()))
|
self.blacklists['user'].get(ctx.author.id, {}).get(lst, default))
|
||||||
|
|
||||||
await formatter.paginate(
|
await formatter.paginate(
|
||||||
ctx,
|
ctx,
|
||||||
removed,
|
removed,
|
||||||
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from {ctx.author.mention}\'s {lst}:**\n')
|
start=f'\N{WHITE HEAVY CHECK MARK} **Removed from {ctx.author.mention}\'s {lst}:**')
|
||||||
if skipped:
|
|
||||||
await formatter.paginate(
|
|
||||||
ctx,
|
|
||||||
skipped,
|
|
||||||
start=f'\N{CROSS MARK} **Not in {ctx.author.mention}\'s {lst}:**\n')
|
|
||||||
|
|
||||||
@blacklist.group(
|
@blacklist.group(
|
||||||
name='clear',
|
name='clear',
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import copy
|
||||||
|
|
||||||
from discord.ext.commands import Paginator
|
from discord.ext.commands import Paginator
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,8 +30,8 @@ async def paginate(
|
||||||
i,
|
i,
|
||||||
start='',
|
start='',
|
||||||
prefix='',
|
prefix='',
|
||||||
kprefix='',
|
kprefix='`',
|
||||||
ksuffix='\n',
|
ksuffix='`\n',
|
||||||
eprefix='```\n',
|
eprefix='```\n',
|
||||||
ejoin=' ',
|
ejoin=' ',
|
||||||
esuffix='\n```',
|
esuffix='\n```',
|
||||||
|
@ -37,17 +39,21 @@ async def paginate(
|
||||||
end=''):
|
end=''):
|
||||||
paginator = Paginator(prefix=prefix, suffix=suffix)
|
paginator = Paginator(prefix=prefix, suffix=suffix)
|
||||||
messages = []
|
messages = []
|
||||||
|
i = copy.deepcopy(i)
|
||||||
|
|
||||||
if start:
|
if start:
|
||||||
paginator.add_line(start)
|
paginator.add_line(start)
|
||||||
|
|
||||||
if type(i) in (tuple, list, set):
|
if type(i) in (tuple, list, set):
|
||||||
|
if not i:
|
||||||
|
i = (' ')
|
||||||
paginator.add_line(eprefix + f'{ejoin}'.join(i) + esuffix)
|
paginator.add_line(eprefix + f'{ejoin}'.join(i) + esuffix)
|
||||||
|
|
||||||
elif type(i) is dict:
|
elif type(i) is dict:
|
||||||
|
if not i:
|
||||||
|
i = {'': ' '}
|
||||||
for k, e in sorted(i.items()):
|
for k, e in sorted(i.items()):
|
||||||
if e and (k not in e) and (len(e) >= 1):
|
paginator.add_line(kprefix if k else '' + k + ksuffix if k else '' + eprefix + f'{ejoin}'.join(e) + esuffix)
|
||||||
paginator.add_line(kprefix + k + ksuffix + eprefix + f'{ejoin}'.join(e) + esuffix)
|
|
||||||
|
|
||||||
if end:
|
if end:
|
||||||
paginator.add_line(end)
|
paginator.add_line(end)
|
||||||
|
|
Loading…
Reference in a new issue