From 929fd0461315006c1b7b4e43bd38c89a718c9b33 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Mon, 17 Aug 2020 01:27:46 +0200 Subject: [PATCH] EUD things for Downloader (#4169) * Initial commit * Send pagified as with other Downloader's things --- docs/guide_publish_cogs.rst | 3 ++ redbot/cogs/downloader/downloader.py | 48 +++++++++++++++++++++----- redbot/cogs/downloader/info_schemas.py | 1 + redbot/cogs/downloader/installable.py | 3 ++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/docs/guide_publish_cogs.rst b/docs/guide_publish_cogs.rst index 236130624..f776e513e 100644 --- a/docs/guide_publish_cogs.rst +++ b/docs/guide_publish_cogs.rst @@ -55,6 +55,9 @@ Keys common to both repo and cog info.json (case sensitive) Keys specific to the cog info.json (case sensitive) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- ``end_user_data_statement`` (string) - A statement explaining what end user data the cog is storing. + This is displayed when a user executes ``[p]cog info``. If the statement has changed since last update, user will be informed during the update. + - ``min_bot_version`` (string) - Min version number of Red in the format ``MAJOR.MINOR.MICRO`` - ``max_bot_version`` (string) - Max version number of Red in the format ``MAJOR.MINOR.MICRO``, diff --git a/redbot/cogs/downloader/downloader.py b/redbot/cogs/downloader/downloader.py index f4888e441..131c64a1b 100644 --- a/redbot/cogs/downloader/downloader.py +++ b/redbot/cogs/downloader/downloader.py @@ -775,8 +775,12 @@ class Downloader(commands.Cog): if rev is not None else "" ) - + _("\nYou can load them using `{prefix}load `").format( - prefix=ctx.clean_prefix + + _( + "\nYou can load them using {command_1}." + " To see end user data statements, you can use {command_2}." + ).format( + command_1=inline(f"{ctx.clean_prefix}load "), + command_2=inline(f"{ctx.clean_prefix}cog info "), ) + message ) @@ -1037,7 +1041,7 @@ class Downloader(commands.Cog): if updates_available: updated_cognames, message = await self._update_cogs_and_libs( - cogs_to_update, libs_to_update + ctx, cogs_to_update, libs_to_update, current_cog_versions=cogs_to_check ) else: if repos: @@ -1118,15 +1122,24 @@ class Downloader(commands.Cog): return msg = _( - "Information on {cog_name}:\n{description}\n\n" - "Made by: {author}\nRequirements: {requirements}" + "Information on {cog_name}:\n" + "{description}\n\n" + "End user data statement:\n" + "{end_user_data_statement}\n\n" + "Made by: {author}\n" + "Requirements: {requirements}" ).format( cog_name=cog.name, description=cog.description or "", + end_user_data_statement=( + cog.end_user_data_statement + or _("Author of the cog didn't provide end user data statement.") + ), author=", ".join(cog.author) or _("Missing from info.json"), requirements=", ".join(cog.requirements) or "None", ) - await ctx.send(box(msg)) + for page in pagify(msg): + await ctx.send(box(page)) async def is_installed( self, cog_name: str @@ -1292,8 +1305,13 @@ class Downloader(commands.Cog): return (cogs_to_check, failed) async def _update_cogs_and_libs( - self, cogs_to_update: Iterable[Installable], libs_to_update: Iterable[Installable] + self, + ctx: commands.Context, + cogs_to_update: Iterable[Installable], + libs_to_update: Iterable[Installable], + current_cog_versions: Iterable[InstalledModule], ) -> Tuple[Set[str], str]: + current_cog_versions_map = {cog.name: cog for cog in current_cog_versions} failed_reqs = await self._install_requirements(cogs_to_update) if failed_reqs: return ( @@ -1308,8 +1326,22 @@ class Downloader(commands.Cog): updated_cognames: Set[str] = set() if installed_cogs: - updated_cognames = {cog.name for cog in installed_cogs} + updated_cognames = set() + cogs_with_changed_eud_statement = set() + for cog in installed_cogs: + updated_cognames.add(cog.name) + current_eud_statement = current_cog_versions_map[cog.name].end_user_data_statement + if current_eud_statement != cog.end_user_data_statement: + cogs_with_changed_eud_statement.add(cog.name) message += _("\nUpdated: ") + humanize_list(tuple(map(inline, updated_cognames))) + if cogs_with_changed_eud_statement: + message += ( + _("\nEnd user data statements of these cogs have changed: ") + + humanize_list(tuple(map(inline, cogs_with_changed_eud_statement))) + + _("\nYou can use {command} to see the updated statements.\n").format( + command=inline(f"{ctx.clean_prefix}cog info ") + ) + ) if failed_cogs: cognames = [cog.name for cog in failed_cogs] message += _("\nFailed to update cogs: ") + humanize_list(tuple(map(inline, cognames))) diff --git a/redbot/cogs/downloader/info_schemas.py b/redbot/cogs/downloader/info_schemas.py index f6564b181..8033d13f8 100644 --- a/redbot/cogs/downloader/info_schemas.py +++ b/redbot/cogs/downloader/info_schemas.py @@ -220,6 +220,7 @@ INSTALLABLE_SCHEMA: SchemaType = { "requirements": ensure_tuple_of_str, "tags": ensure_tuple_of_str, "type": ensure_installable_type, + "end_user_data_statement": ensure_str, } diff --git a/redbot/cogs/downloader/installable.py b/redbot/cogs/downloader/installable.py index 5bb541c3e..c203116e0 100644 --- a/redbot/cogs/downloader/installable.py +++ b/redbot/cogs/downloader/installable.py @@ -43,6 +43,8 @@ class Installable(RepoJSONMixin): Installable's commit. This is not the same as ``repo.commit`` author : `tuple` of `str` Name(s) of the author(s). + end_user_data_statement : `str` + End user data statement of the module. min_bot_version : `VersionInfo` The minimum bot version required for this Installable. max_bot_version : `VersionInfo` @@ -85,6 +87,7 @@ class Installable(RepoJSONMixin): self.repo_name = self._location.parent.stem self.commit = commit + self.end_user_data_statement: str self.min_bot_version: VersionInfo self.max_bot_version: VersionInfo self.min_python_version: Tuple[int, int, int]