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,17 +13,15 @@ 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")) try:
question = " ".join(message.split()[1:]) res = client.query(message)
return next(res.results).text
except Exception:
try: try:
res = client.query(question) return wikipedia.summary(message, sentences=5)
return next(res.results).text
except Exception: except Exception:
try: return "Sorry, I'm unable to answer that"
return wikipedia.summary(question, sentences=5)
except Exception:
return "Sorry, I'm unable to answer that"
return help_methods.get_help_message("message") return help_methods.get_help_message("message")