From 35ffec9c3fa6e227228c1cff0b7b705eaad63a8c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 31 Jan 2024 12:35:01 -0500 Subject: [PATCH] fix(backup): pylint fixes --- backup/backup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backup/backup.py b/backup/backup.py index f5de2c7..f296eca 100644 --- a/backup/backup.py +++ b/backup/backup.py @@ -6,11 +6,10 @@ # |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_| import json -import itertools from redbot.core import commands from redbot.core.bot import Red -from redbot.core.utils.chat_formatting import text_to_file +from redbot.core.utils.chat_formatting import error, text_to_file class Backup(commands.Cog): """A utility to make reinstalling repositories and cogs after migrating the bot far easier.""" @@ -33,10 +32,10 @@ class Backup(commands.Cog): """Export your installed repositories and cogs to a file.""" downloader = ctx.bot.get_cog("Downloader") 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.") + await ctx.send(error(f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again.")) return - all_repos = list(downloader._repo_manager.repos) + all_repos = list(downloader._repo_manager.repos) # pylint: disable=protected-access export_data = [] @@ -56,3 +55,18 @@ class Backup(commands.Cog): export_data.append(repo_dict) await ctx.send(file=text_to_file(json.dumps(export_data, indent=4), 'backup.json')) + + @backup.command(name='import') + @commands.is_owner() + async def backup_import(self, ctx: commands.Context, json: str = None): + """Import your installed repositories and cogs from an export.""" + if json is None: + json = await ctx.message.attachments[0].read() + if json is None: + await ctx.send(error("Please provide a valid JSON export.")) + return + + downloader = ctx.bot.get_cog("Downloader") + if downloader is None: + await ctx.send(error(f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again.")) + return