this is kinda a lot but shh

This commit is contained in:
jack1142
2021-04-05 18:24:11 +02:00
parent 83f2627ee9
commit f2981635e3

View File

@@ -499,25 +499,18 @@ class Downloader(commands.Cog):
success = await repo.install_raw_requirements(deps, self.LIB_PATH) success = await repo.install_raw_requirements(deps, self.LIB_PATH)
if success: if success:
if len(deps) > 1: await ctx.send(_("Libraries installed.") if len(deps) > 1 else _("Library installed."))
await ctx.send(_("Libraries installed."))
else:
await ctx.send(_("Library installed."))
else: else:
if len(deps) > 1: await ctx.send(
await ctx.send( _(
_( "Some libraries failed to install. Please check"
"Some libraries failed to install. Please check" " your logs for a complete list."
" your logs for a complete list."
)
) )
else: if len(deps) > 1
await ctx.send( else _(
_( "The library failed to install. Please check your logs for a complete list."
"The library failed to install. Please check "
"your logs for a complete list."
)
) )
)
@commands.group() @commands.group()
@checks.is_owner() @checks.is_owner()
@@ -726,14 +719,18 @@ class Downloader(commands.Cog):
all_failed_libs += failed_libs all_failed_libs += failed_libs
message = "" message = ""
if failed_reqs: if failed_reqs:
message += _("Failed to install requirements: ") + humanize_list( message += (
tuple(map(inline, failed_reqs)) _("Failed to install requirements: ")
) if len(failed_reqs) > 1
else _("Failed to install the requirement: ")
) + humanize_list(tuple(map(inline, failed_reqs)))
if all_failed_libs: if all_failed_libs:
libnames = [lib.name for lib in failed_libs] libnames = [lib.name for lib in failed_libs]
message += _("\nFailed to install shared libraries: ") + humanize_list( message += (
tuple(map(inline, libnames)) _("\nFailed to install shared libraries: ")
) if len(all_failed_libs) > 1
else _("\nFailed to install shared library: ")
) + humanize_list(tuple(map(inline, libnames)))
if message: if message:
await self.send_pagified( await self.send_pagified(
ctx, ctx,
@@ -825,9 +822,11 @@ class Downloader(commands.Cog):
return return
failed_reqs = await self._install_requirements(cogs) failed_reqs = await self._install_requirements(cogs)
if failed_reqs: if failed_reqs:
message += _("\nFailed to install requirements: ") + humanize_list( message += (
tuple(map(inline, failed_reqs)) _("\nFailed to install requirements: ")
) if len(failed_reqs) > 1
else _("\nFailed to install requirement: ")
) + humanize_list(tuple(map(inline, failed_reqs)))
await self.send_pagified(ctx, message) await self.send_pagified(ctx, message)
return return
@@ -846,19 +845,33 @@ class Downloader(commands.Cog):
if failed_libs: if failed_libs:
libnames = [inline(lib.name) for lib in failed_libs] libnames = [inline(lib.name) for lib in failed_libs]
message = ( message = (
_("\nFailed to install shared libraries for `{repo.name}` repo: ").format( (
repo=repo _("\nFailed to install shared libraries for `{repo.name}` repo: ")
) if len(libnames) > 1
else _("\nFailed to install shared library for `{repo.name}` repo: ")
).format(repo=repo)
+ humanize_list(libnames) + humanize_list(libnames)
+ message + message
) )
if failed_cogs: if failed_cogs:
cognames = [inline(cog.name) for cog in failed_cogs] cognames = [inline(cog.name) for cog in failed_cogs]
message = _("\nFailed to install cogs: ") + humanize_list(cognames) + message message = (
(
_("\nFailed to install cogs: ")
if len(failed_cogs) > 1
else _("\nFailed to install the cog: ")
)
+ humanize_list(cognames)
+ message
)
if installed_cogs: if installed_cogs:
cognames = [inline(cog.name) for cog in installed_cogs] cognames = [inline(cog.name) for cog in installed_cogs]
message = ( message = (
_("Successfully installed cogs: ") (
_("Successfully installed cogs: ")
if len(installed_cogs) > 1
else _("Successfully installed the cog:")
)
+ humanize_list(cognames) + humanize_list(cognames)
+ ( + (
_( _(
@@ -917,12 +930,11 @@ class Downloader(commands.Cog):
message = "" message = ""
if uninstalled_cogs: if uninstalled_cogs:
if len(uninstalled_cogs) > 1: message += (
message += _("Successfully uninstalled cogs: ") + humanize_list( _("Successfully uninstalled cogs: ")
uninstalled_cogs if len(uninstalled_cogs) > 1
) else _("Successfully uninstalled the cog: ")
else: ) + humanize_list(uninstalled_cogs)
message += _("Successfully uninstalled the cog: ") + uninstalled_cogs[0]
if failed_cogs: if failed_cogs:
if len(failed_cogs) > 1: if len(failed_cogs) > 1:
message += ( message += (
@@ -941,16 +953,20 @@ class Downloader(commands.Cog):
) )
) )
else: else:
message += _( message += (
"\nDownloader has removed the cog {cog} from the installed cogs list" _(
" but it wasn't able to find his files." "\nDownloader has removed this cog from the installed cogs list"
).format(cog=inline(failed_cogs[0])) + _( " but it wasn't able to find its files: "
"\nIt was most likely removed without using {command_1}.\n" )
"You may need to remove those files manually if the cog is still usable." + inline(failed_cogs[0])
" If so, ensure the cog has been unloaded with {command_2}." + _(
).format( "\nIt was most likely removed without using {command_1}.\n"
command_1=inline(f"{ctx.clean_prefix}cog uninstall"), "You may need to remove those files manually if the cog is still usable."
command_2=inline(f"{ctx.clean_prefix}unload {failed_cogs[0]}"), " If so, ensure the cog has been unloaded with {command_2}."
).format(
command_1=inline(f"{ctx.clean_prefix}cog uninstall"),
command_2=inline(f"{ctx.clean_prefix}unload {failed_cogs[0]}"),
)
) )
await self.send_pagified(ctx, message) await self.send_pagified(ctx, message)
@@ -978,15 +994,15 @@ class Downloader(commands.Cog):
if pinned: if pinned:
await self._save_to_installed(pinned) await self._save_to_installed(pinned)
cognames = [inline(cog.name) for cog in pinned] cognames = [inline(cog.name) for cog in pinned]
if len(pinned) > 1: message += (
message += _("Pinned cogs: ") + humanize_list(cognames) _("Pinned cogs: ") if len(pinned) > 1 else _("Pinned cog: ")
else: ) + humanize_list(cognames)
message += _("Pinned {cog}").format(cognames[0])
if already_pinned: if already_pinned:
if len(already_pinned) > 1: message += (
message += _("\nThese cogs were already pinned: ") + humanize_list(already_pinned) _("\nThese cogs were already pinned: ")
else: if len(already_pinned) > 1
message += _("\n{cog} was already pinned.").format(cog=already_pinned[0]) else _("\nThis cog was already pinned: ")
) + humanize_list(already_pinned)
await self.send_pagified(ctx, message) await self.send_pagified(ctx, message)
@cog.command(name="unpin", require_var_positional=True) @cog.command(name="unpin", require_var_positional=True)
@@ -1012,15 +1028,15 @@ class Downloader(commands.Cog):
if unpinned: if unpinned:
await self._save_to_installed(unpinned) await self._save_to_installed(unpinned)
cognames = [inline(cog.name) for cog in unpinned] cognames = [inline(cog.name) for cog in unpinned]
if len(unpinned) > 1: message += (
message += _("Unpinned cogs: ") + humanize_list(cognames) _("Unpinned cogs: ") if len(unpinned) > 1 else _("Unpinned cog: ")
else: ) + humanize_list(cognames)
message += _("Unpinned {cog}").format(cognames[0])
if not_pinned: if not_pinned:
if len(not_pinned) > 1: message += (
message += _("\nThese cogs weren't pinned: ") + humanize_list(not_pinned) _("\nThese cogs weren't pinned: ")
else: if len(not_pinned) > 1
message += _("\n{cog} was already not pinned.").format(cog=not_pinned[0]) else _("\nThis cog was already not pinned: ")
) + humanize_list(not_pinned)
await self.send_pagified(ctx, message) await self.send_pagified(ctx, message)
@cog.command(name="listpinned") @cog.command(name="listpinned")
@@ -1065,22 +1081,18 @@ class Downloader(commands.Cog):
message = "" message = ""
if cogs_to_update: if cogs_to_update:
cognames = [cog.name for cog in cogs_to_update] cognames = [cog.name for cog in cogs_to_update]
if len(cognames) > 1: message += (
message += _("These cogs can be updated: ") + humanize_list( _("These cogs can be updated: ")
tuple(map(inline, cognames)) if len(cognames) > 1
) else _("This cog can be updated: ")
else: ) + humanize_list(tuple(map(inline, cognames)))
message += _("{cog} can be updated.").format(cog=inline(cognames[0]))
if libs_to_update: if libs_to_update:
libnames = [cog.name for cog in libs_to_update] libnames = [cog.name for cog in libs_to_update]
if len(libnames) > 1: message += (
message += _("\nThese shared libraries can be updated: ") + humanize_list( _("\nThese shared libraries can be updated: ")
tuple(map(inline, libnames)) if len(libnames) > 1
) else _("\nThis shared library can be updated: ")
else: ) + humanize_list(tuple(map(inline, libnames)))
message += _("\nShared library {library} can be updated.").format(
library=inline(libnames[0])
)
if not (cogs_to_update or libs_to_update) and filter_message: if not (cogs_to_update or libs_to_update) and filter_message:
message += _("No cogs can be updated.") message += _("No cogs can be updated.")
message += filter_message message += filter_message
@@ -1206,8 +1218,10 @@ class Downloader(commands.Cog):
message += _("There were no cogs to check.") message += _("There were no cogs to check.")
if pinned_cogs: if pinned_cogs:
cognames = [cog.name for cog in pinned_cogs] cognames = [cog.name for cog in pinned_cogs]
message += _( message += (
"\nThese cogs are pinned and therefore weren't checked: " _("\nThese cogs are pinned and therefore weren't checked: ")
if len(cognames) > 1
else _("\nThis cog is pinned and therefore wasn't checked: ")
) + humanize_list(tuple(map(inline, cognames))) ) + humanize_list(tuple(map(inline, cognames)))
else: else:
cogs_to_update, libs_to_update = await self._available_updates(cogs_to_check) cogs_to_update, libs_to_update = await self._available_updates(cogs_to_check)
@@ -1240,8 +1254,10 @@ class Downloader(commands.Cog):
await repo.checkout(repo.branch) await repo.checkout(repo.branch)
if pinned_cogs: if pinned_cogs:
cognames = [cog.name for cog in pinned_cogs] cognames = [cog.name for cog in pinned_cogs]
message += _( message += (
"\nThese cogs are pinned and therefore weren't checked: " _("\nThese cogs are pinned and therefore weren't checked: ")
if len(cognames) > 1
else _("\nThis cog is pinned and therefore wasn't checked: ")
) + humanize_list(tuple(map(inline, cognames))) ) + humanize_list(tuple(map(inline, cognames)))
message += filter_message message += filter_message
@@ -1403,30 +1419,23 @@ class Downloader(commands.Cog):
message = "" message = ""
if unavailable_cogs: if unavailable_cogs:
if len(unavailable_cogs) > 1: message = (
message += _("\nCouldn't find these cogs in {repo.name}: ").format( _("\nCouldn't find these cogs in {repo.name}: ")
repo=repo if len(unavailable_cogs) > 1
) + humanize_list(unavailable_cogs) else _("\nCouldn't find this cog in {repo.name}: ")
else: ) + humanize_list(unavailable_cogs)
message += _("\nCouldn't find {cog} cog in {repo.name}").format(
cog=unavailable_cogs[0], repo=repo
)
if already_installed: if already_installed:
if len(already_installed) > 1: message += (
message += _("\nThese cogs were already installed: ") + humanize_list( _("\nThese cogs were already installed: ")
already_installed if len(already_installed) > 1
) else _("\nThis cog was already installed: ")
else: ) + humanize_list(already_installed)
message += _("\n{cog} was already installed.").format(cog=already_installed[0])
if name_already_used: if name_already_used:
if len(name_already_used) > 1: message += (
message += _( _("\nSome cogs with these names are already installed from different repos: ")
"\nSome cogs with these names are already installed from different repos: " if len(name_already_used) > 1
) + humanize_list(name_already_used) else _("Cog with this is already installed from a different repo.")
else: ) + humanize_list(name_already_used)
message += _(
"Cog with name {cog} is already installed from a different repo."
).format(cog=name_already_used[0])
correct_cogs, add_to_message = self._filter_incorrect_cogs(cogs) correct_cogs, add_to_message = self._filter_incorrect_cogs(cogs)
if add_to_message: if add_to_message:
return correct_cogs, f"{message}{add_to_message}" return correct_cogs, f"{message}{add_to_message}"
@@ -1467,25 +1476,23 @@ class Downloader(commands.Cog):
correct_cogs.append(cog) correct_cogs.append(cog)
message = "" message = ""
if outdated_python_version: if outdated_python_version:
if len(outdated_python_version) > 1: message += (
message += _( _("\nThese cogs require higher python version than you have: ")
"\nThese cogs require higher python version than you have: " if len(outdated_python_version)
) + humanize_list(outdated_python_version) else _("This cog requires higher python version than you have: ")
else: ) + humanize_list(outdated_python_version)
message += _("{cog} requires higher python version than you have.").format(
outdated_python_version[0]
)
if outdated_bot_version: if outdated_bot_version:
if len(outdated_bot_version) > 1: message += (
message += _( _(
"\nThese cogs require different Red version" "\nThese cogs require different Red version"
" than you currently have ({current_version}): " " than you currently have ({current_version}): "
).format(current_version=red_version_info) + humanize_list(outdated_bot_version) )
else: if len(outdated_bot_version) > 1
message += _( else _(
"{cog} requires different Red version than you currently " "This cog requires different Red version than you currently "
"have ({current_version})" "have ({current_version}): "
).format(cog=outdated_bot_version, current_version=red_version_info) )
).format(current_version=red_version_info) + humanize_list(outdated_bot_version)
return tuple(correct_cogs), message return tuple(correct_cogs), message
@@ -1542,7 +1549,11 @@ class Downloader(commands.Cog):
if failed_reqs: if failed_reqs:
return ( return (
set(), set(),
_("Failed to install requirements: ") (
_("Failed to install requirements: ")
if len(failed_reqs) > 1
else _("Failed to install the requirement: ")
)
+ humanize_list(tuple(map(inline, failed_reqs))), + humanize_list(tuple(map(inline, failed_reqs))),
) )
installed_cogs, failed_cogs = await self._install_cogs(cogs_to_update) installed_cogs, failed_cogs = await self._install_cogs(cogs_to_update)
@@ -1559,10 +1570,7 @@ class Downloader(commands.Cog):
current_eud_statement = current_cog_versions_map[cog.name].end_user_data_statement current_eud_statement = current_cog_versions_map[cog.name].end_user_data_statement
if current_eud_statement != cog.end_user_data_statement: if current_eud_statement != cog.end_user_data_statement:
cogs_with_changed_eud_statement.add(cog.name) cogs_with_changed_eud_statement.add(cog.name)
if len(installed_cogs) > 1: message += _("\nUpdated: ") + humanize_list(tuple(map(inline, updated_cognames)))
message += _("\nUpdated: ") + humanize_list(tuple(map(inline, updated_cognames)))
else:
message += _("\n{cog} updated.").format(cog=inline(tuple(updated_cognames)[0]))
if cogs_with_changed_eud_statement: if cogs_with_changed_eud_statement:
if len(cogs_with_changed_eud_statement) > 1: if len(cogs_with_changed_eud_statement) > 1:
message += ( message += (
@@ -1573,44 +1581,41 @@ class Downloader(commands.Cog):
) )
) )
else: else:
message += _("End user data statement for {cog} has changed.").format( message += (
cog=tuple(cogs_with_changed_eud_statement)[0] _("End user data statement of this cog has changed:")
) + _("\nYou can use {command} to see the updated statement.\n").format( + inline(next(iter(cogs_with_changed_eud_statement)))
command=inline(f"{ctx.clean_prefix}cog info <repo> <cog>") + _("\nYou can use {command} to see the updated statement.\n").format(
command=inline(f"{ctx.clean_prefix}cog info <repo> <cog>")
)
) )
if failed_cogs: if failed_cogs:
cognames = [cog.name for cog in failed_cogs] cognames = [cog.name for cog in failed_cogs]
if len(failed_cogs) > 1: message += (
message += _("\nFailed to update cogs: ") + humanize_list( _("\nFailed to update cogs: ")
tuple(map(inline, cognames)) if len(failed_cogs) > 1
) else _("\nFailed to update cog: ")
else: ) + humanize_list(tuple(map(inline, cognames)))
message += _("\nFailed to update cog: ") + humanize_list(
tuple(map(inline, cognames))
)
if not cogs_to_update: if not cogs_to_update:
message = _("No cogs were updated.") message = _("No cogs were updated.")
if installed_libs: if installed_libs:
if len(installed_libs) > 1: message += (
message += _( _(
"\nSome shared libraries were updated, you should restart the bot " "\nSome shared libraries were updated, you should restart the bot "
"to bring the changes into effect." "to bring the changes into effect."
) )
else: if len(installed_libs) > 1
message += _( else _(
"\nA shared library was updated, you should restart the " "\nA shared library was updated, you should restart the "
"bot to bring the changes into effect." "bot to bring the changes into effect."
) )
)
if failed_libs: if failed_libs:
libnames = [lib.name for lib in failed_libs] libnames = [lib.name for lib in failed_libs]
if len(failed_cogs) > 1: message += (
message += _("\nFailed to install shared libraries: ") + humanize_list( _("\nFailed to install shared libraries: ")
tuple(map(inline, libnames)) if len(failed_cogs) > 1
) else _("\nFailed to install shared library: ")
else: ) + humanize_list(tuple(map(inline, libnames)))
message += _("\nFailed to install shared library: ") + humanize_list(
tuple(map(inline, libnames))
)
return (updated_cognames, message) return (updated_cognames, message)
async def _ask_for_cog_reload(self, ctx: commands.Context, updated_cognames: Set[str]) -> None: async def _ask_for_cog_reload(self, ctx: commands.Context, updated_cognames: Set[str]) -> None:
@@ -1620,12 +1625,11 @@ class Downloader(commands.Cog):
return return
if not ctx.assume_yes: if not ctx.assume_yes:
if len(updated_cognames) > 1: message = (
message = _("Would you like to reload the updated cogs?") _("Would you like to reload the updated cogs?")
else: if len(updated_cognames) > 1
message = _("Would you like to reload {cog}?").format( else _("Would you like to reload the updated cog?")
cog=inline(updated_cognames[0]) )
)
can_react = ctx.channel.permissions_for(ctx.me).add_reactions can_react = ctx.channel.permissions_for(ctx.me).add_reactions
if not can_react: if not can_react:
message += " (y/n)" message += " (y/n)"