From c07c7317f4848f64530cd8a4edc5bd61c93c3918 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Wed, 31 Jan 2024 13:17:54 -0500 Subject: [PATCH] fix(backup): remove support for message content based json loading --- .docs/backup.md | 2 +- backup/backup.py | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.docs/backup.md b/.docs/backup.md index 2439d0d..787d1db 100644 --- a/.docs/backup.md +++ b/.docs/backup.md @@ -22,4 +22,4 @@ Exports a JSON list of all of your added repositories, and their installed cogs. - Usage: `[p]backup import [json]` -Imports, reinstalls, and reloads cogs from a valid export. Requires either the json export to be provided in the command's message content or to be attached to the command's message. Ignores itself and PyLav cogs. +Imports, reinstalls, and reloads cogs from a valid export. Requires the JSON export to be attached to the invoking message as an attachment. Ignores itself and PyLav cogs. diff --git a/backup/backup.py b/backup/backup.py index d70093d..0fcbccc 100644 --- a/backup/backup.py +++ b/backup/backup.py @@ -59,12 +59,12 @@ class Backup(commands.Cog): @backup.command(name='import') @commands.is_owner() - async def backup_import(self, ctx: commands.Context, *, export: str = None): - """Import your installed repositories and cogs from an export.""" + async def backup_import(self, ctx: commands.Context): + """Import your installed repositories and cogs from an export file.""" if export is None and not len(ctx.message.attachments) == 0: export = await ctx.message.attachments[0].read() try: - export = json.loads(self.extract_json_from_codeblock(export)) + export = json.loads(export) except json.JSONDecodeError: await ctx.send(error("Please provide a valid JSON export.")) return @@ -73,10 +73,3 @@ class Backup(commands.Cog): 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 - - def extract_json_from_codeblock(self, text): - match = re.match(r"```(?:\w+)?\n(.*?)\n```", text, re.DOTALL) - if match: - return match.group(1).strip() - else: - return text