From 1c0c7fa053c631c3b0baee8a00b19c46c984bd86 Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Wed, 25 Mar 2020 14:52:33 -0500 Subject: [PATCH] Correct a couple errors --- cogs/images.py | 31 ++++++++++++++++++++++++++----- cogs/tictactoe.py | 10 ++++++++-- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cogs/images.py b/cogs/images.py index 120ad5b..f0f829e 100644 --- a/cogs/images.py +++ b/cogs/images.py @@ -23,11 +23,17 @@ class Images(commands.Cog): try: image = await utils.download_image(result) - f = discord.File(image, filename=result.name) - await ctx.send(file=f) except (ValueError, AttributeError): await ctx.send("I couldn't connect! Sorry no cats right now ;w;") + f = discord.File(image, filename=result.name) + try: + await ctx.send(file=f) + except discord.HTTPException: + await ctx.send( + f"File to large to send as attachment, here is the URL: {url}" + ) + @commands.command(aliases=['dog', 'rd']) @utils.can_run(send_messages=True) async def doggo(self, ctx): @@ -45,7 +51,12 @@ class Images(commands.Cog): image = await utils.download_image(url) f = discord.File(image, filename=filename) - await ctx.send(file=f) + try: + await ctx.send(file=f) + except discord.HTTPException: + await ctx.send( + f"File to large to send as attachment, here is the URL: {url}" + ) @commands.command(aliases=['snake']) @utils.can_run(send_messages=True) @@ -68,7 +79,12 @@ class Images(commands.Cog): image = await utils.download_image(filename) filename = re.search('.*/optimized/large/(.*)', filename).group(1) f = discord.File(image, filename=filename) - await ctx.send(file=f) + try: + await ctx.send(file=f) + except discord.HTTPException: + await ctx.send( + f"File to large to send as attachment, here is the URL: {url}" + ) @commands.command() @utils.can_run(send_messages=True) @@ -91,7 +107,12 @@ class Images(commands.Cog): image = await utils.download_image(filename) filename = re.search('.*/optimized/large/(.*)', filename).group(1) f = discord.File(image, filename=filename) - await ctx.send(file=f) + try: + await ctx.send(file=f) + except discord.HTTPException: + await ctx.send( + f"File to large to send as attachment, here is the URL: {url}" + ) @commands.command() @commands.guild_only() diff --git a/cogs/tictactoe.py b/cogs/tictactoe.py index 09206f5..683e8d9 100644 --- a/cogs/tictactoe.py +++ b/cogs/tictactoe.py @@ -192,12 +192,18 @@ class TicTacToe(commands.Cog): # Handle updating ratings based on the winner and loser await utils.update_records('tictactoe', ctx.bot.db, winner, loser) # This game has ended, delete it so another one can be made - del self.boards[ctx.message.guild.id] + try: + del self.boards[ctx.message.guild.id] + except KeyError: + pass else: # If no one has won, make sure the game is not full. If it has, delete the board and say it was a tie if board.full(): await ctx.send("This game has ended in a tie!") - del self.boards[ctx.message.guild.id] + try: + del self.boards[ctx.message.guild.id] + except KeyError: + pass # If no one has won, and the game has not ended in a tie, print the new updated board else: player_turn = board.challengers.get('x') if board.X_turn else board.challengers.get('o')