Handle xkcd title lookup failing
This commit is contained in:
parent
65c1beb010
commit
af8e2d9b53
1 changed files with 5 additions and 3 deletions
8
main.py
8
main.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue