From bee97afc3ec300798c1fcae9076b3d9620c31275 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 15 Oct 2017 13:30:40 -0400 Subject: [PATCH 1/2] Fixed MissingArgument --- src/main/cogs/booru.py | 14 +++++++++----- src/main/misc/exceptions.py | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index f5820c4..5f53873 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -66,18 +66,22 @@ class MsG: # Reverse image searches a linked image using the public iqdb @commands.command(name='reverse', aliases=['rev', 'ris'], brief='e621 Reverse image search', description='e621 | NSFW\nReverse-search an image with given URL') @checks.del_ctx() - async def reverse_image_search(self, ctx, url): + async def reverse_image_search(self, ctx, url=None): try: await ctx.trigger_typing() + + if url is None and ctx.message.attachments: + url = ctx.message.attachments[0].url + elif url is None: + raise exc.MissingArgument + await ctx.send('✅ **Probable match:**\n{}'.format(await scraper.check_match(url))) except exc.MatchError: await ctx.send('❌ **No probable match.** Make sure the URL directs to an image file.', delete_after=10) - @reverse_image_search.error - async def reverse_image_search_error(self, ctx, error): - if isinstance(error, errext.MissingRequiredArgument): - return await ctx.send('❌ **Invalid url.**', delete_after=10) + except exc.MissingArgument: + await ctx.send('❌ **Invalid url or file.**', delete_after=10) async def return_pool(self, *, ctx, booru='e621', query=[]): def on_message(msg): diff --git a/src/main/misc/exceptions.py b/src/main/misc/exceptions.py index e9fc682..9e5adea 100644 --- a/src/main/misc/exceptions.py +++ b/src/main/misc/exceptions.py @@ -25,6 +25,10 @@ class Exists(Exception): pass +class MissingArgument(Exception): + pass + + class PostError(Exception): pass From f658918473b4f85ddfeabb31553a38e261f4bc65 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 15 Oct 2017 13:31:05 -0400 Subject: [PATCH 2/2] If/else order change, formatting --- src/main/cogs/owner.py | 4 ++-- src/main/run.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index ac3b2c6..a23bdac 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -28,7 +28,7 @@ class Bot: @checks.del_ctx() async def die(self, ctx): if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel): - await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down 🌙 . . .**') + await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down** 🌙 . . .') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() @@ -43,7 +43,7 @@ class Bot: async def restart(self, ctx): print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n') if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel): - await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting 💤 . . .**') + await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting** 💤 . . .') # u.notify('R E S T A R T I N G') # loop = self.bot.loop.all_tasks() # for task in loop: diff --git a/src/main/run.py b/src/main/run.py index 453debe..fdb15e9 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -35,7 +35,7 @@ async def on_ready(): # bot.loop.create_task(u.clear(booru.temp_urls, 30*60)) if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel): - await bot.get_channel(u.config['startup_channel']).send('**Started ☀️ .**') + await bot.get_channel(u.config['startup_channel']).send('**Started** ☀️ .') print('\n\\ \\ \\ \\ \\ \\ \\ \\ \\\nC O N N E C T E D : {}\n/ / / / / / / / /\n'.format(bot.user.name)) # u.notify('C O N N E C T E D') @@ -54,15 +54,15 @@ async def on_error(error, *args, **kwargs): @bot.event async def on_command_error(ctx, error): if isinstance(error, errext.CheckFailure): - await ctx.send('❌ **Insufficient permissions.**', delete_after=10) - elif not isinstance(error, errext.CommandNotFound): + await ctx.send('⛔️ **Insufficient permissions.**', delete_after=10) + elif isinstance(error, errext.CommandNotFound): + print('INVALID COMMAND : {}'.format(error), file=sys.stderr) + 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 exc.send_error(ctx, error) # u.notify('C O M M A N D E R R O R') - else: - print('INVALID COMMAND : {}'.format(error), file=sys.stderr) async def on_reaction_add(r, u):