mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 22:27:28 +00:00
Fix preparation, reaction, formatting, exception, and removal logic
This commit is contained in:
parent
b292fb62f7
commit
f301dd37dc
1 changed files with 32 additions and 20 deletions
|
@ -1446,19 +1446,18 @@ class MsG:
|
||||||
async def _aliases(self, ctx, tags, blacklist):
|
async def _aliases(self, ctx, tags, blacklist):
|
||||||
def on_reaction(reaction, user):
|
def on_reaction(reaction, user):
|
||||||
if user is ctx.author and reaction.message.channel is ctx.message.channel:
|
if user is ctx.author and reaction.message.channel is ctx.message.channel:
|
||||||
if reaction.emoji == '\N{HEAVY MINUS SIGN}':
|
|
||||||
raise exc.Remove
|
|
||||||
if reaction.emoji == '\N{THUMBS DOWN SIGN}':
|
if reaction.emoji == '\N{THUMBS DOWN SIGN}':
|
||||||
raise exc.Continue
|
raise exc.Continue
|
||||||
elif reaction.emoji == '\N{THUMBS UP SIGN}':
|
if reaction.emoji == '\N{HEAVY MINUS SIGN}':
|
||||||
|
raise exc.Remove
|
||||||
|
if reaction.emoji == '\N{THUMBS UP SIGN}':
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
if msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
if msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
||||||
if msg.content == '0':
|
if msg.content == '0':
|
||||||
raise exc.Abort
|
raise exc.Continue
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1466,6 +1465,7 @@ class MsG:
|
||||||
raise exc.MissingArgument
|
raise exc.MissingArgument
|
||||||
|
|
||||||
aliases = {}
|
aliases = {}
|
||||||
|
messages = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
|
@ -1475,6 +1475,7 @@ class MsG:
|
||||||
alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True)
|
alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True)
|
||||||
if alias_request:
|
if alias_request:
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
|
if dic['name']:
|
||||||
aliases[tag].add(dic['name'])
|
aliases[tag].add(dic['name'])
|
||||||
|
|
||||||
messages = await formatter.paginate(ctx, aliases)
|
messages = await formatter.paginate(ctx, aliases)
|
||||||
|
@ -1488,34 +1489,45 @@ class MsG:
|
||||||
await self.bot.wait_for('reaction_add', check=on_reaction, timeout=8 * 60)
|
await self.bot.wait_for('reaction_add', check=on_reaction, timeout=8 * 60)
|
||||||
|
|
||||||
except exc.Remove:
|
except exc.Remove:
|
||||||
await message.edit(content=f'**Also add aliases?**\n{formatter.dict_tostring(aliases, f=False)}\nType the tag(s) to remove or `0` to abort:')
|
await message.edit(content=f'Type the tag(s) to remove or `0` to cancel:')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
while not self.bot.is_closed():
|
||||||
response = await self.bot.wait_for('message', check=on_message, timeout=8 * 60)
|
response = await self.bot.wait_for('message', check=on_message, timeout=8 * 60)
|
||||||
|
|
||||||
for tag in response.content.split(' '):
|
for tag in response.content.split(' '):
|
||||||
for v in aliases.values():
|
try:
|
||||||
if tag in v:
|
for e in aliases.values():
|
||||||
v.remove(tag)
|
e.remove(tag)
|
||||||
|
messages.append(await ctx.send(f'\N{WHITE HEAVY CHECK MARK} `{tag}` **removed**'))
|
||||||
|
except KeyError:
|
||||||
|
await ctx.send(f'\N{CROSS MARK} `{tag}` **not in aliases**', delete_after=8)
|
||||||
|
except exc.Continue:
|
||||||
|
pass
|
||||||
|
|
||||||
await message.edit(content=f'**Also add aliases?**\n{formatter.dict_tostring(aliases, f=False)}\nConfirm or deny changes')
|
await message.edit(content=f'Confirm or deny changes')
|
||||||
|
|
||||||
|
while not self.bot.is_closed:
|
||||||
await self.bot.wait_for('reaction_add', check=on_reaction, timeout=8 * 60)
|
await self.bot.wait_for('reaction_add', check=on_reaction, timeout=8 * 60)
|
||||||
|
|
||||||
self.aliases.update(aliases)
|
self.aliases.update(aliases)
|
||||||
u.dump(self.aliases, 'cogs/aliases.pkl')
|
u.dump(self.aliases, 'cogs/aliases.pkl')
|
||||||
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
return blacklist
|
return blacklist
|
||||||
|
|
||||||
except exc.Continue:
|
except exc.Continue:
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
except exc.Abort:
|
except asyncio.TimeoutError:
|
||||||
await message.delete()
|
await ctx.send('\N{CROSS MARK} **Command timed out**')
|
||||||
|
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
|
except exc.Abort:
|
||||||
|
raise exc.Abort
|
||||||
|
|
||||||
|
finally:
|
||||||
|
if messages:
|
||||||
|
for msg in messages:
|
||||||
|
await msg.delete()
|
||||||
|
await message.delete()
|
||||||
|
|
||||||
@_add_tags.command(name='global', aliases=['gl', 'g'])
|
@_add_tags.command(name='global', aliases=['gl', 'g'])
|
||||||
@cmds.is_owner()
|
@cmds.is_owner()
|
||||||
|
|
Loading…
Reference in a new issue