Handle xkcd title lookup failing

This commit is contained in:
deadcade 2022-06-12 15:30:11 +02:00
parent 65c1beb010
commit af8e2d9b53

View file

@ -250,9 +250,11 @@ async def xkcd(args, room, event):
title = filter_xkcd_title(line.split(">")[1].split("<")[0]) title = filter_xkcd_title(line.split(">")[1].split("<")[0])
lookup[title] = num lookup[title] = num
user_title = filter_xkcd_title(" ".join(args)) user_title = filter_xkcd_title(" ".join(args))
title = difflib.get_close_matches(user_title, lookup.keys(), n=1)[0] title = difflib.get_close_matches(user_title, lookup.keys(), n=1)
if title: if len(title) > 0:
comic = lookup[title] + "/" 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") r = requests.get(f"https://xkcd.com/{comic}info.0.json")
if settings["debug"]: if settings["debug"]:
rj = json.loads(r.text) rj = json.loads(r.text)