Add inexact search on xkcd titles
This commit is contained in:
parent
82160775b1
commit
2d5d145dc7
1 changed files with 4 additions and 2 deletions
6
main.py
6
main.py
|
@ -9,6 +9,7 @@ import os # Filesystem
|
|||
import mimetypes # Uploading files to homeserver
|
||||
import html # HTML formatting
|
||||
import requests # XKCD command
|
||||
import difflib # XKCD Title lookup
|
||||
import subprocess # GIF Emojis, ping command (admin)
|
||||
import random # roll command
|
||||
import datetime # Ratelimiting
|
||||
|
@ -249,8 +250,9 @@ 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))
|
||||
if user_title in lookup.keys():
|
||||
comic = lookup[user_title] + "/"
|
||||
title = difflib.get_close_matches(user_title, lookup.keys(), n=1)[0]
|
||||
if title:
|
||||
comic = lookup[title] + "/"
|
||||
r = requests.get(f"https://xkcd.com/{comic}info.0.json")
|
||||
if settings["debug"]:
|
||||
rj = json.loads(r.text)
|
||||
|
|
Loading…
Reference in a new issue