Have dragon bot fall back to wikipedia if wolfram is unable to answer the question
This commit is contained in:
parent
4fec8ea6df
commit
776d34cca1
@ -20,11 +20,11 @@ import excuse
|
|||||||
import get_from_reddit
|
import get_from_reddit
|
||||||
import help_methods
|
import help_methods
|
||||||
import lewds
|
import lewds
|
||||||
|
import questions
|
||||||
import role_check
|
import role_check
|
||||||
|
import stock
|
||||||
import wallpaper
|
import wallpaper
|
||||||
import weather
|
import weather
|
||||||
import wolfram
|
|
||||||
import stock
|
|
||||||
|
|
||||||
# Client object
|
# Client object
|
||||||
client = discord.Client()
|
client = discord.Client()
|
||||||
@ -71,7 +71,7 @@ async def on_message(message):
|
|||||||
message.channel,
|
message.channel,
|
||||||
"{} ```{}```".format(
|
"{} ```{}```".format(
|
||||||
message.author.mention,
|
message.author.mention,
|
||||||
wolfram.answer_question(message.content)
|
questions.answer_question(message.content)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
26
app/questions.py
Normal file
26
app/questions.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import wikipedia
|
||||||
|
import wolframalpha
|
||||||
|
|
||||||
|
import help_methods
|
||||||
|
|
||||||
|
def answer_question(message):
|
||||||
|
"""
|
||||||
|
answer_question(question)
|
||||||
|
|
||||||
|
Submits a request to the wolfram API and returns the response
|
||||||
|
If no answer is found, tries wikipedia. If that fails, apologizes
|
||||||
|
"""
|
||||||
|
|
||||||
|
if len(message.split()) > 1:
|
||||||
|
client = wolframalpha.Client('2LU2Y7-YJQTA7TL8E')
|
||||||
|
question = ' '.join(message.split()[1:])
|
||||||
|
try:
|
||||||
|
res = client.query(question)
|
||||||
|
return next(res.results).text
|
||||||
|
except Exception:
|
||||||
|
try:
|
||||||
|
return wikipedia.summary(question, sentences=5)
|
||||||
|
except Exception:
|
||||||
|
return "Sorry, I\'m unable to answer that"
|
||||||
|
|
||||||
|
return help_methods.get_help_message('message')
|
@ -4,5 +4,6 @@ docker
|
|||||||
pylint
|
pylint
|
||||||
pyowm
|
pyowm
|
||||||
requests
|
requests
|
||||||
|
wikipedia
|
||||||
wolframalpha
|
wolframalpha
|
||||||
yahoo-finance
|
yahoo-finance
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
import wolframalpha
|
|
||||||
|
|
||||||
import help_methods
|
|
||||||
|
|
||||||
def answer_question(message):
|
|
||||||
"""
|
|
||||||
answer_question(question)
|
|
||||||
|
|
||||||
submits a request to the wolfram API and returns the response
|
|
||||||
"""
|
|
||||||
|
|
||||||
if len(message.split()) > 1:
|
|
||||||
client = wolframalpha.Client('2LU2Y7-YJQTA7TL8E')
|
|
||||||
question = ' '.join(message.split()[1:])
|
|
||||||
res = client.query(question)
|
|
||||||
return next(res.results).text
|
|
||||||
|
|
||||||
return help_methods.get_help_message('message')
|
|
Loading…
x
Reference in New Issue
Block a user