From 6ebd93ea147df787a6c35a19b981201d68488450 Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Mon, 26 Nov 2018 18:52:38 -0500 Subject: [PATCH 1/3] Add catching of alt invalid link error --- src/utils/scraper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index 581053e..a8e6ee2 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -16,7 +16,7 @@ async def get_post(url): if filesize > 8192 * 1024: raise exc.SizeError(size(filesize, system=alternative)) - except ValueError: + except (ValueError, KeyError): raise exc.MissingArgument content = await u.fetch('http://iqdb.harry.lu', params={'url': url}) From 82fb640fc1ba4a4049a3b6fcd146717851b6b17b Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Mon, 26 Nov 2018 18:53:23 -0500 Subject: [PATCH 2/3] Fix bot exiting on NotFound errors within on_command_error --- src/run.py | 59 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/run.py b/src/run.py index 92c9139..267aa05 100644 --- a/src/run.py +++ b/src/run.py @@ -159,35 +159,36 @@ async def on_error(error, *args, **kwargs): @bot.event async def on_command_error(ctx, error): - if isinstance(error, errext.CommandOnCooldown): - await ctx.message.add_reaction('\N{HOURGLASS}') - await asyncio.sleep(error.retry_after) - await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') - elif isinstance(error, err.NotFound): - print('NOT FOUND') - elif isinstance(error, err.Forbidden): - pass - elif isinstance(error, errext.MissingRequiredArgument): - await ctx.send('**Missing required argument**') - await ctx.message.add_reaction('\N{CROSS MARK}') - elif isinstance(error, errext.BadArgument): - await ctx.send(f'**Invalid argument.** {error}') - await ctx.message.add_reaction('\N{CROSS MARK}') - elif isinstance(error, errext.CheckFailure): - await ctx.send('**Insufficient permissions**') - await ctx.message.add_reaction('\N{NO ENTRY}') - elif isinstance(error, errext.CommandNotFound): - print('INVALID COMMAND : {}'.format(error), file=sys.stderr) - await ctx.message.add_reaction('\N{BLACK QUESTION MARK ORNAMENT}') - else: - print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format( - error), file=sys.stderr) - tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr) - await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) - await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.name, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) - await exc.send_error(ctx, error) - await ctx.message.add_reaction('\N{WARNING SIGN}') - # u.notify('C O M M A N D E R R O R') + with suppress(err.NotFound): + if isinstance(error, errext.CommandOnCooldown): + await ctx.message.add_reaction('\N{HOURGLASS}') + await asyncio.sleep(error.retry_after) + await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + elif isinstance(error, err.NotFound): + print('NOT FOUND') + elif isinstance(error, err.Forbidden): + pass + elif isinstance(error, errext.MissingRequiredArgument): + await ctx.send('**Missing required argument**') + await ctx.message.add_reaction('\N{CROSS MARK}') + elif isinstance(error, errext.BadArgument): + await ctx.send(f'**Invalid argument.** {error}') + await ctx.message.add_reaction('\N{CROSS MARK}') + elif isinstance(error, errext.CheckFailure): + await ctx.send('**Insufficient permissions**') + await ctx.message.add_reaction('\N{NO ENTRY}') + elif isinstance(error, errext.CommandNotFound): + print('INVALID COMMAND : {}'.format(error), file=sys.stderr) + await ctx.message.add_reaction('\N{BLACK QUESTION MARK ORNAMENT}') + else: + print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format( + error), file=sys.stderr) + tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr) + await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) + await bot.get_channel(u.config['info_channel']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.name, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) + await exc.send_error(ctx, error) + await ctx.message.add_reaction('\N{WARNING SIGN}') + # u.notify('C O M M A N D E R R O R') # @bot.event # async def on_command(ctx): From 2c50759753cdf7f144de39817eeec0c2f440ce51 Mon Sep 17 00:00:00 2001 From: Dylan Dizon Date: Mon, 26 Nov 2018 18:54:11 -0500 Subject: [PATCH 3/3] Add incorrect command emoticon --- src/cogs/booru.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 35079e3..4136697 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -304,7 +304,7 @@ class MsG: icon_url=self._get_score(post['score'])) except exc.MissingArgument: - await ctx.send('**Invalid url**') + await ctx.send('\N{CROSS MARK} **Invalid url**') await ctx.message.add_reaction('\N{CROSS MARK}') @get.command(name='image', aliases=['img'], brief='(get) Get direct image from post', description='Return direct image URL for given post\n\nExample:\n\{p\}get image 1145042') @@ -331,7 +331,7 @@ class MsG: await ctx.message.add_reaction('\N{CROSS MARK}') except exc.MissingArgument: - await ctx.send('**Invalid url or file**') + await ctx.send('\N{CROSS MARK} **Invalid url or file**') await ctx.message.add_reaction('\N{CROSS MARK}') @get.command(name='pool', aliases=['p'], brief='(get) Get pool from query', description='Return pool info for given query\n\nExample:\n\{p\}get pool 1145042') @@ -423,7 +423,7 @@ class MsG: await ctx.message.delete() except exc.MissingArgument: - await ctx.send('**Invalid url or file.** Be sure the link directs to an image file') + await ctx.send('\N{CROSS MARK} **Invalid url or file.** Be sure the link directs to an image file') await ctx.message.add_reaction('\N{CROSS MARK}') except exc.SizeError as e: await ctx.send(f'`{e}` **too large.** Maximum is 8 MB') @@ -1417,7 +1417,7 @@ class MsG: usage='[blacklist]') async def get_blacklist(self, ctx): if not ctx.invoked_subcommand: - await ctx.send('**Invalid blacklist**') + await ctx.send('\N{CROSS MARK} **Invalid blacklist**') await ctx.message.add_reaction('\N{CROSS MARK}') @get_blacklist.command( @@ -1483,7 +1483,7 @@ class MsG: usage='[blacklist] [tags...]') async def add_tags(self, ctx): if not ctx.invoked_subcommand: - await ctx.send('**Invalid blacklist**') + await ctx.send('\N{CROSS MARK} **Invalid blacklist**') await ctx.message.add_reaction('\N{CROSS MARK}') async def _add(self, tags, lst, alias=False): @@ -1586,7 +1586,7 @@ class MsG: usage='[blacklist] [tags...]') async def remove_tags(self, ctx): if not ctx.invoked_subcommand: - await ctx.send('**Invalid blacklist**') + await ctx.send('\N{CROSS MARK} **Invalid blacklist**') await ctx.message.add_reaction('\N{CROSS MARK}') def _remove(self, remove, lst): @@ -1684,7 +1684,7 @@ class MsG: usage='[blacklist]') async def clear_blacklist(self, ctx): if not ctx.invoked_subcommand: - await ctx.send('**Invalid blacklist**') + await ctx.send('\N{CROSS MARK} **Invalid blacklist**') await ctx.message.add_reaction('\N{CROSS MARK}') @clear_blacklist.command(