misc(backup): condensed some code
Some checks failed
Actions / Lint Code (Pylint) (pull_request) Failing after 16s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 11s

This commit is contained in:
Seaswimmer 2024-01-31 13:21:24 -05:00
parent 037ef84dcc
commit ac761d9284
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -61,14 +61,10 @@ class Backup(commands.Cog):
@commands.is_owner() @commands.is_owner()
async def backup_import(self, ctx: commands.Context): async def backup_import(self, ctx: commands.Context):
"""Import your installed repositories and cogs from an export file.""" """Import your installed repositories and cogs from an export file."""
if not len(ctx.message.attachments) == 0:
export = await ctx.message.attachments[0].read()
else:
await ctx.send(error("Please provide a valid JSON export file."))
return
try: try:
export = json.loads(export) export_raw = await ctx.message.attachments[0].read()
except json.JSONDecodeError: export = json.loads(export_raw)
except (json.JSONDecodeError, IndexError):
await ctx.send(error("Please provide a valid JSON export file.")) await ctx.send(error("Please provide a valid JSON export file."))
return return