From 27d42f4a37a28daca1807736e9159211c875cc4e Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Thu, 4 Apr 2024 02:16:49 +0200 Subject: [PATCH] avoid nesting if statements --- bot/src/cogs/dev_tools.py | 43 +++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/bot/src/cogs/dev_tools.py b/bot/src/cogs/dev_tools.py index 7e7ac37..8438534 100644 --- a/bot/src/cogs/dev_tools.py +++ b/bot/src/cogs/dev_tools.py @@ -122,12 +122,14 @@ class DevTools(commands.Cog): """ for file in listdir("./src/cogs"): - if file.endswith(".py"): - name = file[:-3] - if name == cog: - await self.bot.unload_extension(f"cogs.{name}") - embed = discord.Embed(color=ctx.me.color, description=f"{cog} has been disabled") - return await ctx.reply(embed=embed) + if not file.endswith(".py"): + continue + + name = file[:-3] + if name == cog: + await self.bot.unload_extension(f"cogs.{name}") + embed = discord.Embed(color=ctx.me.color, description=f"{cog} has been disabled") + return await ctx.reply(embed=embed) embed = embed_templates.error_warning(f"{cog} does not exist") await ctx.reply(embed=embed) @@ -144,12 +146,14 @@ class DevTools(commands.Cog): """ for file in listdir("./src/cogs"): - if file.endswith(".py"): - name = file[:-3] - if name == cog: - await self.bot.load_extension(f"cogs.{name}") - embed = discord.Embed(color=ctx.me.color, description=f"{cog} loaded") - return await ctx.reply(embed=embed) + if not file.endswith(".py"): + continue + + name = file[:-3] + if name == cog: + await self.bot.load_extension(f"cogs.{name}") + embed = discord.Embed(color=ctx.me.color, description=f"{cog} loaded") + return await ctx.reply(embed=embed) embed = embed_templates.error_warning(f"{cog} does not exist") await ctx.reply(embed=embed) @@ -164,13 +168,16 @@ class DevTools(commands.Cog): ctx (commands.Context): Context object cog (str): The name of the cog to reload """ + for file in listdir("./src/cogs"): - if file.endswith(".py"): - name = file[:-3] - if name == cog: - await self.bot.reload_extension(f"cogs.{name}") - embed = discord.Embed(color=ctx.me.color, description=f"{cog} has been reloaded") - return await ctx.reply(embed=embed) + if not file.endswith(".py"): + continue + + name = file[:-3] + if name == cog: + await self.bot.reload_extension(f"cogs.{name}") + embed = discord.Embed(color=ctx.me.color, description=f"{cog} has been reloaded") + return await ctx.reply(embed=embed) embed = embed_templates.error_warning(f"{cog} does not exist") await ctx.reply(embed=embed)