From b47a5190e301e95618b6ac99eb40ad555ea34f34 Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Sun, 24 Dec 2017 14:54:19 +0000 Subject: [PATCH] v1.0.7 - Improved error handling for .avatar update command --- admincommands.py | 13 ++++++++++--- common.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/admincommands.py b/admincommands.py index 06f4848..43aede5 100644 --- a/admincommands.py +++ b/admincommands.py @@ -47,15 +47,22 @@ def cmd_loud(client, msg): @asyncio.coroutine def cmd_avatar(client, msg): - # TODO: error-check - # unsafe, but admin command - use with care for now url = msg.content[8:] + response = "Avatar updated!" try: response = urllib.request.urlopen(url) imgdata = response.read() yield from client.edit_profile(avatar=imgdata) + except urllib.error.URLError as e: + response = "URL Error: " + e + except discord.HTTPException: + response = "Dicsord failed to edit my profile!" + except discord.InvalidArgument: + response = "Invalid image!" except: - yield from discord_send(client, msg, "Error updating avatar!") + response = "Error updating avatar!" + + yield from discord_send(client, msg, response) # COMMAND HANDLING admincommands = { diff --git a/common.py b/common.py index bf80f15..af357fd 100755 --- a/common.py +++ b/common.py @@ -13,7 +13,7 @@ import json # bot version -version = "v1.0.6" +version = "v1.0.7" # TODO: generate this on the fly and make it look acceptable