mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 14:27:27 +00:00
Migrate to Paginator use with long responses, possibly breaking
This commit is contained in:
parent
4622123809
commit
4a2a013323
3 changed files with 51 additions and 33 deletions
|
@ -674,7 +674,7 @@ class MsG:
|
||||||
# Checks if tags are in local blacklists
|
# Checks if tags are in local blacklists
|
||||||
if tags:
|
if tags:
|
||||||
if (len(tags) > 5 and booru == 'e621') or (len(tags) > 4 and booru == 'e926'):
|
if (len(tags) > 5 and booru == 'e621') or (len(tags) > 4 and booru == 'e926'):
|
||||||
raise exc.TagBoundsError(formatter.tostring(tags[5:]))
|
raise exc.TagBoundsError(' '.join(tags[5:]))
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if tag == 'swf' or tag == 'webm' or tag in blacklist:
|
if tag == 'swf' or tag == 'webm' or tag in blacklist:
|
||||||
raise exc.TagBlacklisted(tag)
|
raise exc.TagBlacklisted(tag)
|
||||||
|
@ -689,7 +689,7 @@ class MsG:
|
||||||
raise exc.Timeout
|
raise exc.Timeout
|
||||||
request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join([order] + tags), 'limit': int(self.LIMIT * limit)}, json=True)
|
request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join([order] + tags), 'limit': int(self.LIMIT * limit)}, json=True)
|
||||||
if len(request) == 0:
|
if len(request) == 0:
|
||||||
raise exc.NotFound(formatter.tostring(tags))
|
raise exc.NotFound(' '.join(tags))
|
||||||
if len(request) < limit:
|
if len(request) < limit:
|
||||||
limit = len(request)
|
limit = len(request)
|
||||||
|
|
||||||
|
@ -720,7 +720,7 @@ class MsG:
|
||||||
if posts:
|
if posts:
|
||||||
return posts, order
|
return posts, order
|
||||||
else:
|
else:
|
||||||
raise exc.NotFound(formatter.tostring(tags))
|
raise exc.NotFound(' '.join(tags))
|
||||||
|
|
||||||
# Creates reaction-based paginator for linked pools
|
# Creates reaction-based paginator for linked pools
|
||||||
@cmds.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format')
|
@cmds.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format')
|
||||||
|
@ -896,7 +896,7 @@ class MsG:
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['file_url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, order=order),
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text=values[c - 1]['score'],
|
embed.set_footer(text=values[c - 1]['score'],
|
||||||
icon_url=self._get_score(values[c - 1]['score']))
|
icon_url=self._get_score(values[c - 1]['score']))
|
||||||
|
@ -1060,7 +1060,7 @@ class MsG:
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['artist'], url='https://e926.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
title=values[c - 1]['artist'], url='https://e926.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['file_url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, order=order),
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://e926.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e926.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text=values[c - 1]['score'],
|
embed.set_footer(text=values[c - 1]['score'],
|
||||||
icon_url=self._get_score(values[c - 1]['score']))
|
icon_url=self._get_score(values[c - 1]['score']))
|
||||||
|
@ -1103,7 +1103,7 @@ class MsG:
|
||||||
|
|
||||||
except exc.GoTo:
|
except exc.GoTo:
|
||||||
await paginator.edit(content=f'`{c} / {len(posts)}`')
|
await paginator.edit(content=f'`{c} / {len(posts)}`')
|
||||||
number = await self.bot.wait_for('message', check=on_message, timeout=7 * 60)
|
number = await self.bot.wait_for('message', check=on_message, timeout=8 * 60)
|
||||||
|
|
||||||
if int(number.content) != 0:
|
if int(number.content) != 0:
|
||||||
c = int(number.content)
|
c = int(number.content)
|
||||||
|
@ -1198,7 +1198,7 @@ class MsG:
|
||||||
embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=post['file_url'])
|
embed.set_image(url=post['file_url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, order=order),
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=post['score'], icon_url=self._get_score(post['score']))
|
text=post['score'], icon_url=self._get_score(post['score']))
|
||||||
|
@ -1249,7 +1249,7 @@ class MsG:
|
||||||
embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=post['file_url'])
|
embed.set_image(url=post['file_url'])
|
||||||
embed.set_author(name=formatter.tostring(tags, order=order),
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=post['score'], icon_url=self._get_score(post['score']))
|
text=post['score'], icon_url=self._get_score(post['score']))
|
||||||
|
@ -1411,14 +1411,9 @@ class MsG:
|
||||||
for tag in bl:
|
for tag in bl:
|
||||||
aliases[tag] = list(self.aliases[tag])
|
aliases[tag] = list(self.aliases[tag])
|
||||||
|
|
||||||
paginator = cmds.Paginator(prefix='', suffix='')
|
# paginator.add_line(f'{tag}\n```{" ".join(alias_list)}```')
|
||||||
|
|
||||||
for tag, alias_list in aliases.items():
|
await formatter.paginate(ctx, aliases, start='\N{NO ENTRY SIGN} **Contextual blacklist aliases:**\n')
|
||||||
paginator.add_line(f'{tag}\n```{" ".join(alias_list)}```')
|
|
||||||
|
|
||||||
for page in paginator.pages:
|
|
||||||
print(page)
|
|
||||||
await ctx.send(f'\N{NO ENTRY SIGN} **Contextual blacklist aliases:**\n{page}')
|
|
||||||
|
|
||||||
@_get_blacklist.command(name='global', aliases=['gl', 'g'], brief='Get current global blacklist', description='Get current global blacklist\n\nThis applies to all booru commands, in accordance with Discord\'s ToS agreement\n\nExample:\n\{p\}bl get global')
|
@_get_blacklist.command(name='global', aliases=['gl', 'g'], brief='Get current global blacklist', description='Get current global blacklist\n\nThis applies to all booru commands, in accordance with Discord\'s ToS agreement\n\nExample:\n\{p\}bl get global')
|
||||||
async def __get_global_blacklist(self, ctx, *args):
|
async def __get_global_blacklist(self, ctx, *args):
|
||||||
|
@ -1505,7 +1500,9 @@ class MsG:
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
aliases[tag].add(dic['name'])
|
aliases[tag].add(dic['name'])
|
||||||
|
|
||||||
message = await ctx.send(f'**Also add aliases?**\n{formatter.dict_tostring(aliases, f=False)}')
|
messages = await formatter.paginate(ctx, aliases)
|
||||||
|
message = await ctx.send(
|
||||||
|
'**Also add aliases?** React with the minus sign (\N{HEAVY MINUS SIGN}) to remove unwanted aliases')
|
||||||
await message.add_reaction('\N{THUMBS DOWN SIGN}')
|
await message.add_reaction('\N{THUMBS DOWN SIGN}')
|
||||||
await message.add_reaction('\N{HEAVY MINUS SIGN}')
|
await message.add_reaction('\N{HEAVY MINUS SIGN}')
|
||||||
await message.add_reaction('\N{THUMBS UP SIGN}')
|
await message.add_reaction('\N{THUMBS UP SIGN}')
|
||||||
|
|
|
@ -95,7 +95,7 @@ class Bot:
|
||||||
if v:
|
if v:
|
||||||
permissions[member.mention].append(k)
|
permissions[member.mention].append(k)
|
||||||
|
|
||||||
await ctx.send(f'**Permissions:**\n\n{formatter.dict_tostring(permissions, f=False, newline=True)}')
|
await formatter.paginate(ctx, permissions)
|
||||||
|
|
||||||
@cmds.command(name=',tasks', aliases=[',task'])
|
@cmds.command(name=',tasks', aliases=[',task'])
|
||||||
@cmds.is_owner()
|
@cmds.is_owner()
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
from discord.ext.commands import Paginator
|
||||||
|
|
||||||
|
|
||||||
def tostring(i, *, order=None, newline=False):
|
def tostring(i, *, order=None, newline=False):
|
||||||
o = ''
|
o = ''
|
||||||
if i:
|
if i:
|
||||||
for v in i:
|
for v in i:
|
||||||
o += v + (' ' if newline is False else '\n')
|
o += v + (' ' if newline is False else ' \n')
|
||||||
o = o[:-1]
|
o = o[:-1]
|
||||||
elif order:
|
elif order:
|
||||||
o += order
|
o += order
|
||||||
|
@ -20,22 +23,40 @@ def tostring_commas(i):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def dict_tostring(i, f=True, newline=False):
|
async def paginate(
|
||||||
o = ''
|
ctx,
|
||||||
|
i,
|
||||||
|
start='',
|
||||||
|
prefix='',
|
||||||
|
kprefix='',
|
||||||
|
ksuffix='\n',
|
||||||
|
eprefix='```\n',
|
||||||
|
ejoin=' ',
|
||||||
|
esuffix='\n```',
|
||||||
|
suffix='',
|
||||||
|
end=''):
|
||||||
|
paginator = Paginator(prefix=prefix, suffix=suffix)
|
||||||
|
messages = []
|
||||||
|
|
||||||
if f:
|
if start:
|
||||||
if i:
|
paginator.add_line(start)
|
||||||
for k, v in i.items():
|
|
||||||
o += '**' + k + ':** `' + tostring(v) + '`\n'
|
if type(i) in (tuple, list, set):
|
||||||
elif newline is True:
|
for e in sorted(i):
|
||||||
if i:
|
if e and (e not in i) and (len(i) > 1):
|
||||||
for k, v in i.items():
|
paginator.add_line(eprefix + f'{ejoin}'.join(e) + esuffix)
|
||||||
o += k + ': ```' + tostring(v, newline=newline) + '```\n'
|
elif type(i) is dict:
|
||||||
else:
|
for k, e in sorted(i.items()):
|
||||||
if i:
|
if e and (k not in e) and (len(e) > 1):
|
||||||
for k, v in i.items():
|
paginator.add_line(kprefix + k + ksuffix + eprefix + f'{ejoin}'.join(e) + esuffix)
|
||||||
o += k + ': ```' + tostring(v) + '```\n'
|
|
||||||
return o
|
if end:
|
||||||
|
paginator.add_line(end)
|
||||||
|
|
||||||
|
for page in paginator.pages:
|
||||||
|
messages.append(await ctx.send(page))
|
||||||
|
|
||||||
|
return messages
|
||||||
|
|
||||||
|
|
||||||
def dictelem_tostring(i):
|
def dictelem_tostring(i):
|
||||||
|
|
Loading…
Reference in a new issue