Handle xkcd title lookup failing

This commit is contained in:
deadcade 2022-06-12 15:30:11 +02:00
parent 65c1beb010
commit af8e2d9b53
1 changed files with 5 additions and 3 deletions

View File

@ -250,9 +250,11 @@ async def xkcd(args, room, event):
title = filter_xkcd_title(line.split(">")[1].split("<")[0])
lookup[title] = num
user_title = filter_xkcd_title(" ".join(args))
title = difflib.get_close_matches(user_title, lookup.keys(), n=1)[0]
if title:
comic = lookup[title] + "/"
title = difflib.get_close_matches(user_title, lookup.keys(), n=1)
if len(title) > 0:
comic = lookup[title[0]] + "/"
else:
return await send_text(room.room_id, "Could not find XKCD!")
r = requests.get(f"https://xkcd.com/{comic}info.0.json")
if settings["debug"]:
rj = json.loads(r.text)