Don't catch errors on xkcd if debug is enabled

This commit is contained in:
0xDEADCADE 2022-04-09 13:36:58 +00:00 committed by GitHub
parent 5879bc1826
commit 28acad1884
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

19
main.py
View file

@ -232,15 +232,18 @@ async def xkcd(args, room, event):
user_title = filter_xkcd_title(" ".join(args)) user_title = filter_xkcd_title(" ".join(args))
if user_title in lookup.keys(): if user_title in lookup.keys():
comic = lookup[user_title] + "/" comic = lookup[user_title] + "/"
try: r = requests.get(f"https://xkcd.com/{comic}info.0.json")
r = requests.get(f"https://xkcd.com/{comic}info.0.json") if settings["debug"]:
rj = json.loads(r.text) rj = json.loads(r.text)
filename = download_file(rj["img"], settings["cache_path"] + "/" + str(rj["num"]) + "." + rj["img"].split(".")[-1]) else:
image = await send_file(filename) try:
await send_text(room.room_id, f"{rj['year']}/{rj['month']}/{rj['day']}, {str(rj['num'])}: <a href=\"https://xkcd.com/{str(rj['num'])}/\">{rj['safe_title']}</a>") rj = json.loads(r.text)
return await send_image(room.room_id, image, rj['alt']) except Exception:
except Exception: return await send_text(room.room_id, "Failed to get XKCD!")
return await send_text(room.room_id, "Failed to get XKCD!") filename = download_file(rj["img"], settings["cache_path"] + "/" + str(rj["num"]) + "." + rj["img"].split(".")[-1])
image = await send_file(filename)
await send_text(room.room_id, f"{rj['year']}/{rj['month']}/{rj['day']}, {str(rj['num'])}: <a href=\"https://xkcd.com/{str(rj['num'])}/\">{rj['safe_title']}</a>")
return await send_image(room.room_id, image, rj['alt'])
async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) -> None: async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) -> None:
global client, settings, emojis global client, settings, emojis