fixing the ask method
This commit is contained in:
parent
a7ed58482a
commit
e4d5c2ab2c
@ -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")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user