From 7fa6cd5922742df8f4441581c887b0bc91fcdc96 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 31 Jan 2024 12:18:55 -0500 Subject: [PATCH] feat(backup): changed export format --- backup/backup.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/backup/backup.py b/backup/backup.py index e907d20..f5de2c7 100644 --- a/backup/backup.py +++ b/backup/backup.py @@ -10,6 +10,7 @@ import itertools from redbot.core import commands from redbot.core.bot import Red +from redbot.core.utils.chat_formatting import text_to_file class Backup(commands.Cog): """A utility to make reinstalling repositories and cogs after migrating the bot far easier.""" @@ -34,10 +35,24 @@ class Backup(commands.Cog): if downloader is None: await ctx.send(f"You do not have the `Downloader` cog loaded.\nPlease run `{ctx.prefix}load downloader` and try again.") return + all_repos = list(downloader._repo_manager.repos) - repos_list = [[f"{i.name}", i.url] for i in all_repos] - cogs = await downloader.installed_cogs() - for cog, r in itertools.product(cogs, repos_list): - if cog.repo_name == list(r)[0]: - r.append(cog.name) - await ctx.send(json.dumps(repos_list, indent=4)) + + export_data = [] + + for repo in all_repos: + repo_dict = { + "name": repo.name, + "url": repo.url, + "cogs": [] + } + + cogs = await downloader.installed_cogs() + + for cog in cogs: + if cog.repo_name == repo.name: + repo_dict["cogs"].append(cog.name) + + export_data.append(repo_dict) + + await ctx.send(file=text_to_file(json.dumps(export_data, indent=4), 'backup.json'))