From fca8684f34e8beb4da6ea9cc06e8f2d5d8353974 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Wed, 24 Apr 2019 12:07:29 +0300 Subject: [PATCH] Add cog load actions, solve the bug we found on verification reload --- cogs/admin.py | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index 97cb672..c29bcd5 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -4,6 +4,7 @@ from discord.ext.commands import Cog import traceback import inspect import re +import config from helpers.checks import check_if_bot_manager @@ -21,20 +22,6 @@ class Admin(Cog): await ctx.send(":wave: Goodbye!") await self.bot.logout() - @commands.guild_only() - @commands.check(check_if_bot_manager) - @commands.command() - async def load(self, ctx, ext: str): - """Loads a cog, bot manager only.""" - try: - self.bot.load_extension("cogs." + ext) - except: - await ctx.send(f':x: Cog loading failed, traceback: ' - f'```\n{traceback.format_exc()}\n```') - return - self.bot.log.info(f'Loaded ext {ext}') - await ctx.send(f':white_check_mark: `{ext}` successfully loaded.') - @commands.guild_only() @commands.check(check_if_bot_manager) @commands.command() @@ -105,6 +92,11 @@ class Admin(Cog): for msg in sliced_message: await ctx.send(msg) + async def cog_load_actions(self, cog_name): + if cog_name == "verification": + verif_channel = self.bot.get_channel(config.welcome_channel) + await self.bot.do_resetalgo(verif_channel, "cog load") + @commands.guild_only() @commands.check(check_if_bot_manager) @commands.command() @@ -117,16 +109,31 @@ class Admin(Cog): cogs_to_reload = re.findall(r'cogs/([a-z_]*).py[ ]*\|', git_output) for cog in cogs_to_reload: try: - self.bot.unload_extension("cogs." + cog) - self.bot.load_extension("cogs." + cog) + self.bot.reload_extension("cogs." + cog) self.bot.log.info(f'Reloaded ext {cog}') await ctx.send(f':white_check_mark: `{cog}` ' 'successfully reloaded.') + await self.cog_load_actions(cog) except: await ctx.send(f':x: Cog reloading failed, traceback: ' f'```\n{traceback.format_exc()}\n```') return + @commands.guild_only() + @commands.check(check_if_bot_manager) + @commands.command() + async def load(self, ctx, ext: str): + """Loads a cog, bot manager only.""" + try: + self.bot.load_extension("cogs." + ext) + await self.cog_load_actions(ext) + except: + await ctx.send(f':x: Cog loading failed, traceback: ' + f'```\n{traceback.format_exc()}\n```') + return + self.bot.log.info(f'Loaded ext {ext}') + await ctx.send(f':white_check_mark: `{ext}` successfully loaded.') + @commands.guild_only() @commands.check(check_if_bot_manager) @commands.command() @@ -146,8 +153,8 @@ class Admin(Cog): self.lastreload = ext try: - self.bot.unload_extension("cogs." + ext) - self.bot.load_extension("cogs." + ext) + self.bot.reload_extension("cogs." + ext) + await self.cog_load_actions(ext) except: await ctx.send(f':x: Cog reloading failed, traceback: ' f'```\n{traceback.format_exc()}\n```')