Commit c12dfa00 authored by Gabriel Jacoby-Cooper's avatar Gabriel Jacoby-Cooper

Simplify error handling

parent 012ec577
Pipeline #178492533 passed with stages
in 1 minute and 38 seconds
......@@ -27,33 +27,28 @@ class GSBL(Command):
return
self.image_name = None
self.video_name = None
if len(msg.attachments) > 0:
image_attachment = msg.attachments[0]
self.image_name = image_attachment.filename
await image_attachment.save(self.image_name)
else:
try:
self.image_name = wget.download(content)
except ValueError:
await utils.delay_send(msg.channel, "That's not a valid URL!")
return
except urllib.error.HTTPError:
await utils.delay_send(msg.channel, "That URL doesn't exist (or couldn't be accessed)!")
return
do_generate_video = True
try:
if len(msg.attachments) > 0:
image_attachment = msg.attachments[0]
self.image_name = image_attachment.filename
await image_attachment.save(self.image_name)
else:
self.image_name = wget.download(content)
do_generate_video = True
_ = PIL.Image.open(self.image_name)
except ValueError:
await utils.delay_send(msg.channel, "That's not a valid URL!")
return
except urllib.error.HTTPError:
await utils.delay_send(msg.channel, "That URL doesn't exist (or couldn't be accessed)!")
return
except PIL.UnidentifiedImageError:
await utils.delay_send(msg.channel, "That's not a valid image!")
do_generate_video = False
if do_generate_video:
await asyncio.get_event_loop().run_in_executor(None, self.generate_video)
await msg.channel.send(file=self.video_file)
try:
print()
if type(self.image_name) == str:
os.remove(self.image_name)
if type(self.video_name) == str:
os.remove(self.video_name)
except FileNotFoundError:
await msg.channel.send("Couldn't delete temporary files on bot server")
if type(self.image_name) == str:
os.remove(self.image_name)
if type(self.video_name) == str:
os.remove(self.video_name)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment