[V3 Core] Fix reload of core cogs (#980)

* Fix reload of core cogs

* Remove trailing whitespace
This commit is contained in:
Tobotimus 2017-10-02 04:20:21 +11:00 committed by Will
parent ea4aaf61c1
commit 31395d9efc

View File

@ -82,17 +82,21 @@ class Core:
async def _reload(self, ctx, *, cog_name: str): async def _reload(self, ctx, *, cog_name: str):
"""Reloads a package""" """Reloads a package"""
ctx.bot.unload_extension(cog_name) ctx.bot.unload_extension(cog_name)
self.cleanup_and_refresh_modules(cog_name)
spec = await find_spec(ctx.bot, cog_name)
if spec is None:
await ctx.send(_("No module by that name was found in any"
" cog path."))
return
self.cleanup_and_refresh_modules(spec.name)
try: try:
spec = await ctx.bot.cog_mgr.find_cog(cog_name)
ctx.bot.load_extension(spec) ctx.bot.load_extension(spec)
except Exception as e: except Exception as e:
log.exception("Package reloading failed", exc_info=e) log.exception("Package reloading failed", exc_info=e)
await ctx.send(_("Failed to reload package. Check your console or " await ctx.send(_("Failed to reload package. Check your console or "
"logs for details.")) "logs for details."))
else: else:
curr_pkgs = await ctx.bot.db.packages()
await ctx.bot.save_packages_status(curr_pkgs)
await ctx.send(_("Done.")) await ctx.send(_("Done."))
@commands.command(name="shutdown") @commands.command(name="shutdown")
@ -120,7 +124,7 @@ class Core:
else: else:
importlib._bootstrap._exec(lib.__spec__, lib) importlib._bootstrap._exec(lib.__spec__, lib)
modules = itertools.accumulate(splitted, lambda old, next: "{}.{}".format(old, next)) modules = itertools.accumulate(splitted, "{}.{}".format)
for m in modules: for m in modules:
maybe_reload(m) maybe_reload(m)