Catch exceptions in [p]backup (#2363)

Resolves #2354.

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
Toby Harradine 2019-01-11 09:07:37 +11:00 committed by GitHub
parent 78e4b578e2
commit 7973babe4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1142,6 +1142,9 @@ class Core(commands.Cog, CoreLogic):
await ctx.send(
_("A backup has been made of this instance. It is at {}.").format(backup_file)
)
if backup_file.stat().st_size > 8_000_000:
await ctx.send(_("This backup is to large to send via DM."))
return
await ctx.send(_("Would you like to receive a copy via DM? (y/n)"))
pred = MessagePredicate.yes_or_no(ctx)
@ -1152,10 +1155,18 @@ class Core(commands.Cog, CoreLogic):
else:
if pred.result is True:
await ctx.send(_("OK, it's on its way!"))
async with ctx.author.typing():
await ctx.author.send(
_("Here's a copy of the backup"), file=discord.File(str(backup_file))
try:
async with ctx.author.typing():
await ctx.author.send(
_("Here's a copy of the backup"),
file=discord.File(str(backup_file)),
)
except discord.Forbidden:
await ctx.send(
_("I don't seem to be able to DM you. Do you have closed DMs?")
)
except discord.HTTPException:
await ctx.send(_("I could not send the backup file."))
else:
await ctx.send(_("OK then."))
else: