diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 6db9043d..d2be402e 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -20,11 +20,11 @@ import excuse import get_from_reddit import help_methods import lewds +import questions import role_check +import stock import wallpaper import weather -import wolfram -import stock # Client object client = discord.Client() @@ -71,7 +71,7 @@ async def on_message(message): message.channel, "{} ```{}```".format( message.author.mention, - wolfram.answer_question(message.content) + questions.answer_question(message.content) ) ) diff --git a/app/questions.py b/app/questions.py new file mode 100644 index 00000000..026435e6 --- /dev/null +++ b/app/questions.py @@ -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') diff --git a/app/requirements.txt b/app/requirements.txt index f1f3e62d..2d8258ce 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -4,5 +4,6 @@ docker pylint pyowm requests +wikipedia wolframalpha yahoo-finance diff --git a/app/wolfram.py b/app/wolfram.py deleted file mode 100644 index 83374e68..00000000 --- a/app/wolfram.py +++ /dev/null @@ -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')