[V3 Downloader] Uninstall multiple cogs (#2592)

* feat(downloader): Uninstall multiple cogs

* refactor(downloader): Put everything in one message
This commit is contained in:
jack1142 2019-04-23 02:17:30 +02:00 committed by Will
parent 8555f8c28c
commit 2c8a425f87

View File

@ -327,33 +327,43 @@ class Downloader(commands.Cog):
if cog.install_msg is not None: if cog.install_msg is not None:
await ctx.send(cog.install_msg.replace("[p]", ctx.prefix)) await ctx.send(cog.install_msg.replace("[p]", ctx.prefix))
@cog.command(name="uninstall", usage="<cog_name>") @cog.command(name="uninstall", usage="<cogs>")
async def _cog_uninstall(self, ctx, cog: InstalledCog): async def _cog_uninstall(self, ctx, cogs: commands.Greedy[InstalledCog]):
"""Uninstall a cog. """Uninstall cogs.
You may only uninstall cogs which were previously installed You may only uninstall cogs which were previously installed
by Downloader. by Downloader.
""" """
real_name = cog.name if not cogs:
return await ctx.send_help()
async with ctx.typing():
uninstalled_cogs = []
failed_cogs = []
for cog in set(cogs):
real_name = cog.name
poss_installed_path = (await self.cog_install_path()) / real_name poss_installed_path = (await self.cog_install_path()) / real_name
if poss_installed_path.exists(): if poss_installed_path.exists():
ctx.bot.unload_extension(real_name) ctx.bot.unload_extension(real_name)
await self._delete_cog(poss_installed_path) await self._delete_cog(poss_installed_path)
await self._remove_from_installed(cog) await self._remove_from_installed(cog)
await ctx.send( uninstalled_cogs.append(inline(real_name))
_("Cog `{cog_name}` was successfully uninstalled.").format(cog_name=real_name) else:
) failed_cogs.append(real_name)
else:
await ctx.send( message = ""
_( if uninstalled_cogs:
"That cog was installed but can no longer" message += _("Successfully uninstalled cogs: ") + humanize_list(uninstalled_cogs)
" be located. You may need to remove it's" if failed_cogs:
" files manually if it is still usable." message += (
" Also make sure you've unloaded the cog" _("\nThese cog were installed but can no longer be located: ")
" with `{prefix}unload {cog_name}`." + humanize_list(tuple(map(inline, failed_cogs)))
).format(prefix=ctx.prefix, cog_name=real_name) + _(
) "\nYou may need to remove their files manually if they are still usable."
" Also make sure you've unloaded those cogs with `{prefix}unload {cogs}`."
).format(prefix=ctx.prefix, cogs=" ".join(failed_cogs))
)
await ctx.send(message)
@cog.command(name="update") @cog.command(name="update")
async def _cog_update(self, ctx, cog_name: InstalledCog = None): async def _cog_update(self, ctx, cog_name: InstalledCog = None):