fixing the ask method

This commit is contained in:
Luke Robles 2022-10-06 14:58:58 -07:00
parent 3912b3b15f
commit 95d882e92b

View File

@ -13,15 +13,13 @@ def answer_question(message):
If no answer is found, tries wikipedia. If that fails, apologizes If no answer is found, tries wikipedia. If that fails, apologizes
""" """
if len(message.split()) > 1:
client = wolframalpha.Client(os.getenv("wolfram_token")) client = wolframalpha.Client(os.getenv("wolfram_token"))
question = " ".join(message.split()[1:])
try: try:
res = client.query(question) res = client.query(message)
return next(res.results).text return next(res.results).text
except Exception: except Exception:
try: try:
return wikipedia.summary(question, sentences=5) return wikipedia.summary(message, sentences=5)
except Exception: except Exception:
return "Sorry, I'm unable to answer that" return "Sorry, I'm unable to answer that"