mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 14:27:27 +00:00
Added post author and pool name to e6 commands
This commit is contained in:
parent
62e95e5188
commit
841470655c
1 changed files with 43 additions and 43 deletions
|
@ -67,7 +67,7 @@ class MsG:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
posts = {}
|
posts = {}
|
||||||
pool_id = None
|
pool = {}
|
||||||
|
|
||||||
pools = []
|
pools = []
|
||||||
pool_request = await u.fetch('https://{}.net/pool/index.json'.format(booru), params={'query': ' '.join(query)}, json=True)
|
pool_request = await u.fetch('https://{}.net/pool/index.json'.format(booru), params={'query': ' '.join(query)}, json=True)
|
||||||
|
@ -81,24 +81,24 @@ class MsG:
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
finally:
|
finally:
|
||||||
await match.delete()
|
await match.delete()
|
||||||
pool = [pool for pool in pool_request if pool['name']
|
tempool = [pool for pool in pool_request if pool['name']
|
||||||
== pools[int(selection.content) - 1]][0]
|
== pools[int(selection.content) - 1]][0]
|
||||||
await selection.delete()
|
await selection.delete()
|
||||||
pool_id = pool['id']
|
pool = {'name': tempool['name'], 'id': tempool['id']}
|
||||||
elif request:
|
elif request:
|
||||||
pool = pool_request[0]
|
temppool = pool_request[0]
|
||||||
pool_id = pool_request[0]['id']
|
pool = {'name': pool_request[0]['name'], 'id': pool_request[0]['id']}
|
||||||
else:
|
else:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
page = 1
|
page = 1
|
||||||
while len(posts) < pool['post_count']:
|
while len(posts) < tempool['post_count']:
|
||||||
posts_request = await u.fetch('https://{}.net/pool/show.json'.format(booru), params={'id': pool['id'], 'page': page}, json=True)
|
posts_request = await u.fetch('https://{}.net/pool/show.json'.format(booru), params={'id': tempool['id'], 'page': page}, json=True)
|
||||||
for post in posts_request['posts']:
|
for post in posts_request['posts']:
|
||||||
posts[post['id']] = post['file_url']
|
posts[post['id']] = {'author': post['author'], 'url': post['file_url']}
|
||||||
page += 1
|
page += 1
|
||||||
|
|
||||||
return posts, pool_id
|
return pool, posts
|
||||||
|
|
||||||
# Creates reaction-based paginator for linked pools
|
# Creates reaction-based paginator for linked pools
|
||||||
@commands.command(name='pool', aliases=['e6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True)
|
@commands.command(name='pool', aliases=['e6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True)
|
||||||
|
@ -134,14 +134,14 @@ class MsG:
|
||||||
try:
|
try:
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
|
|
||||||
posts, pool_id = await self.return_pool(ctx=ctx, booru='e621', query=kwords)
|
pool, posts = await self.return_pool(ctx=ctx, booru='e621', query=kwords)
|
||||||
keys = list(posts.keys())
|
keys = list(posts.keys())
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title='/post/{}'.format(keys[c - 1]), url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1])
|
title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1]['url'])
|
||||||
embed.set_author(name='/pool/{}'.format(pool_id),
|
embed.set_author(name=pool['name'],
|
||||||
url='https://e621.net/pool/show?id={}'.format(pool_id), icon_url=user.avatar_url)
|
url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=user.avatar_url)
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
|
|
||||||
|
@ -161,11 +161,11 @@ class MsG:
|
||||||
except exc.Left:
|
except exc.Left:
|
||||||
if c > 1:
|
if c > 1:
|
||||||
c -= 1
|
c -= 1
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
else:
|
else:
|
||||||
|
@ -177,28 +177,28 @@ class MsG:
|
||||||
|
|
||||||
c = int(number.content)
|
c = int(number.content)
|
||||||
await number.delete()
|
await number.delete()
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
|
|
||||||
except exc.Save:
|
except exc.Save:
|
||||||
if values[c - 1] not in starred:
|
if values[c - 1]['url'] not in starred:
|
||||||
starred.append(values[c - 1])
|
starred.append(values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content='**Image** `{}` **saved.**'.format(len(starred)))
|
await paginator.edit(content='**Image** `{}` **saved.**'.format(len(starred)))
|
||||||
|
|
||||||
except exc.Right:
|
except exc.Right:
|
||||||
if c < len(keys):
|
if c < len(keys):
|
||||||
c += 1
|
c += 1
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ class MsG:
|
||||||
await asyncio.sleep(2.1)
|
await asyncio.sleep(2.1)
|
||||||
|
|
||||||
# Messy code that checks image limit and tags in blacklists
|
# Messy code that checks image limit and tags in blacklists
|
||||||
async def check_return_posts(self, *, ctx, booru='e621', tags=[], limit=1, previous=[]):
|
async def check_return_posts(self, *, ctx, booru='e621', tags=[], limit=1, previous={}):
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
|
@ -265,8 +265,8 @@ class MsG:
|
||||||
raise exc.Continue
|
raise exc.Continue
|
||||||
except exc.Continue:
|
except exc.Continue:
|
||||||
continue
|
continue
|
||||||
if post['file_url'] not in posts.values() and post['file_url'] not in previous:
|
if post['id'] not in posts.keys() and post['id'] not in previous.keys():
|
||||||
posts[post['id']] = post['file_url']
|
posts[post['id']] = {'author': post['author'], 'url': post['file_url']}
|
||||||
if len(posts) == limit:
|
if len(posts) == limit:
|
||||||
break
|
break
|
||||||
c += 1
|
c += 1
|
||||||
|
@ -313,7 +313,7 @@ class MsG:
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title='/post/{}'.format(keys[c - 1]), url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1])
|
title=values[c - 1]['author'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color).set_image(url=values[c - 1]['url'])
|
||||||
embed.set_author(name=formatter.tostring(args, random=True),
|
embed.set_author(name=formatter.tostring(args, random=True),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=user.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=user.avatar_url)
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
|
@ -335,11 +335,11 @@ class MsG:
|
||||||
except exc.Left:
|
except exc.Left:
|
||||||
if c > 1:
|
if c > 1:
|
||||||
c -= 1
|
c -= 1
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
else:
|
else:
|
||||||
await paginator.edit(content='❌ **First image.**')
|
await paginator.edit(content='❌ **First image.**')
|
||||||
|
@ -350,17 +350,17 @@ class MsG:
|
||||||
|
|
||||||
c = int(number.content)
|
c = int(number.content)
|
||||||
await number.delete()
|
await number.delete()
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
|
|
||||||
except exc.Save:
|
except exc.Save:
|
||||||
if values[c - 1] not in starred:
|
if values[c - 1]['url'] not in starred:
|
||||||
starred.append(values[c - 1])
|
starred.append(values[c - 1]['url'])
|
||||||
|
|
||||||
await paginator.edit(content='**Image** `{}` **saved.**'.format(len(starred)))
|
await paginator.edit(content='**Image** `{}` **saved.**'.format(len(starred)))
|
||||||
|
|
||||||
|
@ -375,11 +375,11 @@ class MsG:
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
c += 1
|
c += 1
|
||||||
embed.title = '/post/{}'.format(keys[c - 1])
|
embed.title = values[c - 1]['author']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
embed.set_image(url=values[c - 1])
|
embed.set_image(url=values[c - 1]['url'])
|
||||||
await paginator.edit(content=None, embed=embed)
|
await paginator.edit(content=None, embed=embed)
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
|
@ -427,15 +427,15 @@ class MsG:
|
||||||
raise exc.BoundsError(arg)
|
raise exc.BoundsError(arg)
|
||||||
# , previous=temp_urls.get(ctx.message.author.id, []))
|
# , previous=temp_urls.get(ctx.message.author.id, []))
|
||||||
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
||||||
for ident, url in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title='/post/{}'.format(ident), url='https://e621.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['author'], url='https://e621.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color).set_image(url=url)
|
color=ctx.me.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(args, random=True),
|
embed.set_author(name=formatter.tostring(args, random=True),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text='e621', icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.values())
|
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.keys())
|
||||||
except exc.TagBlacklisted as e:
|
except exc.TagBlacklisted as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **blacklisted.**', delete_after=10)
|
await ctx.send('❌ `' + str(e) + '` **blacklisted.**', delete_after=10)
|
||||||
except exc.BoundsError as e:
|
except exc.BoundsError as e:
|
||||||
|
@ -475,13 +475,13 @@ class MsG:
|
||||||
raise exc.BoundsError(arg)
|
raise exc.BoundsError(arg)
|
||||||
# , previous=temp_urls.get(ctx.message.author.id, []))
|
# , previous=temp_urls.get(ctx.message.author.id, []))
|
||||||
posts = await self.check_return_posts(ctx=ctx, booru='e926', tags=args, limit=limit)
|
posts = await self.check_return_posts(ctx=ctx, booru='e926', tags=args, limit=limit)
|
||||||
for ident, url in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title='/post/{}'.format(ident), url='https://e926.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['author'], url='https://e926.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color).set_image(url=url)
|
color=ctx.me.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(args, random=True),
|
embed.set_author(name=formatter.tostring(args, random=True),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text='e926', icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.values())
|
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.values())
|
||||||
except exc.TagBlacklisted as e:
|
except exc.TagBlacklisted as e:
|
||||||
|
|
Loading…
Reference in a new issue