From c046fa2c45b6408e9502754bfbd9cc22feed4c18 Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sun, 3 Jul 2022 13:32:55 -0400 Subject: [PATCH] Using asserts for error catching. --- cogs/post_highscores/__init__.py | 8 ++++---- cogs/score/__init__.py | 18 ++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cogs/post_highscores/__init__.py b/cogs/post_highscores/__init__.py index 300b5a4..498499a 100644 --- a/cogs/post_highscores/__init__.py +++ b/cogs/post_highscores/__init__.py @@ -28,11 +28,11 @@ class PostHighscores(commands.Cog, name="Post Highscores"): highscore_channel_id = highscores_data["highscore_channel_id"] print(f"Printing out highscores information in channel {highscore_channel_id}") channel = self.bot.get_channel(highscore_channel_id) - if channel is None: - response = 'Registered Highscores channel does not exist or was never registered. \ + + error_response = 'Registered Highscores channel does not exist or was never registered. \ Register with "?register" command.' - await ctx.send(response) - return + assert channel is not None, await ctx.send(error_response) + for boss in highscores_config["bosses"]: await highscore_message.send_highscore_message(channel, boss["boss"]) diff --git a/cogs/score/__init__.py b/cogs/score/__init__.py index bc9ae5e..7b12180 100644 --- a/cogs/score/__init__.py +++ b/cogs/score/__init__.py @@ -26,18 +26,16 @@ class Score(commands.Cog, name="Score"): verification_channel_id = highscores_data["verification_channel_id"] channel = self.bot.get_channel(verification_channel_id) - if channel is None: - response = "Registered Verification channel does not exist or was never registered. \ + error_response = "Registered Verification channel does not exist or was never registered. \ Contact server admins." - await ctx.send(response) - return - else: - verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}" + assert channel is not None, await ctx.send(error_response) - await channel.send( - content=verification_string, - files=[await attch.to_file() for attch in ctx.message.attachments], - ) + verification_string = f"{ctx.author.display_name}:{boss_name}:{category}:{score}" + + await channel.send( + content=verification_string, + files=[await attch.to_file() for attch in ctx.message.attachments], + ) # await highscore_manage.submit_score(self, ctx, boss_name, category, score)