mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 14:27:27 +00:00
Changed "0 or cancel" to 🛑 reaction for pool selection, tweaked format
This commit is contained in:
parent
5d053f2ca8
commit
a3dd706674
1 changed files with 52 additions and 36 deletions
|
@ -134,8 +134,14 @@ class MsG:
|
||||||
if len(pool_request) > 1:
|
if len(pool_request) > 1:
|
||||||
for pool in pool_request:
|
for pool in pool_request:
|
||||||
pools.append(pool['name'])
|
pools.append(pool['name'])
|
||||||
match = await ctx.send('**Multiple pools found for `{}`.** Type the number of the correct match.\n```\n{}```\n`0` or `cancel`'.format(' '.join(query), '\n'.join(['{} {}'.format(c, elem) for c, elem in enumerate(pools, 1)])))
|
match = await ctx.send('**Multiple pools found for `{}`.** Type the number of the correct match\n```\n{}```'.format(' '.join(query), '\n'.join(['{} {}'.format(c, elem) for c, elem in enumerate(pools, 1)])))
|
||||||
selection = await self.bot.wait_for('message', check=on_message, timeout=60)
|
|
||||||
|
await ctx.message.add_reaction('🛑')
|
||||||
|
done, pending = await asyncio.wait([self.bot.wait_for('reaction_add', check=on_reaction, timeout=60),
|
||||||
|
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=60), self.bot.wait_for('message', check=on_message, timeout=60)], return_when=asyncio.FIRST_COMPLETED)
|
||||||
|
for future in done:
|
||||||
|
selection = future.result()
|
||||||
|
|
||||||
await match.delete()
|
await match.delete()
|
||||||
tempool = [pool for pool in pool_request if pool['name'] == pools[int(selection.content) - 1]][0]
|
tempool = [pool for pool in pool_request if pool['name'] == pools[int(selection.content) - 1]][0]
|
||||||
await selection.delete()
|
await selection.delete()
|
||||||
|
@ -147,9 +153,8 @@ class MsG:
|
||||||
await ctx.send(f'**{tempool["name"]}**\nhttps://e621.net/pool/show/{tempool["id"]}')
|
await ctx.send(f'**{tempool["name"]}**\nhttps://e621.net/pool/show/{tempool["id"]}')
|
||||||
await ctx.message.add_reaction('✅')
|
await ctx.message.add_reaction('✅')
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort as e:
|
||||||
await ctx.send('**Search aborted**', delete_after=10)
|
await e.message.edit(content='**Search aborted**', delete_after=10)
|
||||||
await ctx.message.add_reaction('\N{CROSS MARK}')
|
|
||||||
|
|
||||||
@commands.command(name='getimage', aliases=['geti', 'gi'])
|
@commands.command(name='getimage', aliases=['geti', 'gi'])
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
|
@ -479,45 +484,56 @@ class MsG:
|
||||||
return args
|
return args
|
||||||
|
|
||||||
async def _get_pool(self, ctx, *, destination, booru='e621', query=[]):
|
async def _get_pool(self, ctx, *, destination, booru='e621', query=[]):
|
||||||
def on_message(msg):
|
def on_reaction(reaction, user):
|
||||||
if (msg.content.isdigit() and int(msg.content) == 0) or msg.content.lower() == 'cancel' and msg.author is ctx.author and msg.channel is ctx.channel:
|
if reaction.emoji == '🛑' and reaction.message.id == ctx.message.id and user is ctx.author:
|
||||||
raise exc.Abort
|
raise exc.Abort(match)
|
||||||
elif msg.content.isdigit():
|
|
||||||
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is ctx.author and msg.channel is ctx.channel:
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def on_message(msg):
|
||||||
|
return msg.content.isdigit() and int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is ctx.author and msg.channel is ctx.channel
|
||||||
|
|
||||||
posts = {}
|
posts = {}
|
||||||
pool = {}
|
pool = {}
|
||||||
|
|
||||||
pools = []
|
try:
|
||||||
pool_request = await u.fetch('https://{}.net/pool/index.json'.format(booru), params={'query': ' '.join(query)}, json=True)
|
pools = []
|
||||||
if len(pool_request) > 1:
|
pool_request = await u.fetch('https://{}.net/pool/index.json'.format(booru), params={'query': ' '.join(query)}, json=True)
|
||||||
for pool in pool_request:
|
if len(pool_request) > 1:
|
||||||
pools.append(pool['name'])
|
for pool in pool_request:
|
||||||
match = await ctx.send('**Multiple pools found for `{}`.** Type the number of the correct match.\n```\n{}```\n`0` or `cancel`'.format(' '.join(query), '\n'.join(['{} {}'.format(c, elem) for c, elem in enumerate(pools, 1)])))
|
pools.append(pool['name'])
|
||||||
selection = await self.bot.wait_for('message', check=on_message, timeout=60)
|
match = await ctx.send('**Multiple pools found for `{}`.** Type the number of the correct match.\n```\n{}```'.format(' '.join(query), '\n'.join(['{} {}'.format(c, elem) for c, elem in enumerate(pools, 1)])))
|
||||||
await match.delete()
|
|
||||||
tempool = [pool for pool in pool_request if pool['name']
|
|
||||||
== pools[int(selection.content) - 1]][0]
|
|
||||||
await selection.delete()
|
|
||||||
pool = {'name': tempool['name'], 'id': tempool['id']}
|
|
||||||
|
|
||||||
await destination.trigger_typing()
|
await ctx.message.add_reaction('🛑')
|
||||||
elif pool_request:
|
done, pending = await asyncio.wait([self.bot.wait_for('reaction_add', check=on_reaction, timeout=60),
|
||||||
tempool = pool_request[0]
|
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=60), self.bot.wait_for('message', check=on_message, timeout=60)], return_when=asyncio.FIRST_COMPLETED)
|
||||||
pool = {'name': pool_request[0]['name'], 'id': pool_request[0]['id']}
|
for future in done:
|
||||||
else:
|
selection = future.result()
|
||||||
raise exc.NotFound
|
|
||||||
|
|
||||||
page = 1
|
await match.delete()
|
||||||
while len(posts) < tempool['post_count']:
|
tempool = [pool for pool in pool_request if pool['name']
|
||||||
posts_request = await u.fetch('https://{}.net/pool/show.json'.format(booru), params={'id': tempool['id'], 'page': page}, json=True)
|
== pools[int(selection.content) - 1]][0]
|
||||||
for post in posts_request['posts']:
|
await selection.delete()
|
||||||
posts[post['id']] = {'artist': ', '.join(post['artist']), 'url': post['file_url']}
|
pool = {'name': tempool['name'], 'id': tempool['id']}
|
||||||
page += 1
|
|
||||||
|
|
||||||
return pool, posts
|
await destination.trigger_typing()
|
||||||
|
elif pool_request:
|
||||||
|
tempool = pool_request[0]
|
||||||
|
pool = {'name': pool_request[0]['name'], 'id': pool_request[0]['id']}
|
||||||
|
else:
|
||||||
|
raise exc.NotFound
|
||||||
|
|
||||||
|
page = 1
|
||||||
|
while len(posts) < tempool['post_count']:
|
||||||
|
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']:
|
||||||
|
posts[post['id']] = {'artist': ', '.join(post['artist']), 'url': post['file_url']}
|
||||||
|
page += 1
|
||||||
|
|
||||||
|
return pool, posts
|
||||||
|
|
||||||
|
except exc.Abort as e:
|
||||||
|
await e.message.edit(content='**Search aborted**')
|
||||||
|
raise exc.Continue
|
||||||
|
|
||||||
# Messy code that checks image limit and tags in blacklists
|
# Messy code that checks image limit and tags in blacklists
|
||||||
async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
async def _get_posts(self, ctx, *, booru='e621', tags=[], limit=1, previous={}):
|
||||||
|
|
Loading…
Reference in a new issue