1
0
Fork 0
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:
Myned 2017-10-30 00:23:33 -04:00
parent 5d053f2ca8
commit a3dd706674

View file

@ -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,24 +484,31 @@ 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 = {}
try:
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)
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'] tempool = [pool for pool in pool_request if pool['name']
== pools[int(selection.content) - 1]][0] == pools[int(selection.content) - 1]][0]
@ -519,6 +531,10 @@ class MsG:
return pool, posts 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={}):
guild = ctx.guild if isinstance( guild = ctx.guild if isinstance(