feat(backup): changed export format

This commit is contained in:
Seaswimmer 2024-01-31 12:18:55 -05:00
parent abc9927dea
commit 7fa6cd5922
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -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'))